88 "sync"
99
1010 "github.com/btcsuite/btcd/btcec/v2"
11+ "github.com/btcsuite/btcd/btcec/v2/ecdsa"
12+ "github.com/btcsuite/btcd/chaincfg/chainhash"
1113 "github.com/lightninglabs/lightning-terminal/autopilotserverrpc"
1214 "github.com/lightninglabs/lightning-terminal/rules"
1315 "github.com/lightningnetwork/lnd/lntest/node"
@@ -44,6 +46,7 @@ type ClientState uint8
4446const (
4547 ClientStateActive = iota
4648 ClientStateInactive
49+ ClientStateRevoked
4750)
4851
4952type clientSession struct {
@@ -103,6 +106,11 @@ func (m *Server) SetFeatures(f map[string]*Feature) {
103106 m .featureSet = f
104107}
105108
109+ // ResetDefaultFeatures resets the servers features set to the default set.
110+ func (m * Server ) ResetDefaultFeatures () {
111+ m .featureSet = defaultFeatures
112+ }
113+
106114// Terms returns any meta data from the autopilot server.
107115//
108116// Note: this is part of the autopilotrpc.AutopilotServer interface.
@@ -167,6 +175,32 @@ func (m *Server) RegisterSession(_ context.Context,
167175 return nil , err
168176 }
169177
178+ // If linked session, check that signature is valid.
179+ if len (req .GroupResponderKey ) != 0 {
180+ // Check that the group key is a known key.
181+ _ , ok := m .sessions [hex .EncodeToString (req .GroupResponderKey )]
182+ if ! ok {
183+ return nil , fmt .Errorf ("unknown group key" )
184+ }
185+
186+ // Check that the signature provided is valid.
187+ sig , err := ecdsa .ParseDERSignature (req .GroupResponderSig )
188+ if err != nil {
189+ return nil , err
190+ }
191+
192+ msg := chainhash .HashB (req .ResponderPubKey )
193+
194+ groupKey , err := btcec .ParsePubKey (req .GroupResponderKey )
195+ if err != nil {
196+ return nil , err
197+ }
198+
199+ if ! sig .Verify (msg , groupKey ) {
200+ return nil , fmt .Errorf ("invalid signature" )
201+ }
202+ }
203+
170204 m .sessions [hex .EncodeToString (req .ResponderPubKey )] = & clientSession {
171205 key : priv ,
172206 state : ClientStateActive ,
@@ -204,7 +238,12 @@ func (m *Server) RevokeSession(_ context.Context,
204238 m .sessMu .Lock ()
205239 defer m .sessMu .Unlock ()
206240
207- delete (m .sessions , hex .EncodeToString (req .ResponderPubKey ))
241+ sess , ok := m .sessions [hex .EncodeToString (req .ResponderPubKey )]
242+ if ! ok {
243+ return nil , nil
244+ }
245+
246+ sess .state = ClientStateRevoked
208247
209248 return & autopilotserverrpc.RevokeSessionResponse {}, nil
210249}
@@ -271,7 +310,7 @@ var defaultFeatures = map[string]*Feature{
271310 "HealthCheck" : {
272311 Description : "check that your node is up" ,
273312 Rules : map [string ]* RuleRanges {
274- rules .RateLimitName : rateLimitRule ,
313+ rules .RateLimitName : RateLimitRule ,
275314 },
276315 Permissions : map [string ][]bakery.Op {
277316 "/lnrpc.Lightning/GetInfo" : {{
@@ -283,7 +322,7 @@ var defaultFeatures = map[string]*Feature{
283322 "AutoFees" : {
284323 Description : "manages your channel fees" ,
285324 Rules : map [string ]* RuleRanges {
286- rules .RateLimitName : rateLimitRule ,
325+ rules .RateLimitName : RateLimitRule ,
287326 },
288327 Permissions : map [string ][]bakery.Op {
289328 "/lnrpc.Lightning/ListChannels" : {{
@@ -302,7 +341,7 @@ var defaultFeatures = map[string]*Feature{
302341 },
303342}
304343
305- var rateLimitRule = & RuleRanges {
344+ var RateLimitRule = & RuleRanges {
306345 Default : & rules.RateLimit {
307346 WriteLimit : & rules.Rate {
308347 Iterations : 1 ,
0 commit comments