testing key input via terminal.

This commit is contained in:
greg stone
2023-02-26 07:32:58 +00:00
parent 69c420c3c3
commit 792cb7cc92
5 changed files with 26 additions and 11 deletions

View File

@@ -2,9 +2,12 @@ package storage
import (
"errors"
"fmt"
"github.com/spf13/viper"
"golang.org/x/term"
"os"
"strings"
"syscall"
)
var (
@@ -64,6 +67,20 @@ func configureKey() {
return
}
if viper.GetBool(storeAskPassFlag) {
log.I.Ln("prompting user for key")
var password []byte
fmt.Print("Enter Encryption Key: ")
password, err = term.ReadPassword(int(syscall.Stdin))
key.Decode(string(password))
return
}
log.I.Ln("no keyfile found, generating a new key")
isNewKey = true

View File

@@ -3,6 +3,7 @@ package storage
import (
"crypto/rand"
"github.com/btcsuite/btcd/btcutil/base58"
"strings"
)
type Key [32]byte
@@ -15,8 +16,11 @@ func (k Key) Encode() string {
return base58.Encode(k[:])
}
func (k Key) Decode(key string) {
base58.Decode(key)
func (k *Key) Decode(key string) {
key = strings.TrimSpace(key)
copy(k[:], base58.Decode(key))
}
func KeyGen() (Key, error) {

View File

@@ -60,14 +60,11 @@ func Run(ctx context.Context) {
opts = badger.DefaultOptions(viper.GetString(storeFilePathFlag))
opts.EncryptionKey = key.Bytes()
opts.IndexCacheSize = 128 << 20
opts.WithLoggingLevel(badger.WARNING)
opts.Logger = nil
db, err = badger.Open(opts)
if err != nil {
check(err)
startupErrors <- err
return
}