diff --git a/crates/jmap-proto/src/request/capability.rs b/crates/jmap-proto/src/request/capability.rs index e26f1265..65e660c0 100644 --- a/crates/jmap-proto/src/request/capability.rs +++ b/crates/jmap-proto/src/request/capability.rs @@ -190,6 +190,14 @@ pub struct InbuxaAccountCapabilities { pub mail_sharing: bool, #[serde(rename(serialize = "addAccounts"))] pub add_accounts: bool, + /// PK-19: whether the principal may add a passkey to their own account + /// now: it holds `sysPasskeyCreate` and no switch turns passkeys off + /// for it (PK-12, PK-13). Lets a client show that up front. + #[serde(rename(serialize = "passkeysAllowed"))] + pub passkeys_allowed: bool, + /// PK-19: how many passkeys an account may have (`maxPasskeys`). + #[serde(rename(serialize = "maxPasskeys"))] + pub max_passkeys: u64, } #[derive(Debug, Clone, serde::Serialize)] diff --git a/crates/jmap/src/api/session.rs b/crates/jmap/src/api/session.rs index 116a6805..080df3f0 100644 --- a/crates/jmap/src/api/session.rs +++ b/crates/jmap/src/api/session.rs @@ -91,6 +91,15 @@ impl SessionHandler for Server { ) .await .caused_by(trc::location!())?; + // inbuxa: PK-19: whether adding a passkey would be refused + let passkey_settings = crate::inbuxa::passkey::settings(self).await?; + let passkeys_allowed = access_token.has_permission(Permission::SysPasskeyCreate) + && crate::inbuxa::passkey::allowed_for( + self, + &passkey_settings, + access_token.account_id(), + ) + .await?; account.account_capabilities.append( Capability::Inbuxa, Capabilities::Inbuxa(InbuxaAccountCapabilities { @@ -100,6 +109,8 @@ impl SessionHandler for Server { ai_explain, mail_sharing: sharing.mail_sharing, add_accounts: sharing.add_accounts, + passkeys_allowed, + max_passkeys: passkey_settings.max_passkeys.clamp(1, 100), }), ); // inbuxa: Fastmail's Masked Email API, for accounts that may hold masks diff --git a/docs/spec/features/passkeys.md b/docs/spec/features/passkeys.md index cc669399..283a93a2 100644 --- a/docs/spec/features/passkeys.md +++ b/docs/spec/features/passkeys.md @@ -170,6 +170,12 @@ passwords. - **PK-16.** An administrator can destroy any account's passkeys, which is the recovery path for a user who lost them all. Deleting an account deletes its passkeys, its user handle and both index entries. +- **PK-19.** The session's `urn:inbuxa:jmap` capability on the signed-in + principal's own account carries `passkeysAllowed` (it holds + `sysPasskeyCreate` and PK-12 and PK-13 leave passkeys on for it) and + `maxPasskeys`. A client uses it to say up front that passkeys are off + instead of offering an add that the server will refuse. An older server + leaves both out; a client then offers the add and shows the refusal. ### Recording @@ -229,6 +235,9 @@ passwords. account can't use a passkey whose user handle belonged to it (PK-16). 10. The audit log shows create, rename and destroy; the Logs page shows the sign-in with `type = passkey` (PK-17, PK-18). +12. The session says `passkeysAllowed: true` and `maxPasskeys` for an account + that may add one, and `false` once its domain switches passkeys off + (PK-19). 11. A server built before this feature starts on a store holding passkeys and signs everyone in with passwords (rollback). diff --git a/tests/src/jmap/principal/get.rs b/tests/src/jmap/principal/get.rs index 6b5b7ed5..b5e5f90a 100644 --- a/tests/src/jmap/principal/get.rs +++ b/tests/src/jmap/principal/get.rs @@ -254,7 +254,7 @@ pub async fn test(test: &TestServer) { // inbuxa: MT-22, the logo that applies to the account, and // LP-19, whether the legacy protocols are open to it, and // ai-explain EX-1, whether Explain can be offered - "urn:inbuxa:jmap": { "logo": null, "legacyProtocols": "enabled", "legacyAllowed": ["imap", "pop3", "manageSieve", "submission"], "aiExplain": false, "mailSharing": true, "addAccounts": true }, + "urn:inbuxa:jmap": { "logo": null, "legacyProtocols": "enabled", "legacyAllowed": ["imap", "pop3", "manageSieve", "submission"], "aiExplain": false, "mailSharing": true, "addAccounts": true, "passkeysAllowed": true, "maxPasskeys": 10 }, "https://www.fastmail.com/dev/maskedemail": {} } } diff --git a/tests/src/system/passkeys.rs b/tests/src/system/passkeys.rs index b20e0f11..52845718 100644 --- a/tests/src/system/passkeys.rs +++ b/tests/src/system/passkeys.rs @@ -55,6 +55,12 @@ async fn call(account: &Account, method: &str, mut arguments: Value) -> (String, ) } +/// PK-19: the session's flag for the signed-in account. +async fn session_allows(account: &Account) -> Value { + let session = account.jmap_session_object().await; + session.0["accounts"][account.id_string()]["accountCapabilities"]["urn:inbuxa:jmap"].clone() +} + async fn list(account: &Account, of: &Account) -> Vec { let (name, response) = call( account, @@ -731,6 +737,11 @@ async fn policy(admin: &Account, user: &Account, key: &SoftKey, client_id: &str) ) .await; + // PK-19: the session says adding would work + let caps = session_allows(user).await; + assert_eq!(caps["passkeysAllowed"], true, "{caps}"); + assert_eq!(caps["maxPasskeys"], 10, "{caps}"); + // PK-12: the domain's off switch stops adding and signing in let domain_id = admin.find_or_create_domain("example.com").await; admin @@ -750,6 +761,9 @@ async fn policy(admin: &Account, user: &Account, key: &SoftKey, client_id: &str) response["notCreated"]["k"]["type"], "forbidden", "{response}" ); + // PK-19: and the session says so up front + let caps = session_allows(user).await; + assert_eq!(caps["passkeysAllowed"], false, "{caps}"); let challenge = new_challenge().await; let response = login(client_id, key.get(&challenge, 9, ORIGIN)).await; assert_eq!(response["type"], "failure", "{response}");