Encrypted Content-Encoding for HTTPMozillamartin.thomson@gmail.comApplications and Real-TimeHTTP Working GroupInternet-DraftThis memo introduces a content coding for HTTP that allows message payloads to
be encrypted.Discussion of this draft takes place on the HTTP working group mailing list
(ietf-http-wg@w3.org), which is archived at https://lists.w3.org/Archives/Public/ietf-http-wg/.Working Group information can be found at http://httpwg.github.io/; source
code and issues list for this draft can be found at https://github.com/httpwg/http-extensions/labels/encryption.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 , since it only encrypts
the channel between the client and server.This document specifies a content coding (Section 3.1.2 of ) 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 , ,
, and - 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 .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, explains how the format is congruent with a
sequence of JSON Web Encryption 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 Crypto-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 .Base64url encoding is defined in Section 2 of .The “aes128gcm” 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 , Section 5.1. The AEAD_AES_128_GCM
algorithm uses a 128 bit content encryption key.Using this content coding requires knowledge of a key. The Crypto-Key header
field () can be included to describe how the content encryption
key is derived or retrieved. Keys might be provided in messages that are
separate from those with encrypted content using Crypto-Key, or provided through
external mechanisms.The “aes128gcm” 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 “aes128gcm” content coding uses a fixed record size. The final encoding
consists of a header (see ), zero or more fixed size encrypted
records, and a partial record. The partial record MUST be shorter than the
fixed record size.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 (“rs”) is included in the content coding header (see
).AEAD_AES_128_GCM produces ciphertext 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. 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 fail to decrypt if the final record ciphertext is
less than 18 octets in size or equal to the record size plus 16 (that is, the
size of a full encrypted record). Valid records always contain at least two
octets of padding and a 16 octet authentication tag.Each record contains between 2 and 65537 octets of padding, inserted into a
record before the enciphered content. Padding consists of a two octet unsigned
integer in network byte order, followed that number of zero-valued octets. A
receiver MUST fail to decrypt if any padding octet other than the first two are
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 .The additional data passed to each invocation of AEAD_AES_128_GCM is a
zero-length octet sequence.A consequence of this record structure is that range requests and
random access to encrypted payload bodies are possible at the granularity of the
record size. Partial records at the ends of a range cannot be decrypted. Thus,
it is best if range requests start and end on record boundaries.Selecting the record size most appropriate for a given situation requires a
trade-off. A smaller record size allows decrypted octets to be released more
rapidly, which can be appropriate for applications that depend on
responsiveness. Smaller records also reduce the additional data required if
random access into the ciphertext is needed. Applications that depend on being
able to pad by arbitrary amounts cannot increase the record size beyond 65537
octets.Applications that don’t depending on streaming, random access, or arbitrary
padding can use larger records, or even a single record. A larger record size
reduces the processing and data overheads.The content coding uses a header block that includes all parameters needed to
decrypt the content (other than the key). The header block is placed in the
body of a message ahead of the sequence of records.
The “salt” parameter comprises the first 16 octets of the “aes128gcm” content
coding header. The same “salt” parameter value MUST NOT be reused for two
different payload bodies that have the same input keying material; generating
a random salt for every application of the content coding ensures that content
encryption key reuse is highly unlikely.
The “rs” or record size parameter contains an unsigned 32-bit integer in
network byte order that describes the record size in octets. Note that it is
therefore impossible to exceed the 2^36-31 limit on plaintext input to
AEAD_AES_128_GCM. Values smaller than 3 are invalid.
The “keyid” parameter can be used to identify the keying material that is
used. When the Crypto-Key header field is used, the “keyid” identifies a
matching value in that field. The “keyid” parameter MUST be used if keying
material included in an Crypto-Key header field is needed to derive the
content encryption key. The “keyid” parameter can also be used to identify
keys in an application-specific fashion.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 using
the SHA-256 hash algorithm .The 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 Crypto-Key header field (). The extract phase
of HKDF therefore produces a pseudorandom key (PRK) as follows:The info parameter to HKDF is set to the ASCII-encoded string “Content-Encoding:
aes128gcm” and a single zero octet:
Concatenation of octet sequences is represented by the || operator.AEAD_AES_128_GCM requires a 16 octet (128 bit) content encryption key (CEK), so
the length (L) parameter to HKDF is 16. The second step of HKDF can therefore
be simplified to the first 16 octets of a single HMAC: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 that 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 length (L) parameter is 12 octets. The info parameter for the nonce is the
ASCII-encoded string “Content-Encoding: nonce”, terminated by a a single zero
octet: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:This nonce construction prevents removal or reordering of records. However, it
permits truncation of the tail of the sequence (see for how this
is avoided).A Crypto-Key header field can be used to describe the input keying material used
by the aes128gcm content coding.Ordinarily, this header field will not appear in the same message as the
encrypted content. Including the encryption key with the encrypted payload
reduces the value of using encryption to a somewhat complicated checksum.
However, the Crypto-Key header field could be used in one message to provision
keys for other messages.The Crypto-Key header field uses the extended ABNF syntax defined in Section 1.2
of and the parameter and OWS rules from .
The “keyid” parameter corresponds to the “keyid” parameter in the content
coding.
The “aes128gcm” parameter contains the base64url-encoded octets of
the input keying material for the “aes128gcm” content coding.Crypto-Key header field values with multiple instances of the same parameter
name in a single crypto-key-params production are invalid.The input keying material used by the key derivation (see ) can be
determined based on the information in the Crypto-Key header field.The value or values provided in the Crypto-Key header field is valid only
for the current HTTP message unless additional information indicates a greater
scope.Alternative methods for determining input keying material MAY be defined by
specifications that use this content coding. This document only defines the use
of the “aes128gcm” parameter which describes an explicit key.The “aes128gcm” parameter MUST decode to at least 16 octets in order to be used
as input keying material for “aes128gcm” content coding.This section shows a few examples of the encrypted content coding.Note: All binary values in the examples in this section use base64url encoding
. This includes the bodies of requests. Whitespace and line
wrapping is added to fit formatting constraints.Here, a successful HTTP GET response has been encrypted using input keying
material that is identified by the string “a1”.The encrypted data in this example is the UTF-8 encoded string “I am the
walrus”. The input keying material is included in the Crypto-Key header field.
The content body contains a single record only and is shown here using base64url
encoding for presentation reasons.Note that the media type has been changed to “application/octet-stream” to avoid
exposing information about the content. Alternatively (and equivalently), the
Content-Type header field can be omitted.This example shows the same encrypted message, but split into records of 10
octets each. The first record includes a single additional octet of padding,
which causes the end of the content to align with a record boundary, forcing the
creation of a third record that contains only padding.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 . 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 coding. 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.There are limits to the data that AEAD_AES_128_GCM can encipher. The maximum
value for the record size is limited by the size of the “rs” field in the header
(see ), which ensures that the 2^36-31 limit for a single application
of AEAD_AES_128_GCM is not reached . In order to preserve a 2^-40
probability of indistinguishability under chosen plaintext attack (IND-CPA), the
total amount of plaintext that can be enciphered MUST be less than 2^44.5 blocks
of 16 octets .If rs is a multiple of 16 octets, this means 398 terabytes can be encrypted
safely, including padding. However, if the record size is not a multiple of 16
octets, the total amount of data that can be safely encrypted is reduced
proportionally. The worst case is a record size of 3 octets, for which at most
74 terabytes of plaintext can be encrypted, of which at least two-thirds is
padding.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:Determine that it is not an issue. For example, if it is expected that all
content stored will be “application/json”, or another very common media type,
exposing the Content-Type header field could be an acceptable risk.If it is considered sensitive information and it is possible to determine it
through other means (e.g., out of band, using hints in other representations,
etc.), omit the relevant headers, and/or normalize them. In the case of
Content-Type, this could be accomplished by always sending Content-Type:
application/octet-stream (the most generic media type), or no Content-Type at
all.If it is considered sensitive information and it is not possible to convey it
elsewhere, encapsulate the HTTP message using the application/http media type
(Section 8.3.2 of ), encrypting that as the payload of the “outer”
message.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 ).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 combined with TLS
might be used to hide the size of individual messages.This memo registers the “aes128gcm” HTTP content coding in the HTTP Content Codings
Registry, as detailed in .Name: aes128gcmDescription: AES-GCM encryption with a 128-bit content encryption keyReference: this specificationThis memo registers the “Crypto-Key” HTTP header field in the Permanent
Message Header Registry, as detailed in .Field name: Crypto-KeyProtocol: HTTPStatus: StandardReference: this specificationNotes:This memo establishes a registry for parameters used by the “Crypto-Key” header
field under the “Hypertext Transfer Protocol (HTTP) Parameters” grouping. The
“Hypertext Transfer Protocol (HTTP) Crypto-Key Parameters” operates under an
“Specification Required” policy .Entries in this registry are expected to include the following information:Parameter Name: The name of the parameter.Purpose: A brief description of the purpose of the parameter.Reference: A reference to a specification that defines the semantics of the
parameter.The initial contents of this registry are:Parameter Name: keyidPurpose: Identify the key that is in use.Reference: this documentParameter Name: aes128gcmPurpose: Provide an explicit input keying material value for the aes128gcm
content coding.Reference: this documentNIST FIPS 180-4, Secure Hash StandardHypertext Transfer Protocol (HTTP/1.1): Semantics and ContentThe Hypertext Transfer Protocol (HTTP) is a stateless \%application- level protocol for distributed, collaborative, hypertext information systems. This document defines the semantics of HTTP/1.1 messages, as expressed by request methods, request header fields, response status codes, and response header fields, along with the payload of messages (metadata and body content) and mechanisms for content negotiation.An Interface and Algorithms for Authenticated EncryptionThis document defines algorithms for Authenticated Encryption with Associated Data (AEAD), and defines a uniform interface and a registry for such algorithms. The interface and registry can be used as an application-independent set of cryptoalgorithm suites. This approach provides advantages in efficiency and security, and promotes the reuse of crypto implementations. [STANDARDS-TRACK]Key words for use in RFCs to Indicate Requirement LevelsIn many standards track documents several words are used to signify the requirements in the specification. These words are often capitalized. This document defines these words as they should be interpreted in IETF documents. This document specifies an Internet Best Current Practices for the Internet Community, and requests discussion and suggestions for improvements.JSON Web Signature (JWS)JSON Web Signature (JWS) represents content secured with digital signatures or Message Authentication Codes (MACs) using JSON-based data structures. Cryptographic algorithms and identifiers for use with this specification are described in the separate JSON Web Algorithms (JWA) specification and an IANA registry defined by that specification. Related encryption capabilities are described in the separate JSON Web Encryption (JWE) specification.HMAC-based Extract-and-Expand Key Derivation Function (HKDF)This document specifies a simple Hashed Message Authentication Code (HMAC)-based key derivation function (HKDF), which can be used as a building block in various protocols and applications. The key derivation function (KDF) is intended to support a wide range of applications and requirements, and is conservative in its use of cryptographic hash functions. This document is not an Internet Standards Track specification; it is published for informational purposes.Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and RoutingThe Hypertext Transfer Protocol (HTTP) is a stateless application-level protocol for distributed, collaborative, hypertext information systems. This document provides an overview of HTTP architecture and its associated terminology, defines the "http" and "https" Uniform Resource Identifier (URI) schemes, defines the HTTP/1.1 message syntax and parsing requirements, and describes related security concerns for implementations.Guidelines for Writing an IANA Considerations Section in RFCsMany protocols make use of identifiers consisting of constants and other well-known values. Even after a protocol has been defined and deployment has begun, new values may need to be assigned (e.g., for a new option type in DHCP, or a new encryption or authentication transform for IPsec). To ensure that such quantities have consistent values and interpretations across all implementations, their assignment must be administered by a central authority. For IETF protocols, that role is provided by the Internet Assigned Numbers Authority (IANA).In order for IANA to manage a given namespace prudently, it needs guidelines describing the conditions under which new values can be assigned or when modifications to existing values can be made. If IANA is expected to play a role in the management of a namespace, IANA must be given clear and concise instructions describing that role. This document discusses issues that should be considered in formulating a policy for assigning values to a namespace and provides guidelines for authors on the specific text that must be included in documents that place demands on IANA.This document obsoletes RFC 2434. This document specifies an Internet Best Current Practices for the Internet Community, and requests discussion and suggestions for improvements.XML Encryption Syntax and ProcessingLimits on Authenticated Encryption Use in TLSThe Transport Layer Security (TLS) Protocol Version 1.2This document specifies Version 1.2 of the Transport Layer Security (TLS) protocol. The TLS protocol provides communications security over the Internet. The protocol allows client/server applications to communicate in a way that is designed to prevent eavesdropping, tampering, or message forgery. [STANDARDS-TRACK]OpenPGP Message FormatThis document is maintained in order to publish all necessary information needed to develop interoperable applications based on the OpenPGP format. It is not a step-by-step cookbook for writing an application. It describes only the format and methods needed to read, check, generate, and write conforming packets crossing any network. It does not deal with storage and implementation questions. It does, however, discuss implementation issues necessary to avoid security flaws.OpenPGP software uses a combination of strong public-key and symmetric cryptography to provide security services for electronic communications and data storage. These services include confidentiality, key management, authentication, and digital signatures. This document specifies the message formats used in OpenPGP. [STANDARDS-TRACK]Cryptographic Message Syntax (CMS)This document describes the Cryptographic Message Syntax (CMS). This syntax is used to digitally sign, digest, authenticate, or encrypt arbitrary message content. [STANDARDS-TRACK]JSON Web Encryption (JWE)JSON Web Encryption (JWE) represents encrypted content using JSON-based data structures. Cryptographic algorithms and identifiers for use with this specification are described in the separate JSON Web Algorithms (JWA) specification and IANA registries defined by that specification. Related digital signature and Message Authentication Code (MAC) capabilities are described in the separate JSON Web Signature (JWS) specification.Hypertext Transfer Protocol (HTTP/1.1): Range RequestsThe Hypertext Transfer Protocol (HTTP) is a stateless application- level protocol for distributed, collaborative, hypertext information systems. This document defines range requests and the rules for constructing and combining responses to those requests.Hypertext Transfer Protocol (HTTP/1.1): AuthenticationThe Hypertext Transfer Protocol (HTTP) is a stateless application- level protocol for distributed, collaborative, hypermedia information systems. This document defines the HTTP Authentication framework.Hypertext Transfer Protocol Version 2 (HTTP/2)This specification describes an optimized expression of the semantics of the Hypertext Transfer Protocol (HTTP), referred to as HTTP version 2 (HTTP/2). HTTP/2 enables a more efficient use of network resources and a reduced perception of latency by introducing header field compression and allowing multiple concurrent exchanges on the same connection. It also introduces unsolicited push of representations from servers to clients.This specification is an alternative to, but does not obsolete, the HTTP/1.1 message syntax. HTTP's existing semantics remain unchanged.The “aes128gcm” content coding can be considered as a sequence of JSON Web
Encryption (JWE) objects , each corresponding to a single fixed size
record that includes leading padding. The following transformations are applied
to a JWE object that might be expressed using the JWE Compact Serialization:The JWE Protected Header is fixed to the value { “alg”: “dir”, “enc”: “A128GCM”
}, describing direct encryption using AES-GCM with a 128-bit content
encryption key. This header is not transmitted, it is instead implied by the
value of the Content-Encoding header field.The JWE Encrypted Key is empty, as stipulated by the direct encryption algorithm.The JWE Initialization Vector (“iv”) for each record is set to the exclusive
or of the 96-bit record sequence number, starting at zero, and a value derived
from the input keying material (see ). This value is also not
transmitted.The final value is the concatenated header, JWE Ciphertext, and JWE
Authentication Tag, all expressed without base64url encoding. The “.”
separator is omitted, since the length of these fields is known.Thus, the example in can be rendered using the JWE Compact
Serialization as:Where the first line represents the fixed JWE Protected Header, an empty JWE
Encrypted Key, and the algorithmically-determined JWE Initialization Vector.
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 input: Richard Barnes, David Benjamin,
Peter Beverloo, JR Conlin, Mike Jones, Stephen Farrell, Adam Langley, John Mattsson, Julian
Reschke, Eric Rescorla, Jim Schaad, and Magnus Westerlund.