From 08940b43d5675558cfb1e1e2f2353f25b19fff1f Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 19 Oct 2017 19:46:42 -0700 Subject: [PATCH] walletunlocker: don't utilize the macaroon authentication service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In this commit we remove all instances of the macaroon authentication service from the UnlockerService struct. We do this, as in the future, the macaroons themselves will be encrypted using the user’s passphrase, therefore we wouldn’t be able to _verify_ the macaroon unless the wallet itself was encrypted. --- walletunlocker/service.go | 40 ++++++++-------------------------- walletunlocker/service_test.go | 6 ++--- 2 files changed, 12 insertions(+), 34 deletions(-) diff --git a/walletunlocker/service.go b/walletunlocker/service.go index 35eb103c..8b639cbf 100644 --- a/walletunlocker/service.go +++ b/walletunlocker/service.go @@ -5,7 +5,6 @@ import ( "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnwallet/btcwallet" - "github.com/lightningnetwork/lnd/macaroons" "github.com/roasbeef/btcd/chaincfg" "github.com/roasbeef/btcwallet/wallet" "golang.org/x/net/context" @@ -16,19 +15,15 @@ import ( // with a password for wallet encryption at startup. type UnlockerService struct { // CreatePasswords is a channel where passwords provided by the rpc - // client to be used to initially create and encrypt a wallet will - // be sent. + // client to be used to initially create and encrypt a wallet will be + // sent. CreatePasswords chan []byte // UnlockPasswords is a channel where passwords provided by the rpc - // client to be used to unlock and decrypt an existing wallet will - // be sent. + // client to be used to unlock and decrypt an existing wallet will be + // sent. UnlockPasswords chan []byte - // authSvc is the authentication/authorization service backed by - // macaroons. - authSvc *bakery.Service - chainDir string netParams *chaincfg.Params } @@ -39,26 +34,17 @@ func New(authSvc *bakery.Service, chainDir string, return &UnlockerService{ CreatePasswords: make(chan []byte, 1), UnlockPasswords: make(chan []byte, 1), - authSvc: authSvc, chainDir: chainDir, netParams: params, } } -// CreateWallet will read the password provided in the CreateWalletRequest -// and send it over the CreatePasswords channel in case no wallet already -// exist in the chain's wallet database directory. +// CreateWallet will read the password provided in the CreateWalletRequest and +// send it over the CreatePasswords channel in case no wallet already exist in +// the chain's wallet database directory. func (u *UnlockerService) CreateWallet(ctx context.Context, in *lnrpc.CreateWalletRequest) (*lnrpc.CreateWalletResponse, error) { - // Check macaroon to see if this is allowed. - if u.authSvc != nil { - if err := macaroons.ValidateMacaroon(ctx, "createwallet", - u.authSvc); err != nil { - return nil, err - } - } - netDir := btcwallet.NetworkDir(u.chainDir, u.netParams) loader := wallet.NewLoader(u.netParams, netDir) @@ -81,19 +67,11 @@ func (u *UnlockerService) CreateWallet(ctx context.Context, } // UnlockWallet sends the password provided by the incoming UnlockWalletRequest -// over the UnlockPasswords channel in case it successfully decrypts an existing -// wallet found in the chain's wallet database directory. +// over the UnlockPasswords channel in case it successfully decrypts an +// existing wallet found in the chain's wallet database directory. func (u *UnlockerService) UnlockWallet(ctx context.Context, in *lnrpc.UnlockWalletRequest) (*lnrpc.UnlockWalletResponse, error) { - // Check macaroon to see if this is allowed. - if u.authSvc != nil { - if err := macaroons.ValidateMacaroon(ctx, "unlockwallet", - u.authSvc); err != nil { - return nil, err - } - } - netDir := btcwallet.NetworkDir(u.chainDir, u.netParams) loader := wallet.NewLoader(u.netParams, netDir) diff --git a/walletunlocker/service_test.go b/walletunlocker/service_test.go index 14d7c71d..d6e7eb8d 100644 --- a/walletunlocker/service_test.go +++ b/walletunlocker/service_test.go @@ -88,9 +88,9 @@ func TestCreateWallet(t *testing.T) { } } -// TestUnlockWallet checks that trying to unlock non-existing wallet fail, -// that unlocking existing wallet with wrong passphrase fails, and that -// unlocking existing wallet with correct passphrase succeeds. +// TestUnlockWallet checks that trying to unlock non-existing wallet fail, that +// unlocking existing wallet with wrong passphrase fails, and that unlocking +// existing wallet with correct passphrase succeeds. func TestUnlockWallet(t *testing.T) { t.Parallel()