GODT-2173: fix: Migrate Bridge password from v2.X.

This commit is contained in:
Jakub
2022-12-12 17:29:43 +01:00
committed by Jakub Cuth
parent 57d563d488
commit 2b25fe1fa4
11 changed files with 243 additions and 101 deletions

View File

@ -34,13 +34,11 @@ func getKeychainPrefPath(vaultDir string) string {
}
func GetHelper(vaultDir string) (string, error) {
filePath := getKeychainPrefPath(vaultDir)
if _, err := os.Stat(filePath); errors.Is(err, fs.ErrNotExist) {
if _, err := os.Stat(getKeychainPrefPath(vaultDir)); errors.Is(err, fs.ErrNotExist) {
return "", nil
}
b, err := os.ReadFile(filePath)
b, err := os.ReadFile(getKeychainPrefPath(vaultDir))
if err != nil {
return "", err
}

View File

@ -28,7 +28,7 @@ type UserData struct {
GluonKey []byte
GluonIDs map[string]string
UIDValidity map[string]imap.UID
BridgePass []byte
BridgePass []byte // raw token represented as byte slice (needs to be encoded)
AddressMode AddressMode
AuthUID string

View File

@ -99,11 +99,18 @@ func (user *User) SetAddressMode(mode AddressMode) error {
})
}
// BridgePass returns the user's bridge password (unencoded).
// BridgePass returns the user's bridge password as raw token bytes (unencoded).
func (user *User) BridgePass() []byte {
return user.vault.getUser(user.userID).BridgePass
}
// SetBridgePass saves bridge password as raw token bytes (unecoded).
func (user *User) SetBridgePass(newPass []byte) error {
return user.vault.modUser(user.userID, func(data *UserData) {
data.BridgePass = newPass
})
}
// AuthUID returns the user's auth UID.
func (user *User) AuthUID() string {
return user.vault.getUser(user.userID).AuthUID