feat: improve change db password without need to be logged in
This commit is contained in:
parent
1d1a95091d
commit
c786528965
|
@ -8,6 +8,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
@ -46,6 +47,7 @@ var zeroAddress = types.Address{}
|
||||||
// Manager represents account manager interface.
|
// Manager represents account manager interface.
|
||||||
type Manager struct {
|
type Manager struct {
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
|
Keydir string
|
||||||
keystore types.KeyStore
|
keystore types.KeyStore
|
||||||
|
|
||||||
accountsGenerator *generator.Generator
|
accountsGenerator *generator.Generator
|
||||||
|
@ -546,6 +548,7 @@ func (m *Manager) ReEncryptKeyStoreDir(keyDirPath, oldPass, newPass string) erro
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
keyDirPath = strings.TrimSuffix(keyDirPath, "/")
|
||||||
keyParent, keyDirName := filepath.Split(keyDirPath)
|
keyParent, keyDirName := filepath.Split(keyDirPath)
|
||||||
|
|
||||||
// backupKeyDirName used to store existing keys before final write
|
// backupKeyDirName used to store existing keys before final write
|
||||||
|
|
|
@ -32,6 +32,7 @@ func (m *GethManager) InitKeystore(keydir string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
m.keystore, err = makeKeyStore(m.gethAccManager)
|
m.keystore, err = makeKeyStore(m.gethAccManager)
|
||||||
|
m.Keydir = keydir
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -539,9 +539,14 @@ func (b *GethStatusBackend) ImportUnencryptedDatabase(acc multiaccounts.Account,
|
||||||
func (b *GethStatusBackend) ChangeDatabasePassword(keyUID string, password string, newPassword string) error {
|
func (b *GethStatusBackend) ChangeDatabasePassword(keyUID string, password string, newPassword string) error {
|
||||||
dbPath := filepath.Join(b.rootDataDir, fmt.Sprintf("%s.db", keyUID))
|
dbPath := filepath.Join(b.rootDataDir, fmt.Sprintf("%s.db", keyUID))
|
||||||
config := b.StatusNode().Config()
|
config := b.StatusNode().Config()
|
||||||
|
keyDir := ""
|
||||||
|
if config == nil {
|
||||||
|
keyDir = b.accountManager.Keydir
|
||||||
|
} else {
|
||||||
|
keyDir = config.KeyStoreDir
|
||||||
|
}
|
||||||
|
|
||||||
if config != nil {
|
if keyDir != "" {
|
||||||
keyDir := config.KeyStoreDir
|
|
||||||
err := b.accountManager.ReEncryptKeyStoreDir(keyDir, password, newPassword)
|
err := b.accountManager.ReEncryptKeyStoreDir(keyDir, password, newPassword)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("ReEncryptKeyStoreDir error: %v", err)
|
return fmt.Errorf("ReEncryptKeyStoreDir error: %v", err)
|
||||||
|
|
Loading…
Reference in New Issue