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

@@ -103,9 +103,6 @@ var seedServeCommand = &cobra.Command{
}, false)
storage.Shutdown()
os.Exit(0)
//
// RPC
//

View File

@@ -11,8 +11,8 @@ func init() {
var (
server *grpc.Server
startupErrors = make(chan error)
isReady = make(chan bool)
startupErrors = make(chan error, 128)
isReady = make(chan bool, 1)
)
func RunWith(ctx context.Context, r func(srv *grpc.Server)) {

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
}