mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-06 01:18:17 +02:00
multi: pass blinding point through to reconstruction
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
@@ -17,6 +18,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/queue"
|
"github.com/lightningnetwork/lnd/queue"
|
||||||
|
"github.com/lightningnetwork/lnd/tlv"
|
||||||
)
|
)
|
||||||
|
|
||||||
// htlcIncomingContestResolver is a ContractResolver that's able to resolve an
|
// htlcIncomingContestResolver is a ContractResolver that's able to resolve an
|
||||||
@@ -520,9 +522,18 @@ func (h *htlcIncomingContestResolver) Supplement(htlc channeldb.HTLC) {
|
|||||||
func (h *htlcIncomingContestResolver) decodePayload() (*hop.Payload,
|
func (h *htlcIncomingContestResolver) decodePayload() (*hop.Payload,
|
||||||
[]byte, error) {
|
[]byte, error) {
|
||||||
|
|
||||||
|
var blindingPoint *btcec.PublicKey
|
||||||
|
h.htlc.BlindingPoint.WhenSome(
|
||||||
|
func(b tlv.RecordT[lnwire.BlindingPointTlvType,
|
||||||
|
*btcec.PublicKey]) {
|
||||||
|
|
||||||
|
blindingPoint = b.Val
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
onionReader := bytes.NewReader(h.htlc.OnionBlob[:])
|
onionReader := bytes.NewReader(h.htlc.OnionBlob[:])
|
||||||
iterator, err := h.OnionProcessor.ReconstructHopIterator(
|
iterator, err := h.OnionProcessor.ReconstructHopIterator(
|
||||||
onionReader, h.htlc.RHash[:],
|
onionReader, h.htlc.RHash[:], blindingPoint,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
@@ -6,6 +6,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
@@ -288,8 +289,8 @@ type mockOnionProcessor struct {
|
|||||||
offeredOnionBlob []byte
|
offeredOnionBlob []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *mockOnionProcessor) ReconstructHopIterator(r io.Reader, rHash []byte) (
|
func (o *mockOnionProcessor) ReconstructHopIterator(r io.Reader, rHash []byte,
|
||||||
hop.Iterator, error) {
|
blindingPoint *btcec.PublicKey) (hop.Iterator, error) {
|
||||||
|
|
||||||
data, err := ioutil.ReadAll(r)
|
data, err := ioutil.ReadAll(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
"github.com/lightningnetwork/lnd/channeldb/models"
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
@@ -40,7 +41,8 @@ type Registry interface {
|
|||||||
type OnionProcessor interface {
|
type OnionProcessor interface {
|
||||||
// ReconstructHopIterator attempts to decode a valid sphinx packet from
|
// ReconstructHopIterator attempts to decode a valid sphinx packet from
|
||||||
// the passed io.Reader instance.
|
// the passed io.Reader instance.
|
||||||
ReconstructHopIterator(r io.Reader, rHash []byte) (hop.Iterator, error)
|
ReconstructHopIterator(r io.Reader, rHash []byte,
|
||||||
|
blindingKey *btcec.PublicKey) (hop.Iterator, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UtxoSweeper defines the sweep functions that contract court requires.
|
// UtxoSweeper defines the sweep functions that contract court requires.
|
||||||
|
@@ -150,20 +150,27 @@ func (p *OnionProcessor) Stop() error {
|
|||||||
// ReconstructHopIterator attempts to decode a valid sphinx packet from the passed io.Reader
|
// ReconstructHopIterator attempts to decode a valid sphinx packet from the passed io.Reader
|
||||||
// instance using the rHash as the associated data when checking the relevant
|
// instance using the rHash as the associated data when checking the relevant
|
||||||
// MACs during the decoding process.
|
// MACs during the decoding process.
|
||||||
func (p *OnionProcessor) ReconstructHopIterator(r io.Reader, rHash []byte) (
|
func (p *OnionProcessor) ReconstructHopIterator(r io.Reader, rHash []byte,
|
||||||
Iterator, error) {
|
blindingPoint *btcec.PublicKey) (Iterator, error) {
|
||||||
|
|
||||||
onionPkt := &sphinx.OnionPacket{}
|
onionPkt := &sphinx.OnionPacket{}
|
||||||
if err := onionPkt.Decode(r); err != nil {
|
if err := onionPkt.Decode(r); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var opts []sphinx.ProcessOnionOpt
|
||||||
|
if blindingPoint != nil {
|
||||||
|
opts = append(opts, sphinx.WithBlindingPoint(blindingPoint))
|
||||||
|
}
|
||||||
|
|
||||||
// Attempt to process the Sphinx packet. We include the payment hash of
|
// Attempt to process the Sphinx packet. We include the payment hash of
|
||||||
// the HTLC as it's authenticated within the Sphinx packet itself as
|
// the HTLC as it's authenticated within the Sphinx packet itself as
|
||||||
// associated data in order to thwart attempts a replay attacks. In the
|
// associated data in order to thwart attempts a replay attacks. In the
|
||||||
// case of a replay, an attacker is *forced* to use the same payment
|
// case of a replay, an attacker is *forced* to use the same payment
|
||||||
// hash twice, thereby losing their money entirely.
|
// hash twice, thereby losing their money entirely.
|
||||||
sphinxPacket, err := p.router.ReconstructOnionPacket(onionPkt, rHash)
|
sphinxPacket, err := p.router.ReconstructOnionPacket(
|
||||||
|
onionPkt, rHash, opts...,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user