A JSON Meta Application Protocol (JMAP) Subprotocol for WebSocketFastmail US LLC1429 Walnut Street, Suite 1201PhiladelphiaPA19102United States of Americamurch@fastmailteam.comhttp://www.fastmail.com/
ART
JMAPjmapwebsocketThis document defines a binding for the JSON Meta Application
Protocol (JMAP) over a WebSocket transport layer. The WebSocket
binding for JMAP provides higher performance than the current
HTTP binding for JMAP.
Status of This Memo
This is an Internet Standards Track document.
This document is a product of the Internet Engineering Task Force
(IETF). It represents the consensus of the IETF community. It has
received public review and has been approved for publication by
the Internet Engineering Steering Group (IESG). Further
information on Internet Standards is available in Section 2 of
RFC 7841.
Information about the current status of this document, any
errata, and how to provide feedback on it may be obtained at
.
Copyright Notice
Copyright (c) 2020 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
() 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.
Table of Contents
. Introduction
. Conventions Used in This Document
. Discovering Support for JMAP over WebSocket
. JMAP Subprotocol
. Authentication
. Handshake
. WebSocket Messages
. Handling Invalid Data
. JMAP Requests
. JMAP Responses
. JMAP Request-Level Errors
. JMAP Push Notifications
. Examples
. Security Considerations
. Connection Confidentiality and Integrity
. Non-browser Clients
. IANA Considerations
. Registration of the WebSocket JMAP Subprotocol
. References
. Normative References
. Informative References
Acknowledgments
Author's Address
IntroductionJMAP
over HTTP requires that
every JMAP API request be authenticated.
Depending on the type of authentication used by
the JMAP client and the configuration of the JMAP server,
authentication could be an expensive operation both in time and
resources. In such circumstances, reauthenticating for every
JMAP API request may harm performance.The WebSocket
binding for JMAP eliminates this performance
hit by authenticating just the WebSocket handshake request and
having those credentials remain in effect for the duration of
the WebSocket connection. This binding supports JMAP API
requests and responses, with optional support for push
notifications.Furthermore, the WebSocket binding for JMAP can optionally
compress both JMAP API
requests and responses.
Although compression of HTTP responses is ubiquitous,
compression of HTTP requests has very low, if any, deployment
and therefore isn't a viable option for JMAP API requests
over HTTP.Conventions Used in This Document
The key words "MUST", "MUST NOT",
"REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT",
"RECOMMENDED", "NOT RECOMMENDED",
"MAY", and "OPTIONAL" in this document are
to be interpreted as
described in BCP 14
when, and only when, they appear in all capitals, as shown here.
This document uses the terminology defined in the core JMAP
specification .Discovering Support for JMAP over WebSocketThe JMAP capabilities object is returned as part of the
standard JMAP Session object (see
).
Servers supporting this specification MUST add a property named
"urn:ietf:params:jmap:websocket" to the capabilities object.
The value of this property is an object that MUST contain the
following information on server capabilities:
url: "String"The wss-URI (see ) to use for initiating a JMAP-over-WebSocket
handshake (the "WebSocket URL endpoint" colloquially).
supportsPush: "Boolean"This is true if the server supports push notifications over the
WebSocket, as described in .
Example:
"urn:ietf:params:jmap:websocket": {
"url": "wss://server.example.com/jmap/ws/",
"supportsPush": true
}
JMAP SubprotocolThe term WebSocket subprotocol refers to an application-level
protocol layered on top of a WebSocket connection. This
document specifies the WebSocket JMAP subprotocol for carrying
JMAP API requests, responses, and optional push notifications
through a WebSocket connection.
Binary data is handled per (via a separate HTTP connection or stream)
or per a future extension to JMAP or this specification.AuthenticationA JMAP WebSocket connection is authenticated by presenting
a user's credentials in the
HTTP request that initiates the WebSocket handshake.
See for
recommendations regarding the selection of HTTP authentication
schemes.HandshakeThe JMAP WebSocket client and JMAP WebSocket server
negotiate the use of the WebSocket JMAP subprotocol during
the WebSocket handshake, either via an HTTP/1.1 Upgrade request
(see )
or an HTTP/2 Extended CONNECT request (see
).
The WebSocket JMAP subprotocol is also intended to run
over future bindings of HTTP (e.g., HTTP/3) provided that there
is a defined mechanism for performing a WebSocket handshake
over that binding.Regardless of the method used for the WebSocket handshake,
the client MUST first perform a TLS handshake on a
JMAP WebSocket URL endpoint
having the "wss://" scheme (WebSocket over TLS) in
accordance with the requirements of running the particular
binding of HTTP over TLS (see
and for HTTP/1.1
and for HTTP/2).
If the TLS handshake fails, the client MUST close the
connection. Otherwise, the client MUST make an
authenticated HTTP request
on the encrypted connection and MUST include the value "jmap"
in the list of protocols for the "Sec-WebSocket-Protocol"
header field.The reply from the server MUST also contain a
corresponding "Sec-WebSocket-Protocol" header field with a
value of "jmap" in order
for a JMAP subprotocol connection to be established.Once the handshake has successfully completed, the
WebSocket connection is established and can be used for JMAP
API requests, responses, and optional push notifications.
Other message types MUST NOT be transmitted over this
connection.The credentials used for authenticating the HTTP request
to initiate the handshake remain in effect for the duration
of the WebSocket connection. If the authentication
credentials for the user expire, the server can either treat
subsequent requests as if they are unauthenticated or close
the WebSocket connection.
In the latter case, the server MAY send a Close frame with a
status code of 1008 (Policy Violation), as defined in
.WebSocket MessagesData frame messages in the JMAP subprotocol MUST be
text frames and contain UTF-8 encoded data. The messages MUST
be in the form of a single JMAP Request object (see
),
JMAP WebSocketPushEnable object (see ),
or JMAP WebSocketPushDisable object (see )
when sent from
the client to the server, and MUST be in the form of a single JMAP
Response object, JSON Problem Details object, or JMAP StateChange
object (see Sections , , and of ,
respectively) when sent from the server to the client.Note that fragmented WebSocket messages (split over
multiple text frames) MUST be coalesced prior to parsing them
as JSON objects.Handling Invalid DataIf a client or server receives a binary frame, the endpoint
can either ignore the frame or close the WebSocket connection.
In the latter case, the endpoint MAY send a Close frame with a
status code of 1003 (Unsupported Data), as defined in
.If a client receives a message that is not in the form of
a JSON Problem Details object, a JMAP Response
object, or a JMAP StateChange object, the client can either
ignore the message or close the WebSocket connection.
In the latter case, the endpoint MAY send a Close frame with a
status code of 1007 (Invalid frame payload data), as
defined in .A server MUST return an appropriate
JSON Problem Details object
for any request-level errors
(e.g., an invalid JMAP object, an unsupported capability or
method call, or exceeding a server request limit).JMAP RequestsThe specification extends the Request object with two
additional arguments when used over a WebSocket:
@type: "String"This MUST be the string "Request".
id: "String" (optional)A client-specified identifier for the request to be echoed
back in the response to this request.
JMAP over WebSocket allows the server to process requests
out of order. The client-specified identifier is used as a
mechanism for the client to correlate requests and
responses.Additionally, the "maxConcurrentRequests" limit in the
"capabilities" object (see ) also applies to requests made on
the WebSocket connection. When using the WebSocket JMAP
subprotocol over a binding of HTTP that allows multiplexing
of requests (e.g., HTTP/2), this limit applies to the sum
of requests made on both the JMAP API endpoint and the
WebSocket connection.JMAP ResponsesThe specification extends the Response object with two
additional arguments when used over a WebSocket:
@type: "String"This MUST be the string "Response".
requestId: "String" (optional; MUST be
returned if an identifier is included in the request)The client-specified identifier in the corresponding
request.
JMAP Request-Level ErrorsThe specification extends the Problem Details object
for request-level errors (see ) with two additional arguments
when used over a WebSocket:
@type: "String"This MUST be the string "RequestError".
requestId: "String" (optional; MUST be
returned if given in the request)The client-specified identifier in the corresponding
request.
JMAP Push NotificationsJMAP-over-WebSocket servers that support push
notifications on the WebSocket will advertise a
"supportsPush" property with a value of true in
the "urn:ietf:params:jmap:websocket" server capabilities
object.Notification FormatAll push notifications take the form of a standard
StateChange object (see ).The specification extends the StateChange object with one
additional argument when used over a WebSocket:
pushState: "String" (optional)A (preferably short) string that encodes the entire server
state visible to the user (not just the objects returned in
this call).The purpose of the "pushState" token is to allow a client
to immediately get any changes that occurred while it was
disconnected (see ). If the server does not support
"pushState" tokens, the client will have to issue a series of
"/changes" requests (see ) upon reconnection to
update its state to match that of the server.
Enabling NotificationsA client enables push notifications from the server for
the current connection by
sending a WebSocketPushEnable object to the server. A
WebSocketPushEnable object has the following properties:
@type: "String"This MUST be the string
"WebSocketPushEnable".
dataTypes: "String[]|null"A list of data type names (e.g., "Mailbox" or "Email") that
the client is interested in. A StateChange notification will
only be sent if the data for one of these types changes.
Other types are omitted from the TypeState object. If null,
changes will be pushed for all supported data types.
pushState: "String" (optional)The last "pushState" token that the client received from
the server. Upon receipt of a "pushState" token, the server
SHOULD immediately send all changes since that
state token.
Disabling NotificationsA client disables push notifications from the server
for the current connection by
sending a WebSocketPushDisable object to the server. A
WebSocketPushDisable object has the following property:
@type: "String"This MUST be the string "WebSocketPushDisable".
ExamplesThe following examples show WebSocket JMAP opening
handshakes, a JMAP Core/echo request and response, and a
subsequent closing handshake.
The examples assume that the JMAP WebSocket URL endpoint has been
advertised in the JMAP Session object as having a path of
"/jmap/ws/" and that TLS negotiation has already succeeded.
Note that folding of header fields is for editorial purposes
only.
WebSocket JMAP connection via HTTP/1.1 with push
notifications for mail
is enabled. This example assumes that the client has cached
pushState "aaa" from a previous connection.
[[ From Client ]] [[ From Server ]]
GET /jmap/ws/ HTTP/1.1
Host: server.example.com
Upgrade: websocket
Connection: Upgrade
Authorization: Basic Zm9vOmJhcg==
Sec-WebSocket-Key:
dGhlIHNhbXBsZSBub25jZQ==
Sec-WebSocket-Protocol: jmap
Sec-WebSocket-Version: 13
Origin: https://www.example.com
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept:
s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
Sec-WebSocket-Protocol: jmap
[WebSocket connection established]
WS_DATA
{
"@type": "WebSocketPushEnable",
"dataTypes": [ "Mailbox", "Email" ],
"pushState": "aaa"
}
WS_DATA
{
"@type": "StateChange",
"changed": {
"a456": {
"Mailbox": "d35ecb040aab"
}
},
"pushState": "bbb"
}
WS_DATA
{
"@type": "Request",
"id": "R1",
"using": [ "urn:ietf:params:jmap:core" ],
"methodCalls": [
[
"Core/echo", {
"hello": true,
"high": 5
},
"b3ff"
]
]
}
WS_DATA
{
"@type": "Response",
"requestId": "R1",
"methodResponses": [
[
"Core/echo", {
"hello": true,
"high": 5
},
"b3ff"
]
]
}
WS_DATA
The quick brown fox jumps
over the lazy dog.
WS_DATA
{
"@type": "RequestError",
"requestId": null,
"type":
"urn:ietf:params:jmap:error:notJSON",
"status": 400,
"detail":
"The request did not parse as I-JSON."
}
[A new email is received]
WS_DATA
{
"@type": "StateChange",
"changed": {
"a123": {
"Email": "0af7a512ce70"
}
}
"pushState": "ccc"
}
WS_CLOSE
WS_CLOSE
[WebSocket connection closed]
WebSocket JMAP connection on an HTTP/2 stream that also
negotiates compression:
[[ From Client ]] [[ From Server ]]
SETTINGS
SETTINGS_ENABLE_CONNECT_PROTOCOL = 1
HEADERS + END_HEADERS
:method = CONNECT
:protocol = websocket
:scheme = https
:path = /jmap/ws/
:authority = server.example.com
origin: https://example.com
authorization = Basic Zm9vOmJhcg==
sec-websocket-protocol = jmap
sec-websocket-version = 13
sec-websocket-extensions =
permessage-deflate
origin = https://www.example.com
HEADERS + END_HEADERS
:status = 200
sec-websocket-protocol = jmap
sec-websocket-extensions =
permessage-deflate
[WebSocket connection established]
DATA
WS_DATA
[compressed text]
DATA
WS_DATA
[compressed text]
...
DATA + END_STREAM
WS_CLOSE
DATA + END_STREAM
WS_CLOSE
[WebSocket connection closed]
[HTTP/2 stream closed]
Security ConsiderationsThe security considerations for both WebSocket (see ) and JMAP (see ) apply to the
WebSocket JMAP subprotocol. Specific security considerations are
described below.Connection Confidentiality and IntegrityTo ensure the confidentiality and integrity of
data sent and received via JMAP over WebSocket, the WebSocket
connection MUST use TLS 1.2
or later, following the recommendations in BCP 195.
Servers SHOULD support TLS 1.3 or
later.Non-browser ClientsJMAP over WebSocket can be used by clients both running
inside and outside of a web browser. As such, the security
considerations in Sections and of
apply to those respective environments.IANA ConsiderationsRegistration of the WebSocket JMAP SubprotocolPer this specification, IANA has registered the following in the
"WebSocket Subprotocol Name Registry" within the "WebSocket Protocol
Registries".
Subprotocol Identifier:
jmap
Subprotocol Common Name:
WebSocket Transport for JMAP (JSON Meta Application
Protocol)
Subprotocol Definition:
RFC 8887
ReferencesNormative ReferencesKey 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.HTTP Over TLSThis memo describes how to use Transport Layer Security (TLS) to secure Hypertext Transfer Protocol (HTTP) connections over the Internet. This memo provides information for the Internet community.The 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]The WebSocket ProtocolThe WebSocket Protocol enables two-way communication between a client running untrusted code in a controlled environment to a remote host that has opted-in to communications from that code. The security model used for this is the origin-based security model commonly used by web browsers. The protocol consists of an opening handshake followed by basic message framing, layered over TCP. The goal of this technology is to provide a mechanism for browser-based applications that need two-way communication with servers that does not rely on opening multiple HTTP connections (e.g., using XMLHttpRequest or <iframe>s and long polling). [STANDARDS-TRACK]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.Recommendations for Secure Use of Transport Layer Security (TLS) and Datagram Transport Layer Security (DTLS)Transport Layer Security (TLS) and Datagram Transport Layer Security (DTLS) are widely used to protect data exchanged over application protocols such as HTTP, SMTP, IMAP, POP, SIP, and XMPP. Over the last few years, several serious attacks on TLS have emerged, including attacks on its most commonly used cipher suites and their modes of operation. This document provides recommendations for improving the security of deployed services that use TLS and DTLS. The recommendations are applicable to the majority of use cases.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.Compression Extensions for WebSocketThis document defines a framework for creating WebSocket extensions that add compression functionality to the WebSocket Protocol. An extension based on this framework compresses the payload data portion of WebSocket data messages on a per-message basis using parameters negotiated during the opening handshake. This framework provides a general method for applying a compression algorithm to the contents of WebSocket messages. Each compression algorithm has to be defined in a document defining the extension by specifying the parameter negotiation and the payload transformation algorithm in detail. This document also specifies one specific compression extension using the DEFLATE algorithm.Ambiguity of Uppercase vs Lowercase in RFC 2119 Key WordsRFC 2119 specifies common key words that may be used in protocol specifications. This document aims to reduce the ambiguity by clarifying that only UPPERCASE usage of the key words have the defined special meanings.Bootstrapping WebSockets with HTTP/2This document defines a mechanism for running the WebSocket Protocol (RFC 6455) over a single stream of an HTTP/2 connection.The Transport Layer Security (TLS) Protocol Version 1.3This document specifies version 1.3 of the Transport Layer Security (TLS) protocol. TLS allows client/server applications to communicate over the Internet in a way that is designed to prevent eavesdropping, tampering, and message forgery.This document updates RFCs 5705 and 6066, and obsoletes RFCs 5077, 5246, and 6961. This document also specifies new requirements for TLS 1.2 implementations.The JSON Meta Application Protocol (JMAP)This document specifies a protocol for clients to efficiently query, fetch, and modify JSON-based data objects, with support for push notification of changes and fast resynchronisation and for out-of- band binary data upload/download.Informative ReferencesThe JSON Meta Application Protocol (JMAP) for MailThis document specifies a data model for synchronising email data with a server using the JSON Meta Application Protocol (JMAP). Clients can use this to efficiently search, access, organise, and send messages, and to get push notifications for fast resynchronisation when new messages are delivered or a change is made in another client.AcknowledgmentsThe author would like to thank the following individuals for
contributing their ideas and support for writing this
specification: , , and .Author's AddressFastmail US LLC1429 Walnut Street, Suite 1201PhiladelphiaPA19102United States of Americamurch@fastmailteam.comhttp://www.fastmail.com/