π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Support accounts passkey RP migration
Manav Rathi28ed57a31108
diff --git a/cli/utils/constants/constants.go b/cli/utils/constants/constants.goindex 4618cc1e30..868fc6b2c1 100644--- a/cli/utils/constants/constants.go+++ b/cli/utils/constants/constants.go@@ -3,4 +3,4 @@ package constantsconst CliDataPath = "/cli-data/"const EnteApiUrl = "https://api.ente.com"-const EnteAccountUrl = "https://accounts.ente.io"+const EnteAccountUrl = "https://accounts.ente.com"diff --git a/docs/docs/photos/features/account/passkeys.md b/docs/docs/photos/features/account/passkeys.mdindex f3d65a731c..707c6c2ca5 100644--- a/docs/docs/photos/features/account/passkeys.md+++ b/docs/docs/photos/features/account/passkeys.md@@ -34,14 +34,15 @@ existing 2FA codes that you have configured (if any).Passkeys get enabled if you add one (or more) passkeys to your account.Conversely, passkeys get disabled if you remove all your existing passkeys.-To add and remove passkeys, use the _Passkey_ option in the settings menu. This-will open up _accounts.ente.io_, where you can manage your passkeys.+To add and remove passkeys, use the _Passkey_ option in the settings menu. This will open the Ente Accounts web app (_accounts.ente.com_), where you can manage your passkeys.++> [!NOTE]+>+> Ente Accounts has moved from _accounts.ente.io_ to _accounts.ente.com_. Older passkeys created on the old domain continue to work, and Ente will automatically open the right domain for your account. New passkeys are created on _accounts.ente.com_.## Login with passkeys-If passkeys are enabled, then _accounts.ente.io_ will automatically open when-you log into your Ente account on a new device. Here you can follow the-instructions given by the browser to verify your passkey.+If passkeys are enabled, then the Ente Accounts web app will automatically open when you log into your Ente account on a new device. Here you can follow the instructions given by the browser to verify your passkey.> These instructions different for each browser and device, but generally they> will ask you to use the same mechanism that you used when you created thediff --git a/docs/docs/self-hosting/installation/config.md b/docs/docs/self-hosting/installation/config.mdindex 17813cdd31..ad48aff2b2 100644--- a/docs/docs/self-hosting/installation/config.md+++ b/docs/docs/self-hosting/installation/config.md@@ -79,7 +79,7 @@ used for Compose and quickstart for ease of use.)| `apps.public-memories` | Memories app base endpoint for public memory shares | `https://memories.ente.com` || `apps.cast` | Cast app base endpoint | `https://cast.ente.com` || `apps.embed-albums` | Embed app base endpoint for embedded sharing | `https://embed.ente.com` |-| `apps.accounts` | Accounts app base endpoint (used for passkey-based 2FA) | `https://accounts.ente.io` |+| `apps.accounts` | Accounts app base endpoint (used for passkey-based 2FA) | `https://accounts.ente.com` |### Databasediff --git a/mobile/apps/auth/lib/core/constants.dart b/mobile/apps/auth/lib/core/constants.dartindex cebeb77dac..7b71492833 100644--- a/mobile/apps/auth/lib/core/constants.dart+++ b/mobile/apps/auth/lib/core/constants.dart@@ -6,7 +6,7 @@ const int thumbnailDataLimit = 100 * 1024;const String sentryDSN ="https://[email protected]/9";-const String kAccountsUrl = "https://accounts.ente.io";+const String kAccountsUrl = "https://accounts.ente.com";final Uri githubFeatureRequestUri = Uri.https("github.com",diff --git a/mobile/apps/locker/lib/core/constants.dart b/mobile/apps/locker/lib/core/constants.dartindex f997a1852d..18d7636480 100644--- a/mobile/apps/locker/lib/core/constants.dart+++ b/mobile/apps/locker/lib/core/constants.dart@@ -1,6 +1,6 @@import 'package:flutter/foundation.dart';-const String kAccountsUrl = "https://accounts.ente.io";+const String kAccountsUrl = "https://accounts.ente.com";const int microSecondsInDay = 86400000000;const int android11SDKINT = 30;diff --git a/mobile/apps/photos/lib/core/constants.dart b/mobile/apps/photos/lib/core/constants.dartindex a05d0d8dbb..79bdb9b7bb 100644--- a/mobile/apps/photos/lib/core/constants.dart+++ b/mobile/apps/photos/lib/core/constants.dart@@ -46,7 +46,7 @@ const kDefaultProductionEndpoint = 'https://api.ente.com';const kLegacyProductionEndpoint = 'https://api.ente.io';const kUploadProxyEndpoint = 'https://uploader.ente.com';const kPhotosWebDomain = 'photos.ente.com';-const kAccountsUrl = 'https://accounts.ente.io';+const kAccountsUrl = 'https://accounts.ente.com';const kFamilyUrl = 'https://family.ente.io';const int intMaxValue = 9223372036854775807;diff --git a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/auth/AuthSteps.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/auth/AuthSteps.ktindex a3574026db..3fd03620d4 100644--- a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/auth/AuthSteps.kt+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/auth/AuthSteps.kt@@ -164,7 +164,7 @@ internal fun OtpVerificationView(email = email,srp = srpAttributes,sessionId = payload.passkeySessionId.orEmpty(),- accountsUrl = payload.accountsUrl ?: "https://accounts.ente.io",+ accountsUrl = payload.accountsUrl ?: "https://accounts.ente.com",twoFactorSessionId = payload.twoFactorSessionId,password = null)@@ -590,7 +590,7 @@ private fun handleSrpResult(email = email,srp = srpAttributes,sessionId = result.passkeySessionId.orEmpty(),- accountsUrl = result.accountsUrl ?: "https://accounts.ente.io",+ accountsUrl = result.accountsUrl ?: "https://accounts.ente.com",twoFactorSessionId = result.twoFactorSessionId,password = password)diff --git a/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/network/NetworkConfiguration.kt b/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/network/NetworkConfiguration.ktindex 831fda0294..4d99b2ba12 100644--- a/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/network/NetworkConfiguration.kt+++ b/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/network/NetworkConfiguration.kt@@ -25,7 +25,7 @@ data class NetworkConfiguration(val default: NetworkConfiguration = NetworkConfiguration(apiEndpoint = "https://api.ente.com".toHttpUrl(),- accountsEndpoint = "https://accounts.ente.io".toHttpUrl(),+ accountsEndpoint = "https://accounts.ente.com".toHttpUrl(),castEndpoint = "https://api.ente.com".toHttpUrl(),publicAlbumsEndpoint = "https://albums.ente.com".toHttpUrl(),familyEndpoint = "https://family.ente.io".toHttpUrl()diff --git a/mobile/native/darwin/Apps/Ensu/Ensu/Auth/OtpVerificationView.swift b/mobile/native/darwin/Apps/Ensu/Ensu/Auth/OtpVerificationView.swiftindex 27d9d64cab..6f4f6021fb 100644--- a/mobile/native/darwin/Apps/Ensu/Ensu/Auth/OtpVerificationView.swift+++ b/mobile/native/darwin/Apps/Ensu/Ensu/Auth/OtpVerificationView.swift@@ -42,7 +42,7 @@ struct OtpVerificationView: View {email: email,srp: srpAttributes,sessionId: payload.passkeySessionId!,- accountsUrl: payload.accountsUrl ?? "https://accounts.ente.io",+ accountsUrl: payload.accountsUrl ?? "https://accounts.ente.com",twoFactorSessionId: payload.twoFactorSessionId,password: nil)diff --git a/mobile/native/darwin/Apps/Ensu/Ensu/Auth/PasswordView.swift b/mobile/native/darwin/Apps/Ensu/Ensu/Auth/PasswordView.swiftindex 3206a60d9f..0adcdac62d 100644--- a/mobile/native/darwin/Apps/Ensu/Ensu/Auth/PasswordView.swift+++ b/mobile/native/darwin/Apps/Ensu/Ensu/Auth/PasswordView.swift@@ -39,7 +39,7 @@ struct PasswordView: View {email: email,srp: srpAttributes,sessionId: result.passkeySessionId!,- accountsUrl: result.accountsUrl ?? "https://accounts.ente.io",+ accountsUrl: result.accountsUrl ?? "https://accounts.ente.com",twoFactorSessionId: result.twoFactorSessionId,password: password)diff --git a/mobile/native/darwin/Apps/Ensu/Ensu/Services/EnsuAuthService.swift b/mobile/native/darwin/Apps/Ensu/Ensu/Services/EnsuAuthService.swiftindex 7867d54e61..70c9ea5d64 100644--- a/mobile/native/darwin/Apps/Ensu/Ensu/Services/EnsuAuthService.swift+++ b/mobile/native/darwin/Apps/Ensu/Ensu/Services/EnsuAuthService.swift@@ -33,7 +33,7 @@ final class EnsuAuthService {private var networkFactory: NetworkFactoryprivate var accountsUrlFallback: String {- networkFactory.configuration.accountsEndpoint?.absoluteString ?? "https://accounts.ente.io"+ networkFactory.configuration.accountsEndpoint?.absoluteString ?? "https://accounts.ente.com"}private init() {diff --git a/mobile/native/darwin/Packages/EnteNetwork/Sources/EnteNetwork/Configuration/NetworkConfiguration.swift b/mobile/native/darwin/Packages/EnteNetwork/Sources/EnteNetwork/Configuration/NetworkConfiguration.swiftindex a9aded742e..27c5cbf576 100644--- a/mobile/native/darwin/Packages/EnteNetwork/Sources/EnteNetwork/Configuration/NetworkConfiguration.swift+++ b/mobile/native/darwin/Packages/EnteNetwork/Sources/EnteNetwork/Configuration/NetworkConfiguration.swift@@ -38,7 +38,7 @@ public struct NetworkConfiguration {// Default Ente configurationpublic static let `default` = NetworkConfiguration(apiEndpoint: URL(string: "https://api.ente.com")!,- accountsEndpoint: URL(string: "https://accounts.ente.io"),+ accountsEndpoint: URL(string: "https://accounts.ente.com"),castEndpoint: URL(string: "https://api.ente.com"), // Fix: Use same endpoint as web apppublicAlbumsEndpoint: URL(string: "https://albums.ente.com"),familyEndpoint: URL(string: "https://family.ente.io")diff --git a/mobile/packages/accounts/lib/services/user_service.dart b/mobile/packages/accounts/lib/services/user_service.dartindex 3135c0e170..4a619ee0bc 100644--- a/mobile/packages/accounts/lib/services/user_service.dart+++ b/mobile/packages/accounts/lib/services/user_service.dart@@ -46,7 +46,7 @@ import "package:pointycastle/srp/srp6_verifier_generator.dart";import 'package:shared_preferences/shared_preferences.dart';import "package:uuid/uuid.dart";-const String kAccountsUrl = "https://accounts.ente.io";+const String kAccountsUrl = "https://accounts.ente.com";class UserService {static const keyHasEnabledTwoFactor = "has_enabled_two_factor";diff --git a/rust/accounts/src/types.rs b/rust/accounts/src/types.rsindex d94e706af2..7a1b88f852 100644--- a/rust/accounts/src/types.rs+++ b/rust/accounts/src/types.rs@@ -10,7 +10,7 @@ use zeroize::Zeroize;pub const DEFAULT_API_BASE_URL: &str = PRODUCTION_API_BASE_URL;/// Default base URL for Ente's accounts broker.-pub const DEFAULT_ACCOUNTS_URL: &str = "https://accounts.ente.io";+pub const DEFAULT_ACCOUNTS_URL: &str = "https://accounts.ente.com";/// Boxed future returned by a configured sleep hook.pub type SleepFuture = Pin<Box<dyn Future<Output = ()> + 'static>>;diff --git a/server/cmd/museum/main.go b/server/cmd/museum/main.goindex 55c7e166b3..cc5c58f02a 100644--- a/server/cmd/museum/main.go+++ b/server/cmd/museum/main.go@@ -110,7 +110,8 @@ func main() {viper.SetDefault("apps.public-locker", "https://share.ente.com")viper.SetDefault("apps.public-paste", "https://paste.ente.com")viper.SetDefault("apps.public-memories", "https://memories.ente.com")- viper.SetDefault("apps.accounts", "https://accounts.ente.io")+ viper.SetDefault("apps.accounts", "https://accounts.ente.com")+ viper.SetDefault("apps.accounts-legacy", "https://accounts.ente.io")viper.SetDefault("apps.cast", "https://cast.ente.com")viper.SetDefault("apps.family", "https://family.ente.io")diff --git a/server/configurations/local.yaml b/server/configurations/local.yamlindex 0ed117fd2b..1d2dc0f525 100644--- a/server/configurations/local.yaml+++ b/server/configurations/local.yaml@@ -102,10 +102,17 @@ apps:public-paste:# Default is https://cast.ente.comcast:- # Default is https://accounts.ente.io# Set this to the URL where your accounts web app is running, primarily used for# passkey based 2FA.+ #+ # Default is https://accounts.ente.comaccounts:+ # Optional. Used only for Ente's accounts.ente.io -> accounts.ente.com+ # passkey migration. Users with passkeys scoped to webauthn.legacy-rpid are+ # sent here.+ #+ # Default is https://accounts.ente.io+ accounts-legacy:# Default is https://family.ente.iofamily:# Default is https://memories.ente.com@@ -325,6 +332,14 @@ webauthn:# See: https://github.com/go-webauthn/webauthnrporigins:- "http://localhost:3001"+ # Optional. Used only when migrating existing passkeys from an older RP ID.+ # Leave unset for normal deployments. Wrong RP/origin values can prevent+ # users from using their passkeys.+ #+ # Credentials without an rp_id are treated as belonging to legacy-rpid.+ # Users with such credentials keep using apps.accounts-legacy.+ legacy-rpid:+ legacy-rporigins: []# Discord config (optional)# Use case: Devopsdiff --git a/server/ente/passkeyCredential.go b/server/ente/passkeyCredential.goindex 3da7cbcc2b..7b8786beda 100644--- a/server/ente/passkeyCredential.go+++ b/server/ente/passkeyCredential.go@@ -10,12 +10,15 @@ import ("github.com/google/uuid")-// PasskeyCredential are the actual WebAuthn credentials we will send back to the user during auth for the browser to check if they have an eligible authenticator.+// PasskeyCredential is our stored representation of a WebAuthn credential.+// The credential material is converted back into webauthn.Credential during+// authentication; RPID records which relying party the credential is scoped to.type PasskeyCredential struct {PasskeyID uuid.UUID `json:"passkeyID"`CredentialID string `json:"credentialID"` // string+ RPID string `json:"rpID"`PublicKey string `json:"publicKey"` // b64 []byteAttestationType string `json:"attestationType"`AuthenticatorTransports string `json:"authenticatorTransports"` // comma-separated slice of stringsdiff --git a/server/ente/webauthnSession.go b/server/ente/webauthnSession.goindex ed4bcab3cf..38d96e370d 100644--- a/server/ente/webauthnSession.go+++ b/server/ente/webauthnSession.go@@ -20,6 +20,8 @@ type WebAuthnSession struct {UserID int64+ RPID string+AllowedCredentialIDs string // [][]byte as b64ExpiresAt int64diff --git a/server/migrations/122_passkey_rp_ids.down.sql b/server/migrations/122_passkey_rp_ids.down.sqlnew file mode 100644index 0000000000..d63aa857ff--- /dev/null+++ b/server/migrations/122_passkey_rp_ids.down.sql@@ -0,0 +1,5 @@+ALTER TABLE webauthn_sessions+ DROP COLUMN IF EXISTS rp_id;++ALTER TABLE passkey_credentials+ DROP COLUMN IF EXISTS rp_id;diff --git a/server/migrations/122_passkey_rp_ids.up.sql b/server/migrations/122_passkey_rp_ids.up.sqlnew file mode 100644index 0000000000..7668e688c3--- /dev/null+++ b/server/migrations/122_passkey_rp_ids.up.sql@@ -0,0 +1,5 @@+ALTER TABLE passkey_credentials+ ADD COLUMN IF NOT EXISTS rp_id TEXT;++ALTER TABLE webauthn_sessions+ ADD COLUMN IF NOT EXISTS rp_id TEXT;diff --git a/server/pkg/api/user.go b/server/pkg/api/user.goindex 28aacc3b6c..1ac9aade3f 100644--- a/server/pkg/api/user.go+++ b/server/pkg/api/user.go@@ -484,9 +484,14 @@ func (h *UserHandler) GetAccountsToken(c *gin.Context) {handler.Error(c, stacktrace.Propagate(err, ""))return}+ accountsURL, err := h.UserController.PasskeyRepo.AccountsURLForUser(userID)+ if err != nil {+ handler.Error(c, stacktrace.Propagate(err, ""))+ return+ }c.JSON(http.StatusOK, gin.H{"accountsToken": token,- "accountsUrl": viper.GetString("apps.accounts"),+ "accountsUrl": accountsURL,})}diff --git a/server/pkg/controller/user/userauth.go b/server/pkg/controller/user/userauth.goindex 24b973fbf0..619453307f 100644--- a/server/pkg/controller/user/userauth.go+++ b/server/pkg/controller/user/userauth.go@@ -614,7 +614,13 @@ func (c *UserController) onVerificationSuccess(context *gin.Context, email strinreturn ente.EmailAuthorizationResponse{}, stacktrace.Propagate(err, "")}}- accountsUrl := viper.GetString("apps.accounts")+ accountsUrl := ""+ if hasPasskeys {+ accountsUrl, err = c.PasskeyRepo.AccountsURLForUser(userID)+ if err != nil {+ return ente.EmailAuthorizationResponse{}, stacktrace.Propagate(err, "")+ }+ }if hasPasskeys && isTwoFactorEnabled {return ente.EmailAuthorizationResponse{ID: userID, PasskeySessionID: passKeySessionID, AccountsUrl: accountsUrl, TwoFactorSessionIDV2: twoFactorSessionID}, nil} else if hasPasskeys {diff --git a/server/pkg/repo/passkey/credential.go b/server/pkg/repo/passkey/credential.goindex 7d80070a98..507dbbc43d 100644--- a/server/pkg/repo/passkey/credential.go+++ b/server/pkg/repo/passkey/credential.go@@ -42,6 +42,7 @@ func (r *Repository) createPasskeyCredential(credential *ente.PasskeyCredential)_, err = r.DB.Exec(`INSERT INTO passkey_credentials(passkey_id,+ rp_id,public_key,attestation_type,authenticator_transports,@@ -57,9 +58,11 @@ func (r *Repository) createPasskeyCredential(credential *ente.PasskeyCredential)$5,$6,$7,- $8+ $8,+ $9)`,credential.PasskeyID,+ credential.RPID,credential.PublicKey,credential.AttestationType,credential.AuthenticatorTransports,diff --git a/server/pkg/repo/passkey/passkey.go b/server/pkg/repo/passkey/passkey.goindex eb249ed6f6..19e57779c8 100644--- a/server/pkg/repo/passkey/passkey.go+++ b/server/pkg/repo/passkey/passkey.go@@ -30,13 +30,19 @@ const ()type Repository struct {- DB *sql.DB- webAuthnInstance *webauthn.WebAuthn+ DB *sql.DB+ RPID string+ webAuthnInstance *webauthn.WebAuthn+ accountsURL string+ legacyRPID string+ legacyWebAuthnInstance *webauthn.WebAuthn+ legacyAccountsURL string}type PasskeyUser struct {*ente.Userrepo *Repository+ rpID string}func (u *PasskeyUser) WebAuthnID() []byte {@@ -55,7 +61,7 @@ func (u *PasskeyUser) WebAuthnDisplayName() string {}func (u *PasskeyUser) WebAuthnCredentials() []webauthn.Credential {- creds, err := u.repo.GetUserPasskeyCredentials(u.ID)+ creds, err := u.repo.GetUserPasskeyCredentials(u.ID, u.rpID)if err != nil {return []webauthn.Credential{}}@@ -71,12 +77,45 @@ func (u *PasskeyUser) WebAuthnIcon() string {func NewRepository(db *sql.DB,) (repo *Repository, err error) {- rpId := viper.GetString("webauthn.rpid")- rpOrigins := viper.GetStringSlice("webauthn.rporigins")+ rpID := viper.GetString("webauthn.rpid")+ webAuthnInstance, err := newWebAuthnInstance(rpID, viper.GetStringSlice("webauthn.rporigins"))+ if err != nil {+ return+ }++ legacyRPID := viper.GetString("webauthn.legacy-rpid")+ var legacyWebAuthnInstance *webauthn.WebAuthn+ if legacyRPID != "" && legacyRPID != rpID {+ legacyOrigins := viper.GetStringSlice("webauthn.legacy-rporigins")+ if len(legacyOrigins) == 0 {+ err = fmt.Errorf("webauthn.legacy-rporigins is required when webauthn.legacy-rpid is set")+ return+ }+ legacyWebAuthnInstance, err = newWebAuthnInstance(legacyRPID, legacyOrigins)+ if err != nil {+ return+ }+ } else {+ legacyRPID = ""+ }++ repo = &Repository{+ DB: db,+ webAuthnInstance: webAuthnInstance,+ RPID: rpID,+ accountsURL: viper.GetString("apps.accounts"),+ legacyRPID: legacyRPID,+ legacyWebAuthnInstance: legacyWebAuthnInstance,+ legacyAccountsURL: viper.GetString("apps.accounts-legacy"),+ }++ return+}+func newWebAuthnInstance(rpID string, rpOrigins []string) (*webauthn.WebAuthn, error) {wconfig := &webauthn.Config{RPDisplayName: "Ente",- RPID: rpId,+ RPID: rpID,RPOrigins: rpOrigins,Timeouts: webauthn.TimeoutsConfig{Login: webauthn.TimeoutConfig{@@ -90,17 +129,60 @@ func NewRepository(},}- webAuthnInstance, err := webauthn.New(wconfig)+ return webauthn.New(wconfig)+}++func (r *Repository) webAuthnInstanceForRPID(rpID string) (*webauthn.WebAuthn, error) {+ if rpID == r.RPID {+ return r.webAuthnInstance, nil+ }+ if rpID == r.legacyRPID {+ return r.legacyWebAuthnInstance, nil+ }+ return nil, fmt.Errorf("missing webauthn config for rp_id %q", rpID)+}++func (r *Repository) selectRPIDForUser(userID int64) (string, error) {+ if r.legacyRPID == "" {+ return r.RPID, nil+ }++ hasLegacyPasskeys, err := r.hasPasskeyCredentialsForRPID(userID, r.legacyRPID)if err != nil {- return+ return "", err+ }+ if hasLegacyPasskeys {+ return r.legacyRPID, nil}+ return r.RPID, nil+}- repo = &Repository{- DB: db,- webAuthnInstance: webAuthnInstance,+func (r *Repository) rpIDForSession(session *ente.WebAuthnSession) string {+ if session.RPID != "" {+ return session.RPID+ }+ if r.legacyRPID != "" {+ return r.legacyRPID}+ return r.RPID+}- return+func (r *Repository) includeCredentialsWithoutRPID(rpID string) bool {+ if r.legacyRPID != "" {+ return rpID == r.legacyRPID+ }+ return rpID == r.RPID+}++func (r *Repository) AccountsURLForUser(userID int64) (string, error) {+ rpID, err := r.selectRPIDForUser(userID)+ if err != nil {+ return "", err+ }+ if rpID == r.legacyRPID {+ return r.legacyAccountsURL, nil+ }+ return r.accountsURL, nil}func (r *Repository) GetPasskeyCount(userID int64) (count int64, err error) {@@ -139,12 +221,28 @@ func (r *Repository) GetUserPasskeys(userID int64) (passkeys []ente.Passkey, err}func (r *Repository) CreateBeginRegistrationData(user *ente.User) (options *protocol.CredentialCreation, session *webauthn.SessionData, id uuid.UUID, err error) {+ rpID, err := r.selectRPIDForUser(user.ID)+ if err != nil {+ err = stacktrace.Propagate(err, "")+ return+ }+ webAuthnInstance, err := r.webAuthnInstanceForRPID(rpID)+ if err != nil {+ err = stacktrace.Propagate(err, "")+ return+ }passkeyUser := &PasskeyUser{User: user,repo: r,+ rpID: rpID,}- if len(passkeyUser.WebAuthnCredentials()) >= ente.MaxPasskeys {+ passkeys, err := r.GetUserPasskeys(user.ID)+ if err != nil {+ err = stacktrace.Propagate(err, "")+ return+ }+ if len(passkeys) >= ente.MaxPasskeys {err = stacktrace.Propagate(&ente.ErrMaxPasskeysReached, "")return}@@ -160,9 +258,9 @@ func (r *Repository) CreateBeginRegistrationData(user *ente.User) (options *protRequireResidentKey: protocol.ResidentKeyRequired(),UserVerification: protocol.VerificationPreferred,}- options, session, err = r.webAuthnInstance.BeginRegistration(passkeyUser, webauthn.WithAuthenticatorSelection(authSelection))+ options, session, err = webAuthnInstance.BeginRegistration(passkeyUser, webauthn.WithAuthenticatorSelection(authSelection))} else {- options, session, err = r.webAuthnInstance.BeginRegistration(passkeyUser)+ options, session, err = webAuthnInstance.BeginRegistration(passkeyUser)}if err != nil {err = stacktrace.Propagate(err, "")@@ -170,7 +268,7 @@ func (r *Repository) CreateBeginRegistrationData(user *ente.User) (options *prot}// save session data- marshalledSessionData, err := r.marshalSessionDataToWebAuthnSession(session)+ marshalledSessionData, err := r.marshalSessionDataToWebAuthnSession(session, rpID)if err != nil {err = stacktrace.Propagate(err, "")return@@ -280,12 +378,23 @@ func (r *Repository) GetTokenData(sessionID string) (*ente.TwoFactorAuthorizatio}func (r *Repository) CreateBeginAuthenticationData(user *ente.User) (options *protocol.CredentialAssertion, session *webauthn.SessionData, id uuid.UUID, err error) {+ rpID, err := r.selectRPIDForUser(user.ID)+ if err != nil {+ err = stacktrace.Propagate(err, "")+ return+ }+ webAuthnInstance, err := r.webAuthnInstanceForRPID(rpID)+ if err != nil {+ err = stacktrace.Propagate(err, "")+ return+ }passkeyUser := &PasskeyUser{User: user,repo: r,+ rpID: rpID,}- options, session, err = r.webAuthnInstance.BeginLogin(passkeyUser)+ options, session, err = webAuthnInstance.BeginLogin(passkeyUser)if err != nil {if _, ok := err.(*protocol.Error); ok {protocolErr := err.(*protocol.Error)@@ -302,7 +411,7 @@ func (r *Repository) CreateBeginAuthenticationData(user *ente.User) (options *pr}// save session data- marshalledSessionData, err := r.marshalSessionDataToWebAuthnSession(session)+ marshalledSessionData, err := r.marshalSessionDataToWebAuthnSession(session, rpID)if err != nil {err = stacktrace.Propagate(err, "")return@@ -320,11 +429,6 @@ func (r *Repository) CreateBeginAuthenticationData(user *ente.User) (options *pr}func (r *Repository) FinishRegistration(user *ente.User, friendlyName string, req *http.Request, sessionID uuid.UUID) (err error) {- passkeyUser := &PasskeyUser{- User: user,- repo: r,- }-session, err := r.getWebAuthnSessionByID(sessionID)if err != nil {err = stacktrace.Propagate(err, "")@@ -336,6 +440,18 @@ func (r *Repository) FinishRegistration(user *ente.User, friendlyName string, rereturn}+ rpID := r.rpIDForSession(session)+ webAuthnInstance, err := r.webAuthnInstanceForRPID(rpID)+ if err != nil {+ err = stacktrace.Propagate(err, "")+ return+ }+ passkeyUser := &PasskeyUser{+ User: user,+ repo: r,+ rpID: rpID,+ }+sessionData, err := session.SessionData()if err != nil {err = stacktrace.Propagate(err, "")@@ -347,7 +463,7 @@ func (r *Repository) FinishRegistration(user *ente.User, friendlyName string, rereturn}- credential, err := r.webAuthnInstance.FinishRegistration(passkeyUser, *sessionData, req)+ credential, err := webAuthnInstance.FinishRegistration(passkeyUser, *sessionData, req)if err != nil {if strings.Contains(err.Error(), "Error parsing attestation response") {err = stacktrace.Propagate(ente.NewBadRequestWithMessage(err.Error()), "")@@ -363,7 +479,7 @@ func (r *Repository) FinishRegistration(user *ente.User, friendlyName string, rereturn}- passkeyCredential, err := r.marshalCredentialToPasskeyCredential(credential, newPasskey.ID)+ passkeyCredential, err := r.marshalCredentialToPasskeyCredential(credential, newPasskey.ID, rpID)if err != nil {err = stacktrace.Propagate(err, "")return@@ -379,11 +495,6 @@ func (r *Repository) FinishRegistration(user *ente.User, friendlyName string, re}func (r *Repository) FinishAuthentication(user *ente.User, req *http.Request, sessionID uuid.UUID) (err error) {- passkeyUser := &PasskeyUser{- User: user,- repo: r,- }-session, err := r.getWebAuthnSessionByID(sessionID)if err != nil {err = stacktrace.Propagate(err, "")@@ -395,6 +506,18 @@ func (r *Repository) FinishAuthentication(user *ente.User, req *http.Request, sereturn}+ rpID := r.rpIDForSession(session)+ webAuthnInstance, err := r.webAuthnInstanceForRPID(rpID)+ if err != nil {+ err = stacktrace.Propagate(err, "")+ return+ }+ passkeyUser := &PasskeyUser{+ User: user,+ repo: r,+ rpID: rpID,+ }+sessionData, err := session.SessionData()if err != nil {err = stacktrace.Propagate(err, "")@@ -406,7 +529,7 @@ func (r *Repository) FinishAuthentication(user *ente.User, req *http.Request, sereturn}- _, err = r.webAuthnInstance.FinishLogin(passkeyUser, *sessionData, req)+ _, err = webAuthnInstance.FinishLogin(passkeyUser, *sessionData, req)if err != nil {logrus.Warnf("Could not finish passkey authentication: %s", err)err = &ente.ApiError{Code: ente.BadRequest, Message: "Invalid signature", HttpStatusCode: http.StatusUnauthorized}@@ -451,6 +574,7 @@ func (r *Repository) saveSessionData(id uuid.UUID, session *ente.WebAuthnSessionid,challenge,user_id,+ rp_id,allowed_credential_ids,expires_at,user_verification_requirement,@@ -464,12 +588,14 @@ func (r *Repository) saveSessionData(id uuid.UUID, session *ente.WebAuthnSession$5,$6,$7,- $8+ $8,+ $9)`,id,session.Challenge,session.UserID,+ session.RPID,session.AllowedCredentialIDs,session.ExpiresAt,session.UserVerificationRequirement,@@ -479,7 +605,7 @@ func (r *Repository) saveSessionData(id uuid.UUID, session *ente.WebAuthnSessionreturn}-func (r *Repository) marshalCredentialToPasskeyCredential(cred *webauthn.Credential, passkeyID uuid.UUID) (*ente.PasskeyCredential, error) {+func (r *Repository) marshalCredentialToPasskeyCredential(cred *webauthn.Credential, passkeyID uuid.UUID, rpID string) (*ente.PasskeyCredential, error) {// Convert the PublicKey to base64publicKeyB64 := base64.StdEncoding.EncodeToString(cred.PublicKey)@@ -515,6 +641,7 @@ func (r *Repository) marshalCredentialToPasskeyCredential(cred *webauthn.CredentpasskeyCred := &ente.PasskeyCredential{CredentialID: credID,PasskeyID: passkeyID,+ RPID: rpID,PublicKey: publicKeyB64,AttestationType: cred.AttestationType,AuthenticatorTransports: authenticatorTransports,@@ -526,7 +653,7 @@ func (r *Repository) marshalCredentialToPasskeyCredential(cred *webauthn.Credentreturn passkeyCred, nil}-func (r *Repository) marshalSessionDataToWebAuthnSession(session *webauthn.SessionData) (webAuthnSession *ente.WebAuthnSession, err error) {+func (r *Repository) marshalSessionDataToWebAuthnSession(session *webauthn.SessionData, rpID string) (webAuthnSession *ente.WebAuthnSession, err error) {userID, err := byteMarshaller.ConvertBytesToInt64(session.UserID)if err != nil {@@ -541,6 +668,7 @@ func (r *Repository) marshalSessionDataToWebAuthnSession(session *webauthn.SessinewWebAuthnSession := &ente.WebAuthnSession{Challenge: session.Challenge,UserID: userID,+ RPID: rpID,AllowedCredentialIDs: byteMarshaller.EncodeSlices(session.AllowedCredentialIDs),ExpiresAt: session.Expires.UnixMicro(),UserVerificationRequirement: string(session.UserVerification),@@ -551,13 +679,27 @@ func (r *Repository) marshalSessionDataToWebAuthnSession(session *webauthn.Sessireturn newWebAuthnSession, nil}-func (r *Repository) GetUserPasskeyCredentials(userID int64) (credentials []webauthn.Credential, err error) {+func (r *Repository) GetUserPasskeyCredentials(userID int64, rpID string) (credentials []webauthn.Credential, err error) {rows, err := r.DB.Query(`- SELECT pc.*+ SELECT+ pc.passkey_id,+ pc.credential_id,+ COALESCE(pc.rp_id, $2) AS rp_id,+ pc.public_key,+ pc.attestation_type,+ pc.authenticator_transports,+ pc.credential_flags,+ pc.authenticator,+ pc.created_atFROM passkey_credentials pcJOIN passkeys p ON pc.passkey_id = p.id- WHERE p.user_id = $1 AND p.deleted_at IS NULL- `, userID)+ WHERE p.user_id = $1+ AND p.deleted_at IS NULL+ AND (+ pc.rp_id = $2+ OR (pc.rp_id IS NULL AND $3)+ )+ `, userID, rpID, r.includeCredentialsWithoutRPID(rpID))if err != nil {err = stacktrace.Propagate(err, "")return@@ -569,6 +711,7 @@ func (r *Repository) GetUserPasskeyCredentials(userID int64) (credentials []webaif err = rows.Scan(&pc.PasskeyID,&pc.CredentialID,+ &pc.RPID,&pc.PublicKey,&pc.AttestationType,&pc.AuthenticatorTransports,@@ -593,6 +736,25 @@ func (r *Repository) GetUserPasskeyCredentials(userID int64) (credentials []webareturn}+func (r *Repository) hasPasskeyCredentialsForRPID(userID int64, rpID string) (bool, error) {+ var count int64+ err := r.DB.QueryRow(`+ SELECT COUNT(*)+ FROM passkey_credentials pc+ JOIN passkeys p ON pc.passkey_id = p.id+ WHERE p.user_id = $1+ AND p.deleted_at IS NULL+ AND (+ pc.rp_id = $2+ OR (pc.rp_id IS NULL AND $3)+ )+ `, userID, rpID, r.includeCredentialsWithoutRPID(rpID)).Scan(&count)+ if err != nil {+ return false, stacktrace.Propagate(err, "")+ }+ return count > 0, nil+}+func (repo *Repository) RemoveExpiredPasskeySessions() error {_, err := repo.DB.Exec(`DELETE FROM webauthn_sessions WHERE expires_at <= $1`,ente_time.Microseconds())diff --git a/server/pkg/repo/passkey/session.go b/server/pkg/repo/passkey/session.goindex f51d86a27a..f16768e48a 100644--- a/server/pkg/repo/passkey/session.go+++ b/server/pkg/repo/passkey/session.go@@ -16,6 +16,7 @@ func (r *Repository) getWebAuthnSessionByID(sessionID uuid.UUID) (session *ente.id,challenge,user_id,+ COALESCE(rp_id, '') AS rp_id,allowed_credential_ids,expires_at,user_verification_requirement,@@ -25,6 +26,7 @@ func (r *Repository) getWebAuthnSessionByID(sessionID uuid.UUID) (session *ente.&session.ID,&session.Challenge,&session.UserID,+ &session.RPID,&session.AllowedCredentialIDs,&session.ExpiresAt,&session.UserVerificationRequirement,diff --git a/web/apps/accounts/README.md b/web/apps/accounts/README.mdindex 82f087f2d4..36c55af38f 100644--- a/web/apps/accounts/README.md+++ b/web/apps/accounts/README.md@@ -1,6 +1,6 @@# Ente Accounts-Code that runs on `accounts.ente.io`.+Code that runs on `accounts.ente.com`.Primarily, this serves a common domain where our clients can create andauthenticate using shared passkeys tied to the user's Ente account.@@ -12,6 +12,9 @@ authenticate using shared passkeys tied to the user's Ente account.> clients, but we do need a web origin to handle the passkey flow for the> desktop and mobile clients.+`accounts.ente.io` remains the legacy origin for users who already have+Passkeys scoped to the old `ente.io` relying-party ID.+For more details about the Passkey flows,[docs/webauthn-passkeys.md](../../docs/webauthn-passkeys.md).diff --git a/web/apps/accounts/src/pages/index.tsx b/web/apps/accounts/src/pages/index.tsxindex 9f8274d900..2ca9d20bda 100644--- a/web/apps/accounts/src/pages/index.tsx+++ b/web/apps/accounts/src/pages/index.tsx@@ -2,7 +2,7 @@ import React, { useEffect } from "react";const Page: React.FC = () => {useEffect(() => {- // There are no user navigable pages currently on accounts.ente.io.+ // There are no user navigable pages on the accounts app.window.location.href = "https://ente.com";}, []);diff --git a/web/apps/accounts/src/services/passkey.ts b/web/apps/accounts/src/services/passkey.tsindex 71fddac872..171cc8b0d2 100644--- a/web/apps/accounts/src/services/passkey.ts+++ b/web/apps/accounts/src/services/passkey.ts@@ -372,6 +372,7 @@ export const shouldRestrictToWhitelistedRedirect = () => {const hostname = new URL(window.location.origin).hostname;return (hostname.endsWith("localhost") ||+ hostname.endsWith(".ente.com") ||hostname.endsWith(".ente.io") ||hostname.endsWith(".ente.sh"));diff --git a/web/docs/deploy.md b/web/docs/deploy.mdindex cacc6201ab..6d01fe4aa8 100644--- a/web/docs/deploy.md+++ b/web/docs/deploy.md@@ -21,7 +21,7 @@ deployments, and the action that triggers them:| [photos.ente.com](https://photos.ente.com) | Production | Daily deploy of `main` || [albums.ente.com](https://albums.ente.com) | Production | Daily deploy of `main` || [auth.ente.com](https://auth.ente.com) | Production | Daily deploy of `main` |-| [accounts.ente.io](https://accounts.ente.io) | Production | Daily deploy of `main` |+| [accounts.ente.com](https://accounts.ente.com) | Production | Daily deploy of `main` || [cast.ente.com](https://cast.ente.com) | Production | Daily deploy of `main` || [payments.ente.com](https://payments.ente.com) | Production | Daily deploy of `main` || [ente.com/help](https://ente.com/help) | Production | Changes in `docs/` on push to `main` |@@ -33,6 +33,8 @@ Apart from this, there are also some other deployments:- `family.ente.io` is currently in a separate repository (Enhancement: bring itin here).+- `accounts.ente.io` remains the legacy Passkey RP origin during the+ `accounts.ente.com` dual-RP migration.---diff --git a/web/docs/webauthn-passkeys.md b/web/docs/webauthn-passkeys.mdindex b994fc98e4..97c0fa00d1 100644--- a/web/docs/webauthn-passkeys.md+++ b/web/docs/webauthn-passkeys.md@@ -51,11 +51,12 @@ used.** This restriction is a byproduct of the enablement for automatic login.| Key | Type | Value || ------------- | ------ | ----------------------------------------------------------------- || accountsToken | string | The Accounts-specific JWT session token. It is encoded in base64. |+| accountsUrl | string | The Accounts origin the client should open for this user. |### Automatically logging into Ente AccountsClients open a WebView with the URL-`https://accounts.ente.io/passkeys?token=<accountsToken>`.+`<accountsUrl>/passkeys?token=<accountsToken>`.If the token is valid, the user will be show a list of their passkeys, and theycan edit / delete them, or add new ones.@@ -303,7 +304,7 @@ The client should redirect the user to the Ente Accounts web app with thissession ID to prompt credential authentication.```-https://accounts.ente.io/passkeys?+https://accounts.ente.com/passkeys?passkeySessionID=<sid>&clientPackage=<pkg>&redirect=<redirect>&recover=<recover-redirect>```@@ -311,6 +312,10 @@ https://accounts.ente.io/passkeys?We use Ente Accounts as the central WebAuthn hub since it allows us to handlemobile and desktop clients too.+During the dual-RP migration, the server returns `accounts.ente.io` for users+who still have legacy `ente.io` passkeys, and `accounts.ente.com` for users+without legacy passkeys.+### Requesting publicKey options (begin)#### POST /users/two-factor/passkeys/begindiff --git a/web/packages/accounts-rs/services/passkey.ts b/web/packages/accounts-rs/services/passkey.tsindex 1f1d20633e..64fe3a2c39 100644--- a/web/packages/accounts-rs/services/passkey.ts+++ b/web/packages/accounts-rs/services/passkey.ts@@ -79,16 +79,16 @@ interface OpenPasskeyVerificationURLOptions {* Photos web app.** Thus, passkey creation and authentication in the desktop app works the same- * way it works in the mobile app - the system browser is invoked to open- * accounts.ente.io.+ * way it works in the mobile app - the system browser is invoked to open the+ * accounts app origin (e.g. accounts.ente.com) returned by remote.*- * - For passkey creation, this is a one-way open. Passkeys get created at- * accounts.ente.io, and that's it.+ * - For passkey creation, this is a one-way open. Passkeys get created at the+ * accounts app origin, and that's it.** - For passkey verification, the flow is two-way. We register a custom* protocol and provide that as a return path redirect. Passkey authentication- * happens at accounts.ente.io, and on success there is redirected back to the- * desktop app.+ * happens at the accounts app origin, and on success there is redirected back+ * to the desktop app.*/export const openPasskeyVerificationURL = ({passkeySessionID,@@ -200,7 +200,7 @@ export const passkeySessionExpiredErrorMessage = "Passkey session has expired";* Check if the user has already authenticated using their passkey for the given* session.*- * This is useful in case the automatic redirect back from accounts.ente.io to+ * This is useful in case the automatic redirect back from the accounts app to* the desktop app does not work for some reason. In such cases, the user can* press the "Check status" button: we'll make an API call to see if the* authentication has already completed, and if so, get the same "response"diff --git a/web/packages/accounts/services/passkey.ts b/web/packages/accounts/services/passkey.tsindex c2803d4d70..f213281b6f 100644--- a/web/packages/accounts/services/passkey.ts+++ b/web/packages/accounts/services/passkey.ts@@ -79,16 +79,16 @@ interface OpenPasskeyVerificationURLOptions {* Photos web app.** Thus, passkey creation and authentication in the desktop app works the same- * way it works in the mobile app - the system browser is invoked to open- * accounts.ente.io.+ * way it works in the mobile app - the system browser is invoked to open the+ * accounts app origin (e.g. accounts.ente.com) returned by remote.*- * - For passkey creation, this is a one-way open. Passkeys get created at- * accounts.ente.io, and that's it.+ * - For passkey creation, this is a one-way open. Passkeys get created at the+ * accounts app origin, and that's it.** - For passkey verification, the flow is two-way. We register a custom* protocol and provide that as a return path redirect. Passkey authentication- * happens at accounts.ente.io, and on success there is redirected back to the- * desktop app.+ * happens at the accounts app origin, and on success there is redirected back+ * to the desktop app.*/export const openPasskeyVerificationURL = ({passkeySessionID,@@ -200,7 +200,7 @@ export const passkeySessionExpiredErrorMessage = "Passkey session has expired";* Check if the user has already authenticated using their passkey for the given* session.*- * This is useful in case the automatic redirect back from accounts.ente.io to+ * This is useful in case the automatic redirect back from the accounts app to* the desktop app does not work for some reason. In such cases, the user can* press the "Check status" button: we'll make an API call to see if the* authentication has already completed, and if so, get the same "response"