mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
walletunlocker: don't utilize the macaroon authentication service
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.
This commit is contained in:
parent
8de0a4cb24
commit
08940b43d5
@ -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)
|
||||
|
||||
|
@ -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()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user