From f2fb11d16e2dcd83ab2c86fc17aaeb7a9adfad4a Mon Sep 17 00:00:00 2001 From: Bernd Schoolmann Date: Thu, 4 Jan 2024 22:13:10 +0100 Subject: [PATCH] Catch wrong password when logging in with api key --- agent/actions/login.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/agent/actions/login.go b/agent/actions/login.go index b13fcf3..ab26aaa 100644 --- a/agent/actions/login.go +++ b/agent/actions/login.go @@ -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()),