feat: improve change db password without need to be logged in

This commit is contained in:
Anthony Laibe 2023-02-11 12:14:20 +01:00 committed by Anthony Laibe
parent 1d1a95091d
commit c786528965
3 changed files with 11 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"sync"
"github.com/google/uuid"
@ -46,6 +47,7 @@ var zeroAddress = types.Address{}
// Manager represents account manager interface.
type Manager struct {
mu sync.RWMutex
Keydir string
keystore types.KeyStore
accountsGenerator *generator.Generator
@ -546,6 +548,7 @@ func (m *Manager) ReEncryptKeyStoreDir(keyDirPath, oldPass, newPass string) erro
return nil
}
keyDirPath = strings.TrimSuffix(keyDirPath, "/")
keyParent, keyDirName := filepath.Split(keyDirPath)
// backupKeyDirName used to store existing keys before final write

View File

@ -32,6 +32,7 @@ func (m *GethManager) InitKeystore(keydir string) error {
}
m.keystore, err = makeKeyStore(m.gethAccManager)
m.Keydir = keydir
return err
}

View File

@ -539,9 +539,14 @@ func (b *GethStatusBackend) ImportUnencryptedDatabase(acc multiaccounts.Account,
func (b *GethStatusBackend) ChangeDatabasePassword(keyUID string, password string, newPassword string) error {
dbPath := filepath.Join(b.rootDataDir, fmt.Sprintf("%s.db", keyUID))
config := b.StatusNode().Config()
keyDir := ""
if config == nil {
keyDir = b.accountManager.Keydir
} else {
keyDir = config.KeyStoreDir
}
if config != nil {
keyDir := config.KeyStoreDir
if keyDir != "" {
err := b.accountManager.ReEncryptKeyStoreDir(keyDir, password, newPassword)
if err != nil {
return fmt.Errorf("ReEncryptKeyStoreDir error: %v", err)