mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
autopilotserver/mock: upgrade mock for session linking
This commit is contained in:
parent
5817543ad9
commit
d0db03a07c
1 changed files with 35 additions and 1 deletions
|
|
@ -8,6 +8,8 @@ import (
|
|||
"sync"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/lightninglabs/lightning-terminal/autopilotserverrpc"
|
||||
"github.com/lightninglabs/lightning-terminal/rules"
|
||||
"github.com/lightningnetwork/lnd/lntest/node"
|
||||
|
|
@ -44,6 +46,7 @@ type ClientState uint8
|
|||
const (
|
||||
ClientStateActive = iota
|
||||
ClientStateInactive
|
||||
ClientStateRevoked
|
||||
)
|
||||
|
||||
type clientSession struct {
|
||||
|
|
@ -172,6 +175,32 @@ func (m *Server) RegisterSession(_ context.Context,
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// If linked session, check that signature is valid.
|
||||
if len(req.GroupResponderKey) != 0 {
|
||||
// Check that the group key is a known key.
|
||||
_, ok := m.sessions[hex.EncodeToString(req.GroupResponderKey)]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unknown group key")
|
||||
}
|
||||
|
||||
// Check that the signature provided is valid.
|
||||
sig, err := ecdsa.ParseDERSignature(req.GroupResponderSig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
msg := chainhash.HashB(req.ResponderPubKey)
|
||||
|
||||
groupKey, err := btcec.ParsePubKey(req.GroupResponderKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !sig.Verify(msg, groupKey) {
|
||||
return nil, fmt.Errorf("invalid signature")
|
||||
}
|
||||
}
|
||||
|
||||
m.sessions[hex.EncodeToString(req.ResponderPubKey)] = &clientSession{
|
||||
key: priv,
|
||||
state: ClientStateActive,
|
||||
|
|
@ -209,7 +238,12 @@ func (m *Server) RevokeSession(_ context.Context,
|
|||
m.sessMu.Lock()
|
||||
defer m.sessMu.Unlock()
|
||||
|
||||
delete(m.sessions, hex.EncodeToString(req.ResponderPubKey))
|
||||
sess, ok := m.sessions[hex.EncodeToString(req.ResponderPubKey)]
|
||||
if !ok {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
sess.state = ClientStateRevoked
|
||||
|
||||
return &autopilotserverrpc.RevokeSessionResponse{}, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue