Fix sync on unlock not working

This commit is contained in:
Bernd Schoolmann 2023-07-18 22:08:09 +02:00
parent bb2c6bf963
commit 11fe67fa36
No known key found for this signature in database
1 changed files with 27 additions and 1 deletions

View File

@ -1,6 +1,10 @@
package actions
import (
"context"
"github.com/quexten/goldwarden/agent/bitwarden"
"github.com/quexten/goldwarden/agent/bitwarden/crypto"
"github.com/quexten/goldwarden/agent/config"
"github.com/quexten/goldwarden/agent/sockets"
"github.com/quexten/goldwarden/agent/systemauth"
@ -43,11 +47,33 @@ func ensureIsLoggedIn(action Action) Action {
}
}
func sync(ctx context.Context, vault *vault.Vault, cfg *config.Config) bool {
token, err := cfg.GetToken()
if err == nil {
if token.AccessToken != "" {
bitwarden.RefreshToken(ctx, cfg)
userSymmetricKey, err := cfg.GetUserSymmetricKey()
if err != nil {
return false
}
protectedUserSymetricKey, err := crypto.SymmetricEncryptionKeyFromBytes(userSymmetricKey)
err = bitwarden.DoFullSync(context.WithValue(ctx, bitwarden.AuthToken{}, token.AccessToken), vault, cfg, &protectedUserSymetricKey, true)
if err != nil {
return false
}
}
}
return true
}
func ensureIsNotLocked(action Action) Action {
return func(request ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx sockets.CallingContext) (interface{}, error) {
if cfg.IsLocked() {
err := cfg.TryUnlock(vault)
if err != nil {
ctx1 := context.Background()
success := sync(ctx1, vault, cfg)
if err != nil || !success {
return ipc.IPCMessageFromPayload(ipc.ActionResponse{
Success: false,
Message: err.Error(),