Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[server] Create totpSession when both passkey and totp are enabled

Neeraj Gupta04ee6f816169
diff --git a/server/ente/user.go b/server/ente/user.go
index 9503af6424..aa2e3ca142 100644
--- a/server/ente/user.go
+++ b/server/ente/user.go
@@ -55,6 +55,10 @@ type EmailAuthorizationResponse struct {
Token string `json:"token,omitempty"`
PasskeySessionID string `json:"passkeySessionID"`
TwoFactorSessionID string `json:"twoFactorSessionID"`
+ // TwoFactorSessionIDV2 is set only if user has both passkey and two factor enabled.
+ // This is to ensure older clients keep using passkey flow when both are set. We can remove
+ // This field once the clients starts surface both options for performing 2fa
+ TwoFactorSessionIDV2 string `json:"twoFactorSessionIDV2"`
// SrpM2 is sent only if the user is logging via SRP
// SrpM2 is the SRP M2 value aka the proof that the server has the verifier
SrpM2 *string `json:"srpM2,omitempty"`
diff --git a/server/pkg/controller/user/userauth.go b/server/pkg/controller/user/userauth.go
index 873942f15d..33f41b03d8 100644
--- a/server/pkg/controller/user/userauth.go
+++ b/server/pkg/controller/user/userauth.go
@@ -379,10 +379,10 @@ func (c *UserController) onVerificationSuccess(context *gin.Context, email strin
if err != nil {
return ente.EmailAuthorizationResponse{}, stacktrace.Propagate(err, "")
}
+ var passKeySessionID, twoFactorSessionID string
- // if the user has passkeys, we will prioritize that over secret TOTP
if hasPasskeys {
- passKeySessionID, err := auth.GenerateURLSafeRandomString(PassKeySessionIDLength)
+ passKeySessionID, err = auth.GenerateURLSafeRandomString(PassKeySessionIDLength)
if err != nil {
return ente.EmailAuthorizationResponse{}, stacktrace.Propagate(err, "")
}
@@ -390,20 +390,23 @@ func (c *UserController) onVerificationSuccess(context *gin.Context, email strin
if err != nil {
return ente.EmailAuthorizationResponse{}, stacktrace.Propagate(err, "")
}
- return ente.EmailAuthorizationResponse{ID: userID, PasskeySessionID: passKeySessionID}, nil
- } else {
- if isTwoFactorEnabled {
- twoFactorSessionID, err := auth.GenerateURLSafeRandomString(TwoFactorSessionIDLength)
- if err != nil {
- return ente.EmailAuthorizationResponse{}, stacktrace.Propagate(err, "")
- }
- err = c.TwoFactorRepo.AddTwoFactorSession(userID, twoFactorSessionID, time.Microseconds()+TwoFactorValidityDurationInMicroSeconds)
- if err != nil {
- return ente.EmailAuthorizationResponse{}, stacktrace.Propagate(err, "")
- }
- return ente.EmailAuthorizationResponse{ID: userID, TwoFactorSessionID: twoFactorSessionID}, nil
+ }
+ if isTwoFactorEnabled {
+ twoFactorSessionID, err = auth.GenerateURLSafeRandomString(TwoFactorSessionIDLength)
+ if err != nil {
+ return ente.EmailAuthorizationResponse{}, stacktrace.Propagate(err, "")
}
-
+ err = c.TwoFactorRepo.AddTwoFactorSession(userID, twoFactorSessionID, time.Microseconds()+TwoFactorValidityDurationInMicroSeconds)
+ if err != nil {
+ return ente.EmailAuthorizationResponse{}, stacktrace.Propagate(err, "")
+ }
+ }
+ if hasPasskeys && isTwoFactorEnabled {
+ return ente.EmailAuthorizationResponse{ID: userID, PasskeySessionID: passKeySessionID, TwoFactorSessionIDV2: twoFactorSessionID}, nil
+ } else if hasPasskeys {
+ return ente.EmailAuthorizationResponse{ID: userID, PasskeySessionID: passKeySessionID}, nil
+ } else if isTwoFactorEnabled {
+ return ente.EmailAuthorizationResponse{ID: userID, TwoFactorSessionID: twoFactorSessionID}, nil
}
token, err := auth.GenerateURLSafeRandomString(TokenLength)