Skip to content

Commit 059f9bf

Browse files
committed
Verify that an HTLC's ReceiveTlvs is authentic
When receiving a payment over a BlindedPaymentPath, a PaymentContext is included but was not authenticated. The previous commit adds an HMAC of the payment::ReceiveTlvs (which contains the PaymentContext) and the nonce used to create the HMAC. This commit verifies the authenticity when parsing the InboundOnionPayload. This prevents a malicious actor from for forging it.
1 parent 7a0bab2 commit 059f9bf

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

lightning/src/ln/msgs.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use bitcoin::script::ScriptBuf;
3232
use bitcoin::hash_types::Txid;
3333

3434
use crate::blinded_path::payment::{BlindedPaymentTlvs, ForwardTlvs, ReceiveTlvs};
35+
use crate::ln::channelmanager::Verification;
3536
use crate::ln::types::ChannelId;
3637
use crate::types::payment::{PaymentPreimage, PaymentHash, PaymentSecret};
3738
use crate::types::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
@@ -2907,9 +2908,19 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
29072908
next_blinding_override,
29082909
})
29092910
},
2910-
ChaChaPolyReadAdapter { readable: BlindedPaymentTlvs::Receive(ReceiveTlvs {
2911-
payment_secret, payment_constraints, payment_context, authentication: _,
2912-
})} => {
2911+
ChaChaPolyReadAdapter { readable: BlindedPaymentTlvs::Receive(mut receive_tlvs) } => {
2912+
if let Some((hmac, nonce)) = receive_tlvs.authentication.take() {
2913+
let expanded_key = node_signer.get_inbound_payment_key();
2914+
if receive_tlvs.verify_for_offer_payment(hmac, nonce, &expanded_key).is_err() {
2915+
return Err(DecodeError::InvalidValue);
2916+
}
2917+
} else {
2918+
return Err(DecodeError::InvalidValue);
2919+
}
2920+
2921+
let ReceiveTlvs {
2922+
payment_secret, payment_constraints, payment_context, authentication: _,
2923+
} = receive_tlvs;
29132924
if total_msat.unwrap_or(0) > MAX_VALUE_MSAT { return Err(DecodeError::InvalidValue) }
29142925
Ok(Self::BlindedReceive {
29152926
sender_intended_htlc_amt_msat: amt.ok_or(DecodeError::InvalidValue)?,

0 commit comments

Comments
 (0)