From d18edadd05fedcd5457a144d1c60f8e5d8ae371b Mon Sep 17 00:00:00 2001 From: Daniel Bertalan Date: Fri, 14 Apr 2023 18:13:41 +0200 Subject: [PATCH] Fix 2FA login with both TOTP and U2F enabled The `2FA.Enabled` field in `/auth`'s JSON output seems to be a bitmap of some sort, as the API returns `3` when both TOTP and U2F login is on. This commit changes some `Enabled == 1` checks to `Enabled != 0` to handle this case properly. Fixes #250 --- auth/auth.go | 2 +- cmd/hydroxide/main.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index c6b6469..5d8fa4e 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -134,7 +134,7 @@ func authenticate(c *protonmail.Client, cachedAuth *CachedAuth, username string) return nil, fmt.Errorf("cannot re-authenticate: %v", err) } - if auth.TwoFactor.Enabled == 1 { + if auth.TwoFactor.Enabled != 0 { return nil, fmt.Errorf("cannot re-authenticate: two factor authentication enabled, please login again manually") } } else if err != nil { diff --git a/cmd/hydroxide/main.go b/cmd/hydroxide/main.go index bd63d52..2d6d10c 100644 --- a/cmd/hydroxide/main.go +++ b/cmd/hydroxide/main.go @@ -291,7 +291,7 @@ func main() { log.Fatal(err) } - if a.TwoFactor.Enabled == 1 { + if a.TwoFactor.Enabled != 0 { if a.TwoFactor.TOTP != 1 { log.Fatal("Only TOTP is supported as a 2FA method") }