From db28e7c8911c5f85d680144aad0e0e1643ca29a5 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Thu, 11 Feb 2021 13:53:30 +0100 Subject: [PATCH] lnd: consolidate WalletUnlocker- and AdminAuthOptions --- lnd.go | 26 +++++--------------------- mobile/bindings.go | 4 ++-- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/lnd.go b/lnd.go index b0c741fb..4ead5573 100644 --- a/lnd.go +++ b/lnd.go @@ -54,31 +54,15 @@ import ( "github.com/lightningnetwork/lnd/watchtower/wtdb" ) -// WalletUnlockerAuthOptions returns a list of DialOptions that can be used to -// authenticate with the wallet unlocker service. -// -// NOTE: This should only be called after the WalletUnlocker listener has -// signaled it is ready. -func WalletUnlockerAuthOptions(cfg *Config) ([]grpc.DialOption, error) { - creds, err := credentials.NewClientTLSFromFile(cfg.TLSCertPath, "") - if err != nil { - return nil, fmt.Errorf("unable to read TLS cert: %v", err) - } - - // Create a dial options array with the TLS credentials. - opts := []grpc.DialOption{ - grpc.WithTransportCredentials(creds), - } - - return opts, nil -} - // AdminAuthOptions returns a list of DialOptions that can be used to // authenticate with the RPC server with admin capabilities. +// skipMacaroons=true should be set if we don't want to include macaroons with +// the auth options. This is needed for instance for the WalletUnlocker +// service, which must be usable also before macaroons are created. // // NOTE: This should only be called after the RPCListener has signaled it is // ready. -func AdminAuthOptions(cfg *Config) ([]grpc.DialOption, error) { +func AdminAuthOptions(cfg *Config, skipMacaroons bool) ([]grpc.DialOption, error) { creds, err := credentials.NewClientTLSFromFile(cfg.TLSCertPath, "") if err != nil { return nil, fmt.Errorf("unable to read TLS cert: %v", err) @@ -90,7 +74,7 @@ func AdminAuthOptions(cfg *Config) ([]grpc.DialOption, error) { } // Get the admin macaroon if macaroons are active. - if !cfg.NoMacaroons { + if !skipMacaroons && !cfg.NoMacaroons { // Load the adming macaroon file. macBytes, err := ioutil.ReadFile(cfg.AdminMacPath) if err != nil { diff --git a/mobile/bindings.go b/mobile/bindings.go index c157edcc..8cb60acb 100644 --- a/mobile/bindings.go +++ b/mobile/bindings.go @@ -105,7 +105,7 @@ func Start(extraArgs string, unlockerReady, rpcReady Callback) { // We must set the TLS certificates in order to properly // authenticate with the wallet unlocker service. - auth, err := lnd.WalletUnlockerAuthOptions(loadedConfig) + auth, err := lnd.AdminAuthOptions(loadedConfig, true) if err != nil { unlockerReady.OnError(err) return @@ -123,7 +123,7 @@ func Start(extraArgs string, unlockerReady, rpcReady Callback) { // Now that the RPC server is ready, we can get the needed // authentication options, and add them to the global dial // options. - auth, err := lnd.AdminAuthOptions(loadedConfig) + auth, err := lnd.AdminAuthOptions(loadedConfig, false) if err != nil { rpcReady.OnError(err) return