watchtower/wtserver: reject unknown blob types

This commit is contained in:
Conner Fromknecht 2019-01-10 15:35:14 -08:00
parent 4f3655ba93
commit ca3e06b785
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
2 changed files with 27 additions and 0 deletions

@ -13,6 +13,7 @@ import (
"github.com/btcsuite/btcd/connmgr"
"github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/watchtower/blob"
"github.com/lightningnetwork/lnd/watchtower/wtdb"
"github.com/lightningnetwork/lnd/watchtower/wtpolicy"
"github.com/lightningnetwork/lnd/watchtower/wtwire"
@ -370,6 +371,15 @@ func (s *Server) handleCreateSession(peer Peer, id *wtdb.SessionID,
rewardAddrBytes := rewardAddress.ScriptAddress()
// Ensure that the requested blob type is supported by our tower.
if !blob.IsSupportedType(req.BlobType) {
log.Debugf("Rejecting CreateSession from %s, unsupported blob "+
"type %s", id, req.BlobType)
return s.replyCreateSession(
peer, id, wtwire.CreateSessionCodeRejectBlobType, nil,
)
}
// TODO(conner): create invoice for upfront payment
// Assemble the session info using the agreed upon parameters, reward

@ -170,6 +170,23 @@ var createSessionTests = []createSessionTestCase{
Data: []byte(addr.ScriptAddress()),
},
},
{
name: "reject unsupported blob type",
initMsg: wtwire.NewInitMessage(
lnwire.NewRawFeatureVector(),
lnwire.NewRawFeatureVector(),
),
createMsg: &wtwire.CreateSession{
BlobType: 0,
MaxUpdates: 1000,
RewardRate: 0,
SweepFeeRate: 1,
},
expReply: &wtwire.CreateSessionReply{
Code: wtwire.CreateSessionCodeRejectBlobType,
Data: []byte{},
},
},
// TODO(conner): add policy rejection tests
}