feat(GODT-3172): do not list, just retrieve vault key.

This commit is contained in:
Jakub
2024-01-03 13:34:58 +01:00
committed by Jakub Cuth
parent 31670ad9eb
commit 89bb7b6389
4 changed files with 7 additions and 20 deletions

View File

@ -104,14 +104,11 @@ func loadVaultKey(vaultDir string, keychains *keychain.List) ([]byte, error) {
return nil, fmt.Errorf("could not create keychain: %w", err)
}
has, err := vault.HasVaultKey(kc)
key, err := vault.GetVaultKey(kc)
if err != nil {
return nil, fmt.Errorf("could not check for vault key: %w", err)
logrus.WithError(err).Warn("Not possible to retrieve vault key, generating new")
return vault.NewVaultKey(kc)
}
if has {
return vault.GetVaultKey(kc)
}
return vault.NewVaultKey(kc)
return key, nil
}

View File

@ -28,7 +28,6 @@ import (
"github.com/ProtonMail/gopenpgp/v2/crypto"
"github.com/ProtonMail/proton-bridge/v3/pkg/keychain"
"golang.org/x/exp/slices"
)
const vaultSecretName = "bridge-vault-key"
@ -69,15 +68,6 @@ func SetHelper(vaultDir, helper string) error {
return os.WriteFile(getKeychainPrefPath(vaultDir), b, 0o600)
}
func HasVaultKey(kc *keychain.Keychain) (bool, error) {
secrets, err := kc.List()
if err != nil {
return false, fmt.Errorf("could not list keychain: %w", err)
}
return slices.Contains(secrets, vaultSecretName), nil
}
func GetVaultKey(kc *keychain.Keychain) ([]byte, error) {
_, keyEnc, err := kc.Get(vaultSecretName)
if err != nil {