Skip to content

Commit 621f295

Browse files
authored
Merge pull request #378 from ellemouton/addSessionExpiryAsMacaroonCaveat
session_rpcserver: add session expiry as macaroon caveat
2 parents 53618d9 + 8777794 commit 621f295

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

session_rpcserver.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"github.com/lightninglabs/lightning-terminal/litrpc"
1313
"github.com/lightninglabs/lightning-terminal/session"
1414
"google.golang.org/grpc"
15+
"gopkg.in/macaroon-bakery.v2/bakery/checkers"
16+
"gopkg.in/macaroon.v2"
1517
)
1618

1719
// sessionRpcServer is the gRPC server for the Session RPC interface.
@@ -188,11 +190,22 @@ func (s *sessionRpcServer) resumeSession(sess *session.Session) error {
188190
return nil
189191
}
190192

191-
readOnly := sess.Type == session.TypeMacaroonReadonly
193+
var (
194+
caveats []macaroon.Caveat
195+
readOnly = sess.Type == session.TypeMacaroonReadonly
196+
)
197+
198+
// Add the session expiry as a macaroon caveat.
199+
macExpiry := checkers.TimeBeforeCaveat(sess.Expiry)
200+
caveats = append(caveats, macaroon.Caveat{
201+
Id: []byte(macExpiry.Condition),
202+
})
203+
192204
mac, err := s.cfg.superMacBaker(
193205
context.Background(), sess.MacaroonRootKey,
194206
&session.MacaroonRecipe{
195207
Permissions: GetAllPermissions(readOnly),
208+
Caveats: caveats,
196209
},
197210
)
198211
if err != nil {

0 commit comments

Comments
 (0)