From 990b8cda962f9d36389909cf6618f7ae2c8572d1 Mon Sep 17 00:00:00 2001 From: James Houlahan Date: Mon, 5 Dec 2022 12:05:35 +0100 Subject: [PATCH] GODT-2180: Allow login with FIDO2 The API docs didn't specify what the "integer" meant. Turns out it's a bitfield; we can't compare with equality. --- internal/bridge/user.go | 2 +- internal/frontend/cli/accounts.go | 2 +- internal/frontend/grpc/service_methods.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/bridge/user.go b/internal/bridge/user.go index e8eff23c..465c5fa6 100644 --- a/internal/bridge/user.go +++ b/internal/bridge/user.go @@ -182,7 +182,7 @@ func (bridge *Bridge) LoginFull( return "", fmt.Errorf("failed to begin login process: %w", err) } - if auth.TwoFA.Enabled == proton.TOTPEnabled { + if auth.TwoFA.Enabled&proton.TOTPEnabled != 0 { logrus.WithField("userID", auth.UserID).Info("Requesting TOTP") totp, err := getTOTP() diff --git a/internal/frontend/cli/accounts.go b/internal/frontend/cli/accounts.go index 00fa69ee..10884d4a 100644 --- a/internal/frontend/cli/accounts.go +++ b/internal/frontend/cli/accounts.go @@ -149,7 +149,7 @@ func (f *frontendCLI) loginAccount(c *ishell.Context) { //nolint:funlen return } - if auth.TwoFA.Enabled == proton.TOTPEnabled { + if auth.TwoFA.Enabled&proton.TOTPEnabled != 0 { code := f.readStringInAttempts("Two factor code", c.ReadLine, isNotEmpty) if code == "" { f.printAndLogError("Cannot login: need two factor code") diff --git a/internal/frontend/grpc/service_methods.go b/internal/frontend/grpc/service_methods.go index d5093c53..100981e1 100644 --- a/internal/frontend/grpc/service_methods.go +++ b/internal/frontend/grpc/service_methods.go @@ -406,7 +406,7 @@ func (s *Service) Login(ctx context.Context, login *LoginRequest) (*emptypb.Empt s.auth = auth switch { - case auth.TwoFA.Enabled == proton.TOTPEnabled: + case auth.TwoFA.Enabled&proton.TOTPEnabled != 0: _ = s.SendEvent(NewLoginTfaRequestedEvent(login.Username)) case auth.PasswordMode == proton.TwoPasswordMode: