You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2026/10/19 13:43:23 UTC
(james-project) 08/08: fixup! [ENHANCEMENT] JMAP Web Push: VAPID (RFC-9749)
This is an automated email from the ASF dual-hosted git repository.
chibenwa pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 0888cddf267fd26c05cbd24be9b99665138d059b
Author: Clement Guyon <cg...@linagora.com>
AuthorDate: Tue Oct 13 11:39:28 2026 +0200
fixup! [ENHANCEMENT] JMAP Web Push: VAPID (RFC-9749)
Derive the session state from the VAPID key (RFC-9749 section 5), so that
clients watching the session subscribe again after a change of key.
---
docs/modules/servers/partials/configure/jmap.adoc | 9 +++---
.../rfc8621/contract/WebPushVapidContract.scala | 32 +++++++++++++++++++++-
.../org/apache/james/jmap/core/Capability.scala | 3 +-
.../james/jmap/core/JmapRfc8621Configuration.scala | 11 +++++++-
.../org/apache/james/jmap/routes/JmapApi.scala | 2 +-
.../apache/james/jmap/routes/SessionSupplier.scala | 3 +-
.../james/jmap/routes/SessionSupplierTest.scala | 29 +++++++++++++++++++-
7 files changed, 78 insertions(+), 11 deletions(-)
diff --git a/docs/modules/servers/partials/configure/jmap.adoc b/docs/modules/servers/partials/configure/jmap.adoc
index 03b0d1bd38..1fd51d8151 100644
--- a/docs/modules/servers/partials/configure/jmap.adoc
+++ b/docs/modules/servers/partials/configure/jmap.adoc
@@ -120,8 +120,8 @@ encoded, as Web Push tools generate it. When set, with `webpush.vapid.private.ke
authenticated with it, and the JMAP session advertises it as the `applicationServerKey` of the
`urn:ietf:params:jmap:webpush-vapid` capability (https://www.rfc-editor.org/rfc/rfc9749[RFC-9749]), which browsers need
to subscribe. Defaults to no VAPID: requests are not authenticated and the capability is not advertised.
-The key pair is meant to stay: key rotation (RFC-9749 section 5) is not implemented. After a change, push services
-refuse the pushes of the subscriptions created with the former key, until clients subscribe again.
+The key pair is meant to stay. After a change the session state changes, which tells clients to subscribe again
+(RFC-9749 section 5), but push services refuse the pushes of the subscriptions created with the former key until they do.
| webpush.vapid.private.key
| Optional string. Private key matching `webpush.vapid.public.key`: a P-256 private key (32 bytes), base64url encoded.
@@ -297,8 +297,9 @@ copied. The {server-name} refuses to start when the two keys do not match.
as `mailto:postmaster@domain.tld`, or the `https:` URL of a contact page. It is sent to the push services only, never
to the users.
- Use the same key pair on every node of a cluster, and keep it: subscriptions are bound to the key they were created
-with. Key rotation (RFC-9749 section 5) is not implemented, hence after a change push services refuse the pushes of
-existing subscriptions until clients subscribe again.
+with. After a change of key the session state changes, which tells clients to subscribe again (RFC-9749 section 5).
+There is no transitional period: the former key no longer signs, hence push services refuse the pushes of existing
+subscriptions until clients subscribe again, and these subscriptions are kept until they expire.
== Annotated specification
diff --git a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/WebPushVapidContract.scala b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/WebPushVapidContract.scala
index 69c1e53651..98f2d39663 100644
--- a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/WebPushVapidContract.scala
+++ b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/WebPushVapidContract.scala
@@ -23,8 +23,8 @@ import java.math.BigInteger
import java.nio.charset.StandardCharsets
import java.security.KeyPair
import java.security.interfaces.{ECPrivateKey, ECPublicKey}
-import java.util.Base64
import java.util.concurrent.TimeUnit
+import java.util.{Base64, UUID}
import com.google.crypto.tink.apps.webpush.WebPushHybridDecrypt
import com.google.crypto.tink.subtle.EllipticCurves.{CurveType, EcdsaEncoding, PointFormatType}
@@ -158,6 +158,36 @@ trait WebPushVapidContract {
assertThat(applicationServerKey).isEqualTo(APPLICATION_SERVER_KEY)
}
+ @Test
+ def sessionStateShouldDependOnTheApplicationServerKey(): Unit = {
+ val sessionState: String = `given`()
+ .when()
+ .get("/session")
+ .`then`
+ .statusCode(SC_OK)
+ .extract()
+ .jsonPath()
+ .get("state")
+
+ val responseSessionState: String = `given`
+ .body(
+ """{
+ | "using": ["urn:ietf:params:jmap:core"],
+ | "methodCalls": [["Core/echo", {}, "c1"]]
+ |}""".stripMargin)
+ .when
+ .post
+ .`then`
+ .statusCode(SC_OK)
+ .extract()
+ .jsonPath()
+ .get("sessionState")
+
+ assertThat(sessionState)
+ .isEqualTo(UUID.nameUUIDFromBytes(APPLICATION_SERVER_KEY.getBytes(StandardCharsets.UTF_8)).toString)
+ assertThat(responseSessionState).isEqualTo(sessionState)
+ }
+
@Test
def pushVerificationShouldBeAuthenticated(pushServer: ClientAndServer): Unit = {
createPushSubscription(pushServer)
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/core/Capability.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/core/Capability.scala
index 363a791a29..84c4331cb4 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/core/Capability.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/core/Capability.scala
@@ -151,8 +151,7 @@ case class WebPushVapidCapabilityFactory(configuration: JmapRfc8621Configuration
override def createReactive(urlPrefixes: UrlPrefixes, username: Username): Publisher[Capability] =
capability().map(SMono.just[Capability]).getOrElse(SMono.empty[Capability])
- private def capability(): Option[Capability] = configuration.vapid
- .filter(_ => configuration.webPushEnabled)
+ private def capability(): Option[Capability] = configuration.advertisedVapid
.map(vapid => WebPushVapidCapability(WebPushVapidCapabilityProperties(vapid.applicationServerKey)))
}
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/core/JmapRfc8621Configuration.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/core/JmapRfc8621Configuration.scala
index a20ca85a25..886459fb8e 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/core/JmapRfc8621Configuration.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/core/JmapRfc8621Configuration.scala
@@ -20,8 +20,9 @@
package org.apache.james.jmap.core
import java.net.URI
+import java.nio.charset.StandardCharsets
import java.time.temporal.ChronoUnit
-import java.util.Optional
+import java.util.{Optional, UUID}
import com.google.common.base.Preconditions
import com.google.common.collect.ImmutableList
@@ -160,6 +161,14 @@ case class JmapRfc8621Configuration(urlPrefixString: String,
preventServerSideRequestForgery = preventServerSideRequestForgery,
vapid = vapid)
+ // The VAPID key clients subscribe with: none when Web Push is disabled
+ val advertisedVapid: Option[VapidConfiguration] = vapid.filter(_ => webPushEnabled)
+
+ // RFC 9749 section 5: the session state changes with the VAPID key, which tells clients to subscribe again
+ val sessionState: UuidState = advertisedVapid
+ .map(vapid => UuidState(UUID.nameUUIDFromBytes(vapid.applicationServerKey.getBytes(StandardCharsets.UTF_8))))
+ .getOrElse(UuidState.INSTANCE)
+
def urlPrefixes(): UrlPrefixes = UrlPrefixes(new URI(urlPrefixString), new URI(websocketPrefixString))
def getAuthenticationStrategiesAsJava(): Optional[java.util.List[String]] = authenticationStrategies.toJava
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/JmapApi.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/JmapApi.scala
index 54ce755f7a..f2251c7af0 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/JmapApi.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/JmapApi.scala
@@ -53,7 +53,7 @@ class JMAPApi (methods: Set[Method], defaultCapabilities: Set[CapabilityIdentifi
_ <- validateMaxCalls(requestObject)
} yield {
processSequentiallyAndUpdateContext(requestObject, mailboxSession, processingContext, capabilities)
- .map(invocations => ResponseObject(ResponseObject.SESSION_STATE, invocations.map(_.invocation)))
+ .map(invocations => ResponseObject(configuration.sessionState, invocations.map(_.invocation)))
}
validatedRequestObject.fold(e => SMono.error(e), obj => obj)
}
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/SessionSupplier.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/SessionSupplier.scala
index 0209004c79..df48fa5bda 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/SessionSupplier.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/SessionSupplier.scala
@@ -57,7 +57,8 @@ class SessionSupplier(capabilityFactories: Set[CapabilityFactory], configuration
apiUrl = urlEndpointResolver.apiUrl,
downloadUrl = urlEndpointResolver.downloadUrl,
uploadUrl = urlEndpointResolver.uploadUrl,
- eventSourceUrl = urlEndpointResolver.eventSourceUrl)
+ eventSourceUrl = urlEndpointResolver.eventSourceUrl,
+ state = configuration.sessionState)
}
}
diff --git a/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/routes/SessionSupplierTest.scala b/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/routes/SessionSupplierTest.scala
index 41f04cd3bc..46f66c1a1d 100644
--- a/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/routes/SessionSupplierTest.scala
+++ b/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/routes/SessionSupplierTest.scala
@@ -21,7 +21,7 @@ package org.apache.james.jmap.routes
import org.apache.james.core.Username
import org.apache.james.jmap.core.CapabilityIdentifier.JMAP_WEBPUSH_VAPID
-import org.apache.james.jmap.core.{DefaultCapabilities, JmapRfc8621Configuration, WebPushVapidCapabilityProperties}
+import org.apache.james.jmap.core.{DefaultCapabilities, JmapRfc8621Configuration, UuidState, WebPushVapidCapabilityProperties}
import org.apache.james.jmap.pushsubscription.VapidTestFixture
import org.apache.james.jmap.routes.SessionSupplierTest.USERNAME
import org.scalatest.matchers.should.Matchers
@@ -63,6 +63,33 @@ class SessionSupplierTest extends AnyWordSpec with Matchers {
.capabilities.ids should not contain JMAP_WEBPUSH_VAPID
}
+ "keep the session state when no key pair is configured" in {
+ new SessionSupplier(DefaultCapabilities.supported(JmapRfc8621Configuration.LOCALHOST_CONFIGURATION), JmapRfc8621Configuration.LOCALHOST_CONFIGURATION)
+ .generate(USERNAME, Set(), JmapRfc8621Configuration.LOCALHOST_CONFIGURATION.urlPrefixes()).blockOption().get
+ .state should equal(UuidState.INSTANCE)
+ }
+
+ "keep the session state when Web Push is disabled" in {
+ val configuration = JmapRfc8621Configuration.LOCALHOST_CONFIGURATION.copy(vapid = Some(VapidTestFixture.CONFIGURATION), webPushEnabled = false)
+
+ new SessionSupplier(DefaultCapabilities.supported(configuration), configuration)
+ .generate(USERNAME, Set(), configuration.urlPrefixes()).blockOption().get
+ .state should equal(UuidState.INSTANCE)
+ }
+
+ "change the session state with the VAPID key" in {
+ val configuration = JmapRfc8621Configuration.LOCALHOST_CONFIGURATION.copy(vapid = Some(VapidTestFixture.CONFIGURATION))
+ val rotated = configuration.copy(vapid = Some(VapidTestFixture.CONFIGURATION.copy(applicationServerKey = "another key")))
+
+ def state(configuration: JmapRfc8621Configuration): UuidState =
+ new SessionSupplier(DefaultCapabilities.supported(configuration), configuration)
+ .generate(USERNAME, Set(), configuration.urlPrefixes()).blockOption().get.state
+
+ state(configuration) should not equal UuidState.INSTANCE
+ state(configuration) should equal(state(configuration))
+ state(rotated) should not equal state(configuration)
+ }
+
"return correct account" which {
val accounts = new SessionSupplier(DefaultCapabilities.supported(JmapRfc8621Configuration.LOCALHOST_CONFIGURATION), JmapRfc8621Configuration.LOCALHOST_CONFIGURATION)
.generate(USERNAME, Set(), JmapRfc8621Configuration.LOCALHOST_CONFIGURATION.urlPrefixes()).blockOption().get.accounts
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org