lnd: revert back to prior default wallet public passphrase

In this commit we ensure the behavior of lnd with the —noencryptwallet
command line option heaves as it did before user initiated wallet
encryption was implemented. We do this by modifying the
waitForWalletPassword method to instead return two pass phrases: one
public and one private. The default wallet public passphrase is then
restarted back to the value which was used stoically in the codebase
before the latest merged PR.
This commit is contained in:
Olaoluwa Osuntokun 2017-10-19 19:53:19 -07:00
parent 08940b43d5
commit 8358349b2d
No known key found for this signature in database
GPG key ID: 964EA263DD637C21
2 changed files with 18 additions and 13 deletions

View file

@ -103,7 +103,8 @@ type chainControl struct {
// branches of chainControl instances exist: one backed by a running btcd // branches of chainControl instances exist: one backed by a running btcd
// full-node, and the other backed by a running neutrino light client instance. // full-node, and the other backed by a running neutrino light client instance.
func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB, func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
walletPw []byte) (*chainControl, func(), error) { privateWalletPw, publicWalletPw []byte) (*chainControl, func(), error) {
// Set the RPC config from the "home" chain. Multi-chain isn't yet // Set the RPC config from the "home" chain. Multi-chain isn't yet
// active, so we'll restrict usage to a particular chain for now. // active, so we'll restrict usage to a particular chain for now.
homeChainConfig := cfg.Bitcoin homeChainConfig := cfg.Bitcoin
@ -132,8 +133,8 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
} }
walletConfig := &btcwallet.Config{ walletConfig := &btcwallet.Config{
PrivatePass: walletPw, PrivatePass: privateWalletPw,
PublicPass: walletPw, PublicPass: publicWalletPw,
DataDir: homeChainConfig.ChainDir, DataDir: homeChainConfig.ChainDir,
NetParams: activeNetParams.Params, NetParams: activeNetParams.Params,
FeeEstimator: cc.feeEstimator, FeeEstimator: cc.feeEstimator,

24
lnd.go
View file

@ -190,10 +190,13 @@ func lndMain() error {
// We wait until the user provides a password over RPC. In case lnd is // We wait until the user provides a password over RPC. In case lnd is
// started with the --noencryptwallet flag, we use the default password // started with the --noencryptwallet flag, we use the default password
// "hello" for wallet encryption. // "hello" for wallet encryption.
walletPw := []byte("hello") privateWalletPw := []byte("hello")
publicWalletPw := []byte("public")
if !cfg.NoEncryptWallet { if !cfg.NoEncryptWallet {
walletPw, err = waitForWalletPassword(grpcEndpoint, restEndpoint, privateWalletPw, publicWalletPw, err = waitForWalletPassword(
serverOpts, proxyOpts, tlsConf, macaroonService) grpcEndpoint, restEndpoint, serverOpts, proxyOpts,
tlsConf, macaroonService,
)
if err != nil { if err != nil {
return err return err
} }
@ -203,7 +206,7 @@ func lndMain() error {
// instances of the pertinent interfaces required to operate the // instances of the pertinent interfaces required to operate the
// Lightning Network Daemon. // Lightning Network Daemon.
activeChainControl, chainCleanUp, err := newChainControlFromConfig(cfg, activeChainControl, chainCleanUp, err := newChainControlFromConfig(cfg,
chanDB, walletPw) chanDB, privateWalletPw, publicWalletPw)
if err != nil { if err != nil {
fmt.Printf("unable to create chain control: %v\n", err) fmt.Printf("unable to create chain control: %v\n", err)
return err return err
@ -623,7 +626,8 @@ func genMacaroons(svc *bakery.Service, admFile, roFile string) error {
// the user to this RPC server. // the user to this RPC server.
func waitForWalletPassword(grpcEndpoint, restEndpoint string, func waitForWalletPassword(grpcEndpoint, restEndpoint string,
serverOpts []grpc.ServerOption, proxyOpts []grpc.DialOption, serverOpts []grpc.ServerOption, proxyOpts []grpc.DialOption,
tlsConf *tls.Config, macaroonService *bakery.Service) ([]byte, error) { tlsConf *tls.Config, macaroonService *bakery.Service) ([]byte, []byte, error) {
// Set up a new PasswordService, which will listen // Set up a new PasswordService, which will listen
// for passwords provided over RPC. // for passwords provided over RPC.
grpcServer := grpc.NewServer(serverOpts...) grpcServer := grpc.NewServer(serverOpts...)
@ -641,7 +645,7 @@ func waitForWalletPassword(grpcEndpoint, restEndpoint string,
lis, err := net.Listen("tcp", grpcEndpoint) lis, err := net.Listen("tcp", grpcEndpoint)
if err != nil { if err != nil {
fmt.Printf("failed to listen: %v", err) fmt.Printf("failed to listen: %v", err)
return nil, err return nil, nil, err
} }
defer lis.Close() defer lis.Close()
@ -667,7 +671,7 @@ func waitForWalletPassword(grpcEndpoint, restEndpoint string,
err = lnrpc.RegisterWalletUnlockerHandlerFromEndpoint(ctx, mux, err = lnrpc.RegisterWalletUnlockerHandlerFromEndpoint(ctx, mux,
grpcEndpoint, proxyOpts) grpcEndpoint, proxyOpts)
if err != nil { if err != nil {
return nil, err return nil, nil, err
} }
srv := &http.Server{Handler: mux} srv := &http.Server{Handler: mux}
defer func() { defer func() {
@ -706,10 +710,10 @@ func waitForWalletPassword(grpcEndpoint, restEndpoint string,
// created if none exists when creating the chain control. // created if none exists when creating the chain control.
select { select {
case walletPw := <-pwService.CreatePasswords: case walletPw := <-pwService.CreatePasswords:
return walletPw, nil return walletPw, walletPw, nil
case walletPw := <-pwService.UnlockPasswords: case walletPw := <-pwService.UnlockPasswords:
return walletPw, nil return walletPw, walletPw, nil
case <-shutdownChannel: case <-shutdownChannel:
return nil, fmt.Errorf("shutting down") return nil, nil, fmt.Errorf("shutting down")
} }
} }