8
8
"sync"
9
9
10
10
"github.com/btcsuite/btcd/btcec/v2"
11
+ "github.com/btcsuite/btcd/btcec/v2/ecdsa"
12
+ "github.com/btcsuite/btcd/chaincfg/chainhash"
11
13
"github.com/lightninglabs/lightning-terminal/autopilotserverrpc"
12
14
"github.com/lightninglabs/lightning-terminal/rules"
13
15
"github.com/lightningnetwork/lnd/lntest/node"
@@ -44,6 +46,7 @@ type ClientState uint8
44
46
const (
45
47
ClientStateActive = iota
46
48
ClientStateInactive
49
+ ClientStateRevoked
47
50
)
48
51
49
52
type clientSession struct {
@@ -103,6 +106,11 @@ func (m *Server) SetFeatures(f map[string]*Feature) {
103
106
m .featureSet = f
104
107
}
105
108
109
+ // ResetDefaultFeatures resets the servers features set to the default set.
110
+ func (m * Server ) ResetDefaultFeatures () {
111
+ m .featureSet = defaultFeatures
112
+ }
113
+
106
114
// Terms returns any meta data from the autopilot server.
107
115
//
108
116
// Note: this is part of the autopilotrpc.AutopilotServer interface.
@@ -167,6 +175,32 @@ func (m *Server) RegisterSession(_ context.Context,
167
175
return nil , err
168
176
}
169
177
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
+
170
204
m .sessions [hex .EncodeToString (req .ResponderPubKey )] = & clientSession {
171
205
key : priv ,
172
206
state : ClientStateActive ,
@@ -204,7 +238,12 @@ func (m *Server) RevokeSession(_ context.Context,
204
238
m .sessMu .Lock ()
205
239
defer m .sessMu .Unlock ()
206
240
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
208
247
209
248
return & autopilotserverrpc.RevokeSessionResponse {}, nil
210
249
}
@@ -271,7 +310,7 @@ var defaultFeatures = map[string]*Feature{
271
310
"HealthCheck" : {
272
311
Description : "check that your node is up" ,
273
312
Rules : map [string ]* RuleRanges {
274
- rules .RateLimitName : rateLimitRule ,
313
+ rules .RateLimitName : RateLimitRule ,
275
314
},
276
315
Permissions : map [string ][]bakery.Op {
277
316
"/lnrpc.Lightning/GetInfo" : {{
@@ -283,7 +322,7 @@ var defaultFeatures = map[string]*Feature{
283
322
"AutoFees" : {
284
323
Description : "manages your channel fees" ,
285
324
Rules : map [string ]* RuleRanges {
286
- rules .RateLimitName : rateLimitRule ,
325
+ rules .RateLimitName : RateLimitRule ,
287
326
},
288
327
Permissions : map [string ][]bakery.Op {
289
328
"/lnrpc.Lightning/ListChannels" : {{
@@ -302,7 +341,7 @@ var defaultFeatures = map[string]*Feature{
302
341
},
303
342
}
304
343
305
- var rateLimitRule = & RuleRanges {
344
+ var RateLimitRule = & RuleRanges {
306
345
Default : & rules.RateLimit {
307
346
WriteLimit : & rules.Rate {
308
347
Iterations : 1 ,
0 commit comments