mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-19 00:27:06 +00:00
fix(GODT-2913): Reduce the number of configuration failure detected.
This commit is contained in:
@ -119,8 +119,9 @@ func (s *Connector) Init(_ context.Context, cache connector.IMAPState) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Connector) Authorize(ctx context.Context, username string, password []byte) bool {
|
func (s *Connector) Authorize(ctx context.Context, username string, password []byte) bool {
|
||||||
addrID, err := s.identityState.CheckAuth(username, password, s.telemetry)
|
addrID, err := s.identityState.CheckAuth(username, password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
s.telemetry.ReportConfigStatusFailure("IMAP " + err.Error())
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -48,6 +48,7 @@ type EventProvider interface {
|
|||||||
type Telemetry interface {
|
type Telemetry interface {
|
||||||
useridentity.Telemetry
|
useridentity.Telemetry
|
||||||
SendConfigStatusSuccess(ctx context.Context)
|
SendConfigStatusSuccess(ctx context.Context)
|
||||||
|
ReportConfigStatusFailure(errDetails string)
|
||||||
}
|
}
|
||||||
|
|
||||||
type GluonIDProvider interface {
|
type GluonIDProvider interface {
|
||||||
|
|||||||
@ -32,7 +32,7 @@ type sharedIdentity interface {
|
|||||||
GetPrimaryAddress() (proton.Address, error)
|
GetPrimaryAddress() (proton.Address, error)
|
||||||
GetAddresses() []proton.Address
|
GetAddresses() []proton.Address
|
||||||
WithAddrKR(addrID string, fn func(userKR, addrKR *crypto.KeyRing) error) error
|
WithAddrKR(addrID string, fn func(userKR, addrKR *crypto.KeyRing) error) error
|
||||||
CheckAuth(email string, password []byte, telemetry Telemetry) (string, error)
|
CheckAuth(email string, password []byte) (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type rwIdentity struct {
|
type rwIdentity struct {
|
||||||
@ -102,11 +102,11 @@ func (r *rwIdentity) WithAddrKRs(fn func(*crypto.KeyRing, map[string]*crypto.Key
|
|||||||
return r.identity.WithAddrKRs(r.keyPassProvider.KeyPass(), fn)
|
return r.identity.WithAddrKRs(r.keyPassProvider.KeyPass(), fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *rwIdentity) CheckAuth(email string, password []byte, telemetry Telemetry) (string, error) {
|
func (r *rwIdentity) CheckAuth(email string, password []byte) (string, error) {
|
||||||
r.lock.RLock()
|
r.lock.RLock()
|
||||||
defer r.lock.RUnlock()
|
defer r.lock.RUnlock()
|
||||||
|
|
||||||
return r.identity.CheckAuth(email, password, r.bridgePassProvider, telemetry)
|
return r.identity.CheckAuth(email, password, r.bridgePassProvider)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *rwIdentity) Write(f func(identity *useridentity.State) error) error {
|
func (r *rwIdentity) Write(f func(identity *useridentity.State) error) error {
|
||||||
|
|||||||
@ -221,7 +221,7 @@ func (s *Service) run(ctx context.Context) {
|
|||||||
|
|
||||||
case *checkAuthReq:
|
case *checkAuthReq:
|
||||||
s.log.WithField("email", bridgelogging.Sensitive(r.email)).Debug("Checking authentication")
|
s.log.WithField("email", bridgelogging.Sensitive(r.email)).Debug("Checking authentication")
|
||||||
addrID, err := s.identityState.CheckAuth(r.email, r.password, s.bridgePassProvider, s.telemetry)
|
addrID, err := s.identityState.CheckAuth(r.email, r.password, s.bridgePassProvider)
|
||||||
request.Reply(ctx, addrID, err)
|
request.Reply(ctx, addrID, err)
|
||||||
|
|
||||||
case *resyncReq:
|
case *resyncReq:
|
||||||
|
|||||||
@ -249,7 +249,7 @@ func (s *Service) run(ctx context.Context) {
|
|||||||
r.Reply(ctx, maps.Clone(s.identity.Addresses), nil)
|
r.Reply(ctx, maps.Clone(s.identity.Addresses), nil)
|
||||||
|
|
||||||
case *checkAuthReq:
|
case *checkAuthReq:
|
||||||
id, err := s.identity.CheckAuth(req.email, req.password, s.bridgePassProvider, s.telemetry)
|
id, err := s.identity.CheckAuth(req.email, req.password, s.bridgePassProvider)
|
||||||
r.Reply(ctx, id, err)
|
r.Reply(ctx, id, err)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@ -226,7 +226,7 @@ func (s *State) Clone() *State {
|
|||||||
|
|
||||||
// CheckAuth returns whether the given email and password can be used to authenticate over IMAP or SMTP with this user.
|
// CheckAuth returns whether the given email and password can be used to authenticate over IMAP or SMTP with this user.
|
||||||
// It returns the address ID of the authenticated address.
|
// It returns the address ID of the authenticated address.
|
||||||
func (s *State) CheckAuth(email string, password []byte, bridgePassProvider BridgePassProvider, telemetry Telemetry) (string, error) {
|
func (s *State) CheckAuth(email string, password []byte, bridgePassProvider BridgePassProvider) (string, error) {
|
||||||
if email == "crash@bandicoot" {
|
if email == "crash@bandicoot" {
|
||||||
panic("your wish is my command.. I crash")
|
panic("your wish is my command.. I crash")
|
||||||
}
|
}
|
||||||
@ -237,11 +237,7 @@ func (s *State) CheckAuth(email string, password []byte, bridgePassProvider Brid
|
|||||||
}
|
}
|
||||||
|
|
||||||
if subtle.ConstantTimeCompare(bridgePassProvider.BridgePass(), dec) != 1 {
|
if subtle.ConstantTimeCompare(bridgePassProvider.BridgePass(), dec) != 1 {
|
||||||
err := fmt.Errorf("invalid password")
|
return "", fmt.Errorf("invalid password")
|
||||||
if telemetry != nil {
|
|
||||||
telemetry.ReportConfigStatusFailure(err.Error())
|
|
||||||
}
|
|
||||||
return "", err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, addr := range s.AddressesSorted {
|
for _, addr := range s.AddressesSorted {
|
||||||
|
|||||||
@ -674,7 +674,7 @@ func (user *User) ReportSMTPAuthFailed(username string) {
|
|||||||
emails := user.Emails()
|
emails := user.Emails()
|
||||||
for _, mail := range emails {
|
for _, mail := range emails {
|
||||||
if mail == username {
|
if mail == username {
|
||||||
user.ReportConfigStatusFailure("invalid username or password")
|
user.ReportConfigStatusFailure("SMTP invalid username or password")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user