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) }, false)
storage.Shutdown()
os.Exit(0)
// //
// RPC // RPC
// //

View File

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

View File

@@ -2,9 +2,12 @@ package storage
import ( import (
"errors" "errors"
"fmt"
"github.com/spf13/viper" "github.com/spf13/viper"
"golang.org/x/term"
"os" "os"
"strings" "strings"
"syscall"
) )
var ( var (
@@ -64,6 +67,20 @@ func configureKey() {
return 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") log.I.Ln("no keyfile found, generating a new key")
isNewKey = true isNewKey = true

View File

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

View File

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