Skip to content

Commit 5d4ae27

Browse files
committed
multi: add super mac validator to proxy
1 parent 6d03a8c commit 5d4ae27

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

rpc_proxy.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"time"
1414

1515
"github.com/improbable-eng/grpc-web/go/grpcweb"
16+
"github.com/lightninglabs/lightning-terminal/session"
1617
"github.com/lightningnetwork/lnd/lncfg"
1718
"github.com/lightningnetwork/lnd/macaroons"
1819
grpcProxy "github.com/mwitkow/grpc-proxy/proxy"
@@ -64,6 +65,7 @@ func (e *proxyErr) Unwrap() error {
6465
// or REST request and delegate (and convert if necessary) it to the correct
6566
// component.
6667
func newRpcProxy(cfg *Config, validator macaroons.MacaroonValidator,
68+
superMacValidator session.SuperMacaroonValidator,
6769
permissionMap map[string][]bakery.Op,
6870
bufListener *bufconn.Listener) *rpcProxy {
6971

@@ -80,10 +82,11 @@ func newRpcProxy(cfg *Config, validator macaroons.MacaroonValidator,
8082
// need to be addressed with a custom director that just takes care of a
8183
// few HTTP header fields.
8284
p := &rpcProxy{
83-
cfg: cfg,
84-
basicAuth: basicAuth,
85-
macValidator: validator,
86-
bufListener: bufListener,
85+
cfg: cfg,
86+
basicAuth: basicAuth,
87+
macValidator: validator,
88+
superMacValidator: superMacValidator,
89+
bufListener: bufListener,
8790
}
8891
p.grpcServer = grpc.NewServer(
8992
// From the grpxProxy doc: This codec is *crucial* to the
@@ -156,8 +159,9 @@ type rpcProxy struct {
156159
cfg *Config
157160
basicAuth string
158161

159-
macValidator macaroons.MacaroonValidator
160-
bufListener *bufconn.Listener
162+
macValidator macaroons.MacaroonValidator
163+
superMacValidator session.SuperMacaroonValidator
164+
bufListener *bufconn.Listener
161165

162166
superMacaroon string
163167

session/macaroon.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package session
22

33
import (
44
"bytes"
5+
"context"
56
"encoding/binary"
67
"encoding/hex"
78
"strconv"
@@ -18,6 +19,11 @@ var (
1819
SuperMacaroonRootKeyPrefix = [4]byte{0xFF, 0xEE, 0xDD, 0xCC}
1920
)
2021

22+
// SuperMacaroonValidator is a function type for validating a super macaroon.
23+
type SuperMacaroonValidator func(ctx context.Context,
24+
superMacaroon []byte, requiredPermissions []bakery.Op,
25+
fullMethod string) error
26+
2127
// NewSuperMacaroonRootKeyID returns a new macaroon root key ID that has the
2228
// prefix to mark it as a super macaroon root key.
2329
func NewSuperMacaroonRootKeyID(id [4]byte) uint64 {

terminal.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ func (g *LightningTerminal) Run() error {
194194
g.loopServer = loopd.New(g.cfg.Loop, nil)
195195
g.poolServer = pool.NewServer(g.cfg.Pool)
196196
g.rpcProxy = newRpcProxy(
197-
g.cfg, g, getAllMethodPermissions(), bufRpcListener,
197+
g.cfg, g, g.validateSuperMacaroon, getAllMethodPermissions(),
198+
bufRpcListener,
198199
)
199200

200201
// Create an instance of the local Terminal Connect session store DB.

0 commit comments

Comments
 (0)