Other: Put back old 2FA/two-pass flow in GUI

This commit is contained in:
James Houlahan
2022-10-12 16:20:08 +02:00
parent 1517a7b665
commit d330000c8d
5 changed files with 157 additions and 18 deletions

View File

@ -37,6 +37,7 @@ import (
"github.com/ProtonMail/proton-bridge/v2/pkg/restarter"
"github.com/google/uuid"
"github.com/sirupsen/logrus"
"gitlab.protontech.ch/go/liteapi"
"google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials"
@ -65,6 +66,10 @@ type Service struct { // nolint:structcheck
bridge *bridge.Bridge
newVersionInfo updater.VersionInfo
authClient *liteapi.Client
auth liteapi.Auth
password []byte
log *logrus.Entry
initializing sync.WaitGroup
initializationDone sync.Once
@ -263,6 +268,45 @@ func (s *Service) watchEvents() {
}
}
func (s *Service) loginAbort() {
s.loginClean()
}
func (s *Service) loginClean() {
s.auth = liteapi.Auth{}
s.authClient = nil
for i := range s.password {
s.password[i] = '\x00'
}
s.password = s.password[0:0]
}
func (s *Service) finishLogin() {
defer s.loginClean()
if len(s.password) == 0 || s.auth.UID == "" || s.authClient == nil {
s.log.
WithField("hasPass", len(s.password) != 0).
WithField("hasAuth", s.auth.UID != "").
WithField("hasClient", s.authClient != nil).
Error("Finish login: authentication incomplete")
_ = s.SendEvent(NewLoginError(LoginErrorType_TWO_PASSWORDS_ABORT, "Missing authentication, try again."))
return
}
userID, err := s.bridge.LoginUser(context.Background(), s.authClient, s.auth, s.password)
if err != nil {
s.log.WithError(err).Errorf("Finish login failed")
_ = s.SendEvent(NewLoginError(LoginErrorType_TWO_PASSWORDS_ABORT, err.Error()))
return
}
s.log.WithField("userID", userID).Debug("Login finished")
_ = s.SendEvent(NewLoginFinishedEvent(userID))
}
func (s *Service) triggerReset() {
defer func() {
_ = s.SendEvent(NewResetFinishedEvent())