GODT-1609: Fix bridge password encoding

This commit is contained in:
James Houlahan
2022-10-04 17:50:44 +02:00
parent 51633e000b
commit 6ac68984f2
9 changed files with 23 additions and 10 deletions

View File

@ -19,7 +19,7 @@ func newSMTPBackend() (*smtpBackend, error) {
return &smtpBackend{}, nil
}
func (backend *smtpBackend) Login(state *smtp.ConnectionState, username string, password string) (smtp.Session, error) {
func (backend *smtpBackend) Login(state *smtp.ConnectionState, username, password string) (smtp.Session, error) {
backend.usersLock.RLock()
defer backend.usersLock.RUnlock()

View File

@ -76,7 +76,8 @@ func (bridge *Bridge) QueryUserInfo(query string) (UserInfo, error) {
// If necessary, a TOTP and mailbox password are requested via the callbacks.
func (bridge *Bridge) LoginUser(
ctx context.Context,
username string, password []byte,
username string,
password []byte,
getTOTP func() (string, error),
getKeyPass func() ([]byte, error),
) (string, error) {

View File

@ -256,6 +256,7 @@ func TestBridge_LoginDeleteRestart(t *testing.T) {
func TestBridge_BridgePass(t *testing.T) {
withEnv(t, func(ctx context.Context, s *server.Server, dialer *bridge.TestDialer, locator bridge.Locator, storeKey []byte) {
var userID string
var pass []byte
withBridge(t, ctx, s.GetHostURL(), dialer, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) {

View File

@ -24,10 +24,11 @@
package proto
import (
reflect "reflect"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
emptypb "google.golang.org/protobuf/types/known/emptypb"
reflect "reflect"
)
const (

View File

@ -8,6 +8,7 @@ package proto
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"

View File

@ -1,6 +1,8 @@
package vault
import (
"encoding/hex"
"github.com/ProtonMail/gopenpgp/v2/crypto"
)
@ -16,3 +18,12 @@ func newRandomToken(size int) []byte {
return token
}
func newRandomString(size int) []byte {
token, err := RandomToken(size)
if err != nil {
panic(err)
}
return []byte(hex.EncodeToString(token))
}

View File

@ -91,7 +91,7 @@ func (vault *Vault) ForUser(fn func(*User) error) error {
}
// AddUser creates a new user in the vault with the given ID and username.
// A bridge password is generated using the package's token generator.
// A bridge password and gluon key are generated using the package's token generator.
func (vault *Vault) AddUser(userID, username, authUID, authRef string, keyPass []byte) (*User, error) {
if idx := xslices.IndexFunc(vault.get().Users, func(user UserData) bool {
return user.UserID == userID
@ -107,7 +107,7 @@ func (vault *Vault) AddUser(userID, username, authUID, authRef string, keyPass [
GluonKey: newRandomToken(32),
GluonIDs: make(map[string]string),
UIDValidity: make(map[string]imap.UID),
BridgePass: newRandomToken(16),
BridgePass: newRandomString(16),
AddressMode: CombinedMode,
AuthUID: authUID,