link: ensure minimum failure reason length
This commit modifies the link behavior so that every failure reason that we pass back is length-compliant (>=256 bytes).
This commit is contained in:
2 files changed
+138
-3
No files matched your search
@@ -2,6 +2,7 @@ package htlcswitch
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
crand "crypto/rand"
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
prand "math/rand"
|
||||
@@ -1850,6 +1851,35 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
|
||||
}
|
||||
|
||||
case *lnwire.UpdateFailHTLC:
|
||||
// Verify that the failure reason is at least 256 bytes plus
|
||||
// overhead.
|
||||
const minimumFailReasonLength = lnwire.FailureMessageLength +
|
||||
2 + 2 + 32
|
||||
|
||||
if len(msg.Reason) < minimumFailReasonLength {
|
||||
// We've received a reason with a non-compliant length.
|
||||
// Older nodes happily relay back these failures that
|
||||
// may originate from a node further downstream.
|
||||
// Therefore we can't just fail the channel.
|
||||
//
|
||||
// We want to be compliant ourselves, so we also can't
|
||||
// pass back the reason unmodified. And we must make
|
||||
// sure that we don't hit the magic length check of 260
|
||||
// bytes in processRemoteSettleFails either.
|
||||
//
|
||||
// Because the reason is unreadable for the payer
|
||||
// anyway, we just replace it by a compliant-length
|
||||
// series of random bytes.
|
||||
msg.Reason = make([]byte, minimumFailReasonLength)
|
||||
_, err := crand.Read(msg.Reason[:])
|
||||
if err != nil {
|
||||
l.log.Errorf("Random generation error: %v", err)
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Add fail to the update log.
|
||||
idx := msg.ID
|
||||
err := l.channel.ReceiveFailHTLC(idx, msg.Reason[:])
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user