Skip to content

Commit

Permalink
Catch wrong password when logging in with api key
Browse files Browse the repository at this point in the history
  • Loading branch information
quexten committed Jan 4, 2024
1 parent 5af0780 commit f2fb11d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions agent/actions/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()),
Expand All @@ -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()),
Expand Down

0 comments on commit f2fb11d

Please sign in to comment.