mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-11 13:16:53 +00:00
GODT-2173: fix: Migrate Bridge password from v2.X.
This commit is contained in:
@ -25,6 +25,7 @@ import (
|
||||
"github.com/ProtonMail/gluon/imap"
|
||||
"github.com/ProtonMail/go-proton-api"
|
||||
"github.com/ProtonMail/gopenpgp/v2/crypto"
|
||||
"github.com/ProtonMail/proton-bridge/v3/pkg/algo"
|
||||
"github.com/ProtonMail/proton-bridge/v3/pkg/message"
|
||||
"github.com/bradenaw/juniper/xslices"
|
||||
)
|
||||
@ -135,7 +136,7 @@ func newFailedMessageLiteral(
|
||||
"Error": syncErr.Error(),
|
||||
}); err != nil {
|
||||
panic(err)
|
||||
} else if _, err := buf.Write(lineWrap(b64Encode(b))); err != nil {
|
||||
} else if _, err := buf.Write(lineWrap(algo.B64Encode(b))); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
@ -58,36 +57,6 @@ func groupBy[Key comparable, Value any](items []Value, key func(Value) Key) map[
|
||||
return groups
|
||||
}
|
||||
|
||||
// b64Encode returns the base64 encoding of the given byte slice.
|
||||
func b64Encode(b []byte) []byte {
|
||||
enc := make([]byte, base64.StdEncoding.EncodedLen(len(b)))
|
||||
|
||||
base64.StdEncoding.Encode(enc, b)
|
||||
|
||||
return enc
|
||||
}
|
||||
|
||||
// b64RawEncode returns the base64 encoding of the given byte slice.
|
||||
func b64RawEncode(b []byte) []byte {
|
||||
enc := make([]byte, base64.RawURLEncoding.EncodedLen(len(b)))
|
||||
|
||||
base64.RawURLEncoding.Encode(enc, b)
|
||||
|
||||
return enc
|
||||
}
|
||||
|
||||
// b64RawDecode returns the bytes represented by the base64 encoding of the given byte slice.
|
||||
func b64RawDecode(b []byte) ([]byte, error) {
|
||||
dec := make([]byte, base64.RawURLEncoding.DecodedLen(len(b)))
|
||||
|
||||
n, err := base64.RawURLEncoding.Decode(dec, b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return dec[:n], nil
|
||||
}
|
||||
|
||||
// getAddrID returns the address ID for the given email address.
|
||||
func getAddrID(apiAddrs map[string]proton.Address, email string) (string, error) {
|
||||
for _, addr := range apiAddrs {
|
||||
|
||||
@ -36,6 +36,7 @@ import (
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/logging"
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/safe"
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/vault"
|
||||
"github.com/ProtonMail/proton-bridge/v3/pkg/algo"
|
||||
"github.com/bradenaw/juniper/xslices"
|
||||
"github.com/go-resty/resty/v2"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -355,7 +356,7 @@ func (user *User) GluonKey() []byte {
|
||||
|
||||
// BridgePass returns the user's bridge password, used for authentication over SMTP and IMAP.
|
||||
func (user *User) BridgePass() []byte {
|
||||
return b64RawEncode(user.vault.BridgePass())
|
||||
return algo.B64RawEncode(user.vault.BridgePass())
|
||||
}
|
||||
|
||||
// UsedSpace returns the total space used by the user on the API.
|
||||
@ -431,7 +432,7 @@ func (user *User) CheckAuth(email string, password []byte) (string, error) {
|
||||
panic("your wish is my command.. I crash")
|
||||
}
|
||||
|
||||
dec, err := b64RawDecode(password)
|
||||
dec, err := algo.B64RawDecode(password)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to decode password: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user