Skip to content

Commit c0d94a9

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 9af18c2 commit c0d94a9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lightning/src/ln/msgs.rs

Lines changed: 7 additions & 1 deletion
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, UnauthenticatedReceiveTlvs};
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};
@@ -2908,7 +2909,12 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
29082909
})
29092910
},
29102911
ChaChaPolyReadAdapter { readable: BlindedPaymentTlvs::Receive(receive_tlvs) } => {
2911-
let ReceiveTlvs { tlvs, authentication: _ } = receive_tlvs;
2912+
let ReceiveTlvs { tlvs, authentication: (hmac, nonce) } = receive_tlvs;
2913+
let expanded_key = node_signer.get_inbound_payment_key();
2914+
if tlvs.verify_for_offer_payment(hmac, nonce, &expanded_key).is_err() {
2915+
return Err(DecodeError::InvalidValue);
2916+
}
2917+
29122918
let UnauthenticatedReceiveTlvs {
29132919
payment_secret, payment_constraints, payment_context,
29142920
} = tlvs;

0 commit comments

Comments
 (0)