Skip to content

Commit

Permalink
fix(GODT-3124): Return errors during auth info + improved logging
Browse files Browse the repository at this point in the history
  • Loading branch information
LBeernaertProton committed Nov 28, 2023
1 parent 88e7263 commit c13f158
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions server/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/ProtonMail/go-proton-api"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)

func (s *Server) handlePostAuthInfo() gin.HandlerFunc {
Expand All @@ -18,6 +19,7 @@ func (s *Server) handlePostAuthInfo() gin.HandlerFunc {

info, err := s.b.NewAuthInfo(req.Username)
if err != nil {
logrus.WithError(err).Errorf("User '%v' failed auth info", req.Username)
_ = c.AbortWithError(http.StatusUnauthorized, err)
return
}
Expand Down Expand Up @@ -48,6 +50,7 @@ func (s *Server) handlePostAuth() gin.HandlerFunc {

auth, err := s.b.NewAuth(req.Username, clientEphemeral, clientProof, req.SRPSession)
if err != nil {
logrus.WithError(err).Errorf("User '%v' not authorized", req.Username)
_ = c.AbortWithError(http.StatusUnauthorized, err)
return
}
Expand Down
8 changes: 6 additions & 2 deletions server/backend/api_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@ import (
"github.com/ProtonMail/go-proton-api"
"github.com/ProtonMail/go-srp"
"github.com/google/uuid"
"github.com/sirupsen/logrus"
)

func (b *Backend) NewAuthInfo(username string) (proton.AuthInfo, error) {
return writeBackendRetErr(b, func(b *unsafeBackend) (proton.AuthInfo, error) {
return withAccName(b, username, func(acc *account) (proton.AuthInfo, error) {
server, err := srp.NewServerFromSigned(modulus, acc.verifier, 2048)
if err != nil {
return proton.AuthInfo{}, nil
logrus.WithError(err).Errorf("Failed to create SRP Server")
return proton.AuthInfo{}, fmt.Errorf("failed to create new srp server %w", err)
}

challenge, err := server.GenerateChallenge()
if err != nil {
return proton.AuthInfo{}, nil
logrus.WithError(err).Errorf("Failed to generate srp challeng")
return proton.AuthInfo{}, fmt.Errorf("failed to generate srp challend %w", err)
}

session := uuid.NewString()
Expand All @@ -42,6 +45,7 @@ func (b *Backend) NewAuth(username string, ephemeral, proof []byte, session stri
return withAccName(b, username, func(acc *account) (proton.Auth, error) {
server, ok := b.srp[session]
if !ok {
logrus.Errorf("Session '%v' not found for user='%v'", session, username)
return proton.Auth{}, fmt.Errorf("invalid session")
}

Expand Down
3 changes: 3 additions & 0 deletions server/backend/quark.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/ProtonMail/go-proton-api"
"github.com/sirupsen/logrus"
)

func (s *Backend) RunQuarkCommand(command string, args ...string) (any, error) {
Expand Down Expand Up @@ -77,6 +78,8 @@ func (s *Backend) quarkUserCreate(args ...string) (proton.User, error) {
}
}

logrus.Infof("User '%v' created with id=%v", *name, userID)

return s.GetUser(userID)
}

Expand Down

0 comments on commit c13f158

Please sign in to comment.