Skip to content

Commit

Permalink
protonmail: make auth errors more verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
emersion committed Apr 13, 2019
1 parent 93c8007 commit 139f392
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions protonmail/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package protonmail

import (
"encoding/base64"
"errors"
"fmt"
"io/ioutil"
"log"
"net/http"
Expand Down Expand Up @@ -129,7 +129,7 @@ func (c *Client) Auth(username, password, twoFactorCode string, info *AuthInfo)

proofs, err := srp([]byte(password), info)
if err != nil {
return nil, err
return nil, fmt.Errorf("SRP failed during auth: %v", err)
}

reqData := &authReq{
Expand Down Expand Up @@ -223,7 +223,7 @@ func (c *Client) Unlock(auth *Auth, passphrase string) (openpgp.EntityList, erro
if auth.keySalt != "" {
keySalt, err := base64.StdEncoding.DecodeString(auth.keySalt)
if err != nil {
return nil, err
return nil, fmt.Errorf("malformed key salt: %v", err)
}

passphraseBytes, err = computeKeyPassword(passphraseBytes, keySalt)
Expand All @@ -236,34 +236,34 @@ func (c *Client) Unlock(auth *Auth, passphrase string) (openpgp.EntityList, erro

keyRing, err := openpgp.ReadArmoredKeyRing(strings.NewReader(auth.privateKey))
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to read auth key ring: %v", err)
}
if len(keyRing) == 0 {
return nil, errors.New("auth key ring is empty")
return nil, fmt.Errorf("auth key ring is empty")
}

for _, e := range keyRing {
if err := unlockKey(e, passphraseBytes); err != nil {
return nil, err
return nil, fmt.Errorf("failed to unlock auth key ring: %v", err)
}
}

// Decrypt access token

block, err := armor.Decode(strings.NewReader(auth.accessToken))
if err != nil {
return nil, err
return nil, fmt.Errorf("malformed access token: %v", err)
}

msg, err := openpgp.ReadMessage(block.Body, keyRing, nil, nil)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to read access token: %v", err)
}

// TODO: maybe check signature
accessTokenBytes, err := ioutil.ReadAll(msg.UnverifiedBody)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to read access token: %v", err)
}

c.uid = auth.UID
Expand Down

0 comments on commit 139f392

Please sign in to comment.