@@ -659,33 +659,9 @@ func (g *LightningTerminal) ValidateMacaroon(ctx context.Context,
659
659
return err
660
660
}
661
661
662
- // If we haven't connected to lnd yet, we can't check the super
663
- // macaroon. The user will need to wait a bit.
664
- if g .lndClient == nil {
665
- return fmt .Errorf ("cannot validate macaroon, not yet " +
666
- "connected to lnd, please wait" )
667
- }
668
-
669
- // Convert permissions to the form that lndClient will accept.
670
- permissions := make (
671
- []lndclient.MacaroonPermission , len (requiredPermissions ),
662
+ return g .validateSuperMacaroon (
663
+ ctx , macBytes , requiredPermissions , fullMethod ,
672
664
)
673
- for idx , perm := range requiredPermissions {
674
- permissions [idx ] = lndclient.MacaroonPermission {
675
- Entity : perm .Entity ,
676
- Action : perm .Action ,
677
- }
678
- }
679
-
680
- res , err := g .lndClient .Client .CheckMacaroonPermissions (
681
- ctx , macBytes , permissions , fullMethod ,
682
- )
683
- if ! res {
684
- return fmt .Errorf ("macaroon is not valid, returned %v" ,
685
- res )
686
- }
687
-
688
- return err
689
665
}
690
666
691
667
// Validate all macaroons for services that are running in the local
@@ -1129,6 +1105,45 @@ func (g *LightningTerminal) createRESTProxy() error {
1129
1105
return nil
1130
1106
}
1131
1107
1108
+ // validateSuperMacaroon makes sure the given macaroon is a valid super macaroon
1109
+ // that was issued by lnd and contains all the required permissions, even if
1110
+ // the actual RPC method isn't a lnd request.
1111
+ func (g * LightningTerminal ) validateSuperMacaroon (ctx context.Context ,
1112
+ superMacaroon []byte , requiredPermissions []bakery.Op ,
1113
+ fullMethod string ) error {
1114
+
1115
+ // If we haven't connected to lnd yet, we can't check the super
1116
+ // macaroon. The user will need to wait a bit.
1117
+ if g .lndClient == nil {
1118
+ return fmt .Errorf ("cannot validate macaroon, not yet " +
1119
+ "connected to lnd, please wait" )
1120
+ }
1121
+
1122
+ // Convert permissions to the form that lndClient will accept.
1123
+ permissions := make (
1124
+ []lndclient.MacaroonPermission , len (requiredPermissions ),
1125
+ )
1126
+ for idx , perm := range requiredPermissions {
1127
+ permissions [idx ] = lndclient.MacaroonPermission {
1128
+ Entity : perm .Entity ,
1129
+ Action : perm .Action ,
1130
+ }
1131
+ }
1132
+
1133
+ res , err := g .lndClient .Client .CheckMacaroonPermissions (
1134
+ ctx , superMacaroon , permissions , fullMethod ,
1135
+ )
1136
+ if err != nil {
1137
+ return fmt .Errorf ("lnd macaroon validation failed: %v" ,
1138
+ err )
1139
+ }
1140
+ if ! res {
1141
+ return fmt .Errorf ("macaroon is not valid" )
1142
+ }
1143
+
1144
+ return nil
1145
+ }
1146
+
1132
1147
// BakeSuperMacaroon uses the lnd client to bake a macaroon that can include
1133
1148
// permissions for multiple daemons.
1134
1149
func BakeSuperMacaroon (ctx context.Context , lnd lnrpc.LightningClient ,
0 commit comments