diff --git a/go.mod b/go.mod index 3021f04a..343a5d12 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/Masterminds/semver/v3 v3.1.1 github.com/ProtonMail/gluon v0.14.2-0.20221202093012-ad1570c49c8c github.com/ProtonMail/go-autostart v0.0.0-20210130080809-00ed301c8e9a - github.com/ProtonMail/go-proton-api v0.1.5 + github.com/ProtonMail/go-proton-api v0.2.1 github.com/ProtonMail/go-rfc5322 v0.11.0 github.com/ProtonMail/gopenpgp/v2 v2.4.10 github.com/PuerkitoBio/goquery v1.8.0 diff --git a/go.sum b/go.sum index 1a784fd6..a5a0a02a 100644 --- a/go.sum +++ b/go.sum @@ -43,8 +43,8 @@ github.com/ProtonMail/go-message v0.0.0-20210611055058-fabeff2ec753/go.mod h1:NB github.com/ProtonMail/go-mime v0.0.0-20220302105931-303f85f7fe0f/go.mod h1:NYt+V3/4rEeDuaev/zw1zCq8uqVEuPHzDPo3OZrlGJ4= github.com/ProtonMail/go-mime v0.0.0-20220429130430-2192574d760f h1:4IWzKjHzZxdrW9k4zl/qCwenOVHDbVDADPPHFLjs0Oc= github.com/ProtonMail/go-mime v0.0.0-20220429130430-2192574d760f/go.mod h1:qRZgbeASl2a9OwmsV85aWwRqic0NHPh+9ewGAzb4cgM= -github.com/ProtonMail/go-proton-api v0.1.5 h1:6RJO3jXP3opFfGqrXNvFTefdD4MlfxKjIebT8r5ROf8= -github.com/ProtonMail/go-proton-api v0.1.5/go.mod h1:jqvJ2HqLHqiPJoEb+BTIB1IF7wvr6p+8ZfA6PO2NRNk= +github.com/ProtonMail/go-proton-api v0.2.1 h1:M15/zzfx6EPiskv2+gogUkmvx7Y1SmRRtLT6GiBh5T0= +github.com/ProtonMail/go-proton-api v0.2.1/go.mod h1:jqvJ2HqLHqiPJoEb+BTIB1IF7wvr6p+8ZfA6PO2NRNk= github.com/ProtonMail/go-rfc5322 v0.11.0 h1:o5Obrm4DpmQEffvgsVqG6S4BKwC1Wat+hYwjIp2YcCY= github.com/ProtonMail/go-rfc5322 v0.11.0/go.mod h1:6oOKr0jXvpoE6pwTx/HukigQpX2J9WUf6h0auplrFTw= github.com/ProtonMail/go-srp v0.0.5 h1:xhUioxZgDbCnpo9JehyFhwwsn9JLWkUGfB0oiKXgiGg= diff --git a/internal/bridge/user.go b/internal/bridge/user.go index 465c5fa6..3e34058c 100644 --- a/internal/bridge/user.go +++ b/internal/bridge/user.go @@ -182,7 +182,7 @@ func (bridge *Bridge) LoginFull( return "", fmt.Errorf("failed to begin login process: %w", err) } - if auth.TwoFA.Enabled&proton.TOTPEnabled != 0 { + if auth.TwoFA.Enabled&proton.HasTOTP != 0 { logrus.WithField("userID", auth.UserID).Info("Requesting TOTP") totp, err := getTOTP() diff --git a/internal/frontend/cli/accounts.go b/internal/frontend/cli/accounts.go index 10884d4a..93f6b2b9 100644 --- a/internal/frontend/cli/accounts.go +++ b/internal/frontend/cli/accounts.go @@ -149,7 +149,7 @@ func (f *frontendCLI) loginAccount(c *ishell.Context) { //nolint:funlen return } - if auth.TwoFA.Enabled&proton.TOTPEnabled != 0 { + if auth.TwoFA.Enabled&proton.HasTOTP != 0 { code := f.readStringInAttempts("Two factor code", c.ReadLine, isNotEmpty) if code == "" { f.printAndLogError("Cannot login: need two factor code") diff --git a/internal/frontend/grpc/service_methods.go b/internal/frontend/grpc/service_methods.go index 100981e1..efeb7bb6 100644 --- a/internal/frontend/grpc/service_methods.go +++ b/internal/frontend/grpc/service_methods.go @@ -406,7 +406,7 @@ func (s *Service) Login(ctx context.Context, login *LoginRequest) (*emptypb.Empt s.auth = auth switch { - case auth.TwoFA.Enabled&proton.TOTPEnabled != 0: + case auth.TwoFA.Enabled&proton.HasTOTP != 0: _ = s.SendEvent(NewLoginTfaRequestedEvent(login.Username)) case auth.PasswordMode == proton.TwoPasswordMode: diff --git a/internal/user/imap.go b/internal/user/imap.go index ec5f70ff..ba6c734b 100644 --- a/internal/user/imap.go +++ b/internal/user/imap.go @@ -534,20 +534,10 @@ func (conn *imapConnector) createDraft(ctx context.Context, literal []byte, addr decBody = string(message.RichBody) } - encBody, err := addrKR.Encrypt(crypto.NewPlainMessageFromString(decBody), nil) - if err != nil { - return proton.Message{}, fmt.Errorf("failed to encrypt message body: %w", err) - } - - armBody, err := encBody.GetArmored() - if err != nil { - return proton.Message{}, fmt.Errorf("failed to get armored message body: %w", err) - } - - draft, err := conn.client.CreateDraft(ctx, proton.CreateDraftReq{ + draft, err := conn.client.CreateDraft(ctx, addrKR, proton.CreateDraftReq{ Message: proton.DraftTemplate{ Subject: message.Subject, - Body: armBody, + Body: decBody, MIMEType: message.MIMEType, Sender: &mail.Address{Name: sender.DisplayName, Address: sender.Email}, diff --git a/internal/user/smtp.go b/internal/user/smtp.go index d827ac40..67682f37 100644 --- a/internal/user/smtp.go +++ b/internal/user/smtp.go @@ -188,19 +188,9 @@ func sendWithKey( //nolint:funlen return proton.Message{}, fmt.Errorf("unsupported MIME type: %v", message.MIMEType) } - encBody, err := addrKR.Encrypt(crypto.NewPlainMessageFromString(decBody), nil) - if err != nil { - return proton.Message{}, fmt.Errorf("failed to encrypt message body: %w", err) - } - - armBody, err := encBody.GetArmored() - if err != nil { - return proton.Message{}, fmt.Errorf("failed to get armored message body: %w", err) - } - - draft, err := createDraft(ctx, client, emails, from, to, parentID, message.InReplyTo, proton.DraftTemplate{ + draft, err := createDraft(ctx, client, addrKR, emails, from, to, parentID, message.InReplyTo, proton.DraftTemplate{ Subject: message.Subject, - Body: armBody, + Body: decBody, MIMEType: message.MIMEType, Sender: message.Sender, @@ -312,6 +302,7 @@ func getParentID( //nolint:funlen func createDraft( ctx context.Context, client *proton.Client, + addrKR *crypto.KeyRing, emails []string, from string, to []string, @@ -357,7 +348,7 @@ func createDraft( action = proton.ForwardAction } - return client.CreateDraft(ctx, proton.CreateDraftReq{ + return client.CreateDraft(ctx, addrKR, proton.CreateDraftReq{ Message: template, ParentID: parentID, Action: action, diff --git a/tests/user_test.go b/tests/user_test.go index f28c17fd..eb7be069 100644 --- a/tests/user_test.go +++ b/tests/user_test.go @@ -269,20 +269,10 @@ func (s *scenario) theFollowingFieldsWereChangedInDraftForAddressOfAccount(draft } if wantMessages[0].Body != "" { - enc, err := addrKR.Encrypt(crypto.NewPlainMessageFromString(wantMessages[0].Body), addrKR) - if err != nil { - return fmt.Errorf("failed to encrypt message body: %w", err) - } - - arm, err := enc.GetArmored() - if err != nil { - return fmt.Errorf("failed to get armored message: %w", err) - } - - changes.Body = arm + changes.Body = wantMessages[0].Body } - if _, err := c.UpdateDraft(ctx, draftID, proton.UpdateDraftReq{Message: changes}); err != nil { + if _, err := c.UpdateDraft(ctx, draftID, addrKR, proton.UpdateDraftReq{Message: changes}); err != nil { return fmt.Errorf("failed to update draft: %w", err) }