forked from Silverfish/proton-bridge
Other: Switch from liteapi to go-proton-api
This commit is contained in:
@ -21,11 +21,11 @@ import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/ProtonMail/go-proton-api"
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/bridge"
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/constants"
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/vault"
|
||||
"github.com/abiosoft/ishell"
|
||||
"gitlab.protontech.ch/go/liteapi"
|
||||
)
|
||||
|
||||
func (f *frontendCLI) listAccounts(_ *ishell.Context) {
|
||||
@ -149,14 +149,14 @@ func (f *frontendCLI) loginAccount(c *ishell.Context) { //nolint:funlen
|
||||
return
|
||||
}
|
||||
|
||||
if auth.TwoFA.Enabled == liteapi.TOTPEnabled {
|
||||
if auth.TwoFA.Enabled == proton.TOTPEnabled {
|
||||
code := f.readStringInAttempts("Two factor code", c.ReadLine, isNotEmpty)
|
||||
if code == "" {
|
||||
f.printAndLogError("Cannot login: need two factor code")
|
||||
return
|
||||
}
|
||||
|
||||
if err := client.Auth2FA(context.Background(), liteapi.Auth2FAReq{TwoFactorCode: code}); err != nil {
|
||||
if err := client.Auth2FA(context.Background(), proton.Auth2FAReq{TwoFactorCode: code}); err != nil {
|
||||
f.printAndLogError("Cannot login: ", err)
|
||||
return
|
||||
}
|
||||
@ -164,7 +164,7 @@ func (f *frontendCLI) loginAccount(c *ishell.Context) { //nolint:funlen
|
||||
|
||||
var keyPass []byte
|
||||
|
||||
if auth.PasswordMode == liteapi.TwoPasswordMode {
|
||||
if auth.PasswordMode == proton.TwoPasswordMode {
|
||||
keyPass = []byte(f.readStringInAttempts("Mailbox password", c.ReadPassword, isNotEmpty))
|
||||
if len(keyPass) == 0 {
|
||||
f.printAndLogError("Cannot login: need mailbox password")
|
||||
|
||||
@ -24,12 +24,13 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
emptypb "google.golang.org/protobuf/types/known/emptypb"
|
||||
wrapperspb "google.golang.org/protobuf/types/known/wrapperspb"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -39,9 +40,9 @@ const (
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
//**********************************************************
|
||||
// **********************************************************
|
||||
// Log related message
|
||||
//**********************************************************
|
||||
// **********************************************************
|
||||
// Note: the enum values are prefixed with 'LOG_' to avoid a clash in C++ on Windows with the ERROR macro defined in wingdi.h
|
||||
type LogLevel int32
|
||||
|
||||
@ -104,9 +105,9 @@ func (LogLevel) EnumDescriptor() ([]byte, []int) {
|
||||
return file_bridge_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
//**********************************************************
|
||||
// **********************************************************
|
||||
// user related messages
|
||||
//**********************************************************
|
||||
// **********************************************************
|
||||
type UserState int32
|
||||
|
||||
const (
|
||||
@ -436,9 +437,11 @@ func (x *AddLogEntryRequest) GetMessage() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
//**********************************************************
|
||||
// Bug reporting related messages.
|
||||
//**********************************************************
|
||||
// **********************************************************
|
||||
//
|
||||
// Bug reporting related messages.
|
||||
//
|
||||
// **********************************************************
|
||||
type ReportBugRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@ -628,9 +631,9 @@ func (x *LoginAbortRequest) GetUsername() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
//**********************************************************
|
||||
// **********************************************************
|
||||
// IMAP/SMTP Mail Server settings
|
||||
//**********************************************************
|
||||
// **********************************************************
|
||||
type ImapSmtpSettings struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@ -702,9 +705,9 @@ func (x *ImapSmtpSettings) GetUseSSLForSmtp() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
//**********************************************************
|
||||
// **********************************************************
|
||||
// Keychain related message
|
||||
//**********************************************************
|
||||
// **********************************************************
|
||||
type AvailableKeychainsResponse struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@ -1239,9 +1242,9 @@ func (*StreamEvent_Mail) isStreamEvent_Event() {}
|
||||
|
||||
func (*StreamEvent_User) isStreamEvent_Event() {}
|
||||
|
||||
//**********************************************************
|
||||
// **********************************************************
|
||||
// App related events
|
||||
//**********************************************************
|
||||
// **********************************************************
|
||||
type AppEvent struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@ -1667,9 +1670,9 @@ func (*ShowMainWindowEvent) Descriptor() ([]byte, []int) {
|
||||
return file_bridge_proto_rawDescGZIP(), []int{19}
|
||||
}
|
||||
|
||||
//**********************************************************
|
||||
// **********************************************************
|
||||
// Login related events
|
||||
//**********************************************************
|
||||
// **********************************************************
|
||||
type LoginEvent struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@ -1979,9 +1982,9 @@ func (x *LoginFinishedEvent) GetUserID() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
//**********************************************************
|
||||
// **********************************************************
|
||||
// Update related events
|
||||
//**********************************************************
|
||||
// **********************************************************
|
||||
type UpdateEvent struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@ -2477,9 +2480,9 @@ func (*UpdateVersionChanged) Descriptor() ([]byte, []int) {
|
||||
return file_bridge_proto_rawDescGZIP(), []int{33}
|
||||
}
|
||||
|
||||
//**********************************************************
|
||||
// **********************************************************
|
||||
// Cache on disk related events
|
||||
//**********************************************************
|
||||
// **********************************************************
|
||||
type DiskCacheEvent struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@ -2706,9 +2709,9 @@ func (*DiskCachePathChangeFinishedEvent) Descriptor() ([]byte, []int) {
|
||||
return file_bridge_proto_rawDescGZIP(), []int{37}
|
||||
}
|
||||
|
||||
//**********************************************************
|
||||
// **********************************************************
|
||||
// Mail server settings related events
|
||||
//**********************************************************
|
||||
// **********************************************************
|
||||
type MailServerSettingsEvent struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@ -2935,9 +2938,9 @@ func (*ChangeMailServerSettingsFinishedEvent) Descriptor() ([]byte, []int) {
|
||||
return file_bridge_proto_rawDescGZIP(), []int{41}
|
||||
}
|
||||
|
||||
//**********************************************************
|
||||
// **********************************************************
|
||||
// keychain related events
|
||||
//**********************************************************
|
||||
// **********************************************************
|
||||
type KeychainEvent struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@ -3146,9 +3149,9 @@ func (*RebuildKeychainEvent) Descriptor() ([]byte, []int) {
|
||||
return file_bridge_proto_rawDescGZIP(), []int{45}
|
||||
}
|
||||
|
||||
//**********************************************************
|
||||
// **********************************************************
|
||||
// Mail related events
|
||||
//**********************************************************
|
||||
// **********************************************************
|
||||
type MailEvent struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
|
||||
@ -8,6 +8,7 @@ package grpc
|
||||
|
||||
import (
|
||||
context "context"
|
||||
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
|
||||
@ -29,6 +29,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/ProtonMail/go-proton-api"
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/bridge"
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/certs"
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/events"
|
||||
@ -39,7 +40,6 @@ import (
|
||||
sysinfotypes "github.com/elastic/go-sysinfo/types"
|
||||
"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"
|
||||
@ -76,8 +76,8 @@ type Service struct { // nolint:structcheck
|
||||
target updater.VersionInfo
|
||||
targetLock safe.RWMutex
|
||||
|
||||
authClient *liteapi.Client
|
||||
auth liteapi.Auth
|
||||
authClient *proton.Client
|
||||
auth proton.Auth
|
||||
password []byte
|
||||
|
||||
log *logrus.Entry
|
||||
@ -352,7 +352,7 @@ func (s *Service) loginAbort() {
|
||||
}
|
||||
|
||||
func (s *Service) loginClean() {
|
||||
s.auth = liteapi.Auth{}
|
||||
s.auth = proton.Auth{}
|
||||
s.authClient = nil
|
||||
for i := range s.password {
|
||||
s.password[i] = '\x00'
|
||||
|
||||
@ -24,6 +24,7 @@ import (
|
||||
"runtime"
|
||||
|
||||
"github.com/Masterminds/semver/v3"
|
||||
"github.com/ProtonMail/go-proton-api"
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/bridge"
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/constants"
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/events"
|
||||
@ -33,7 +34,6 @@ import (
|
||||
"github.com/ProtonMail/proton-bridge/v2/pkg/keychain"
|
||||
"github.com/ProtonMail/proton-bridge/v2/pkg/ports"
|
||||
"github.com/sirupsen/logrus"
|
||||
"gitlab.protontech.ch/go/liteapi"
|
||||
"golang.org/x/exp/maps"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
@ -383,12 +383,12 @@ func (s *Service) Login(ctx context.Context, login *LoginRequest) (*emptypb.Empt
|
||||
|
||||
if errors.Is(err, bridge.ErrUserAlreadyLoggedIn) {
|
||||
_ = s.SendEvent(NewLoginAlreadyLoggedInEvent(auth.UserID))
|
||||
} else if apiErr := new(liteapi.Error); errors.As(err, &apiErr) {
|
||||
} else if apiErr := new(proton.Error); errors.As(err, &apiErr) {
|
||||
switch apiErr.Code { // nolint:exhaustive
|
||||
case liteapi.PasswordWrong:
|
||||
case proton.PasswordWrong:
|
||||
_ = s.SendEvent(NewLoginError(LoginErrorType_USERNAME_PASSWORD_ERROR, ""))
|
||||
|
||||
case liteapi.PaidPlanRequired:
|
||||
case proton.PaidPlanRequired:
|
||||
_ = s.SendEvent(NewLoginError(LoginErrorType_FREE_USER, ""))
|
||||
|
||||
default:
|
||||
@ -406,10 +406,10 @@ func (s *Service) Login(ctx context.Context, login *LoginRequest) (*emptypb.Empt
|
||||
s.auth = auth
|
||||
|
||||
switch {
|
||||
case auth.TwoFA.Enabled == liteapi.TOTPEnabled:
|
||||
case auth.TwoFA.Enabled == proton.TOTPEnabled:
|
||||
_ = s.SendEvent(NewLoginTfaRequestedEvent(login.Username))
|
||||
|
||||
case auth.PasswordMode == liteapi.TwoPasswordMode:
|
||||
case auth.PasswordMode == proton.TwoPasswordMode:
|
||||
_ = s.SendEvent(NewLoginTwoPasswordsRequestedEvent())
|
||||
|
||||
default:
|
||||
@ -441,8 +441,8 @@ func (s *Service) Login2FA(ctx context.Context, login *LoginRequest) (*emptypb.E
|
||||
return
|
||||
}
|
||||
|
||||
if err := s.authClient.Auth2FA(context.Background(), liteapi.Auth2FAReq{TwoFactorCode: string(twoFA)}); err != nil {
|
||||
if apiErr := new(liteapi.Error); errors.As(err, &apiErr) && apiErr.Code == liteapi.PasswordWrong {
|
||||
if err := s.authClient.Auth2FA(context.Background(), proton.Auth2FAReq{TwoFactorCode: string(twoFA)}); err != nil {
|
||||
if apiErr := new(proton.Error); errors.As(err, &apiErr) && apiErr.Code == proton.PasswordWrong {
|
||||
s.log.Warn("Login 2FA: retry 2fa")
|
||||
_ = s.SendEvent(NewLoginError(LoginErrorType_TFA_ERROR, ""))
|
||||
} else {
|
||||
@ -454,7 +454,7 @@ func (s *Service) Login2FA(ctx context.Context, login *LoginRequest) (*emptypb.E
|
||||
return
|
||||
}
|
||||
|
||||
if s.auth.PasswordMode == liteapi.TwoPasswordMode {
|
||||
if s.auth.PasswordMode == proton.TwoPasswordMode {
|
||||
_ = s.SendEvent(NewLoginTwoPasswordsRequestedEvent())
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user