Catch wrong password when logging in with api key

This commit is contained in:
Bernd Schoolmann 2024-01-04 22:13:10 +01:00
parent 5af078092e
commit f2fb11d16e
No known key found for this signature in database
1 changed files with 13 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import (
"github.com/quexten/goldwarden/agent/bitwarden"
"github.com/quexten/goldwarden/agent/bitwarden/crypto"
"github.com/quexten/goldwarden/agent/config"
"github.com/quexten/goldwarden/agent/notify"
"github.com/quexten/goldwarden/agent/sockets"
"github.com/quexten/goldwarden/agent/vault"
"github.com/quexten/goldwarden/ipc/messages"
@ -80,6 +81,12 @@ func handleLogin(msg messages.IPCMessage, cfg *config.Config, vault *vault.Vault
err = crypto.InitKeyringFromMasterKey(vault.Keyring, profile.Profile.Key, profile.Profile.PrivateKey, orgKeys, masterKey)
if err != nil {
defer func() {
notify.Notify("Goldwarden", "Could not decrypt. Wrong password?", "", func() {})
cfg.SetToken(config.LoginToken{})
vault.Clear()
}()
var payload = messages.ActionResponse{
Success: false,
Message: fmt.Sprintf("Could not sync vault: %s", err.Error()),
@ -101,6 +108,12 @@ func handleLogin(msg messages.IPCMessage, cfg *config.Config, vault *vault.Vault
protectedUserSymetricKey, err = crypto.MemorySymmetricEncryptionKeyFromBytes(vault.Keyring.GetAccountKey().Bytes())
}
if err != nil {
defer func() {
notify.Notify("Goldwarden", "Could not decrypt. Wrong password?", "", func() {})
cfg.SetToken(config.LoginToken{})
vault.Clear()
}()
var payload = messages.ActionResponse{
Success: false,
Message: fmt.Sprintf("Could not sync vault: %s", err.Error()),