Skip to content

Commit d4d22f6

Browse files
committed
f - HMAC entire ReceiveTlvs
1 parent 9e0fc23 commit d4d22f6

File tree

3 files changed

+22
-31
lines changed

3 files changed

+22
-31
lines changed

lightning/src/ln/channelmanager.rs

+4-17
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,6 @@ pub enum PendingHTLCRouting {
198198
custom_tlvs: Vec<(u64, Vec<u8>)>,
199199
/// Set if this HTLC is the final hop in a multi-hop blinded path.
200200
requires_blinded_error: bool,
201-
/// An HMAC of `payment_context` along with a nonce used to construct it.
202-
authentication: Option<(Hmac<Sha256>, Nonce)>,
203201
},
204202
/// The onion indicates that this is for payment to us but which contains the preimage for
205203
/// claiming included, and is unrelated to any invoice we'd previously generated (aka a
@@ -5996,19 +5994,19 @@ where
59965994
let blinded_failure = routing.blinded_failure();
59975995
let (
59985996
cltv_expiry, onion_payload, payment_data, payment_context, phantom_shared_secret,
5999-
mut onion_fields, has_recipient_created_payment_secret, authentication,
5997+
mut onion_fields, has_recipient_created_payment_secret
60005998
) = match routing {
60015999
PendingHTLCRouting::Receive {
60026000
payment_data, payment_metadata, payment_context,
60036001
incoming_cltv_expiry, phantom_shared_secret, custom_tlvs,
6004-
requires_blinded_error: _, authentication,
6002+
requires_blinded_error: _
60056003
} => {
60066004
let _legacy_hop_data = Some(payment_data.clone());
60076005
let onion_fields = RecipientOnionFields { payment_secret: Some(payment_data.payment_secret),
60086006
payment_metadata, custom_tlvs };
60096007
(incoming_cltv_expiry, OnionPayload::Invoice { _legacy_hop_data },
60106008
Some(payment_data), payment_context, phantom_shared_secret, onion_fields,
6011-
true, authentication)
6009+
true)
60126010
},
60136011
PendingHTLCRouting::ReceiveKeysend {
60146012
payment_data, payment_preimage, payment_metadata,
@@ -6021,7 +6019,7 @@ where
60216019
custom_tlvs,
60226020
};
60236021
(incoming_cltv_expiry, OnionPayload::Spontaneous(payment_preimage),
6024-
payment_data, None, None, onion_fields, has_recipient_created_payment_secret, None)
6022+
payment_data, None, None, onion_fields, has_recipient_created_payment_secret)
60256023
},
60266024
_ => {
60276025
panic!("short_channel_id == 0 should imply any pending_forward entries are of type Receive");
@@ -6206,16 +6204,6 @@ where
62066204
payment_preimage
62076205
} else { fail_htlc!(claimable_htlc, payment_hash); }
62086206
} else { None };
6209-
6210-
// Authenticate the PaymentContext received over a BlindedPaymentPath
6211-
if let Some(payment_context) = payment_context.as_ref() {
6212-
if let Some((hmac, nonce)) = authentication {
6213-
if payment_context.verify_for_offer_payment(hmac, nonce, &self.inbound_payment_key).is_err() {
6214-
fail_htlc!(claimable_htlc, payment_hash);
6215-
}
6216-
}
6217-
}
6218-
62196207
match claimable_htlc.onion_payload {
62206208
OnionPayload::Invoice { .. } => {
62216209
let payment_data = payment_data.unwrap();
@@ -12374,7 +12362,6 @@ impl_writeable_tlv_based_enum!(PendingHTLCRouting,
1237412362
(5, custom_tlvs, optional_vec),
1237512363
(7, requires_blinded_error, (default_value, false)),
1237612364
(9, payment_context, option),
12377-
(11, authentication, option),
1237812365
},
1237912366
(2, ReceiveKeysend) => {
1238012367
(0, payment_preimage, required),

lightning/src/ln/msgs.rs

+14-8
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};
@@ -1745,12 +1746,9 @@ pub struct FinalOnionHopData {
17451746
}
17461747

17471748
mod fuzzy_internal_msgs {
1748-
use bitcoin::hashes::hmac::Hmac;
1749-
use bitcoin::hashes::sha256::Hash as Sha256;
17501749
use bitcoin::secp256k1::PublicKey;
17511750
use crate::blinded_path::payment::{BlindedPaymentPath, PaymentConstraints, PaymentContext, PaymentRelay};
17521751
use crate::offers::invoice_request::InvoiceRequest;
1753-
use crate::offers::nonce::Nonce;
17541752
use crate::types::payment::{PaymentPreimage, PaymentSecret};
17551753
use crate::types::features::{BlindedHopFeatures, Bolt12InvoiceFeatures};
17561754
use super::{FinalOnionHopData, TrampolineOnionPacket};
@@ -1794,7 +1792,6 @@ mod fuzzy_internal_msgs {
17941792
intro_node_blinding_point: Option<PublicKey>,
17951793
keysend_preimage: Option<PaymentPreimage>,
17961794
custom_tlvs: Vec<(u64, Vec<u8>)>,
1797-
authentication: (Hmac<Sha256>, Nonce),
17981795
}
17991796
}
18001797

@@ -2911,9 +2908,19 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
29112908
next_blinding_override,
29122909
})
29132910
},
2914-
ChaChaPolyReadAdapter { readable: BlindedPaymentTlvs::Receive(ReceiveTlvs {
2915-
payment_secret, payment_constraints, payment_context, authentication,
2916-
})} => {
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;
29172924
if total_msat.unwrap_or(0) > MAX_VALUE_MSAT { return Err(DecodeError::InvalidValue) }
29182925
Ok(Self::BlindedReceive {
29192926
sender_intended_htlc_amt_msat: amt.ok_or(DecodeError::InvalidValue)?,
@@ -2925,7 +2932,6 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
29252932
intro_node_blinding_point,
29262933
keysend_preimage,
29272934
custom_tlvs,
2928-
authentication,
29292935
})
29302936
},
29312937
}

lightning/src/ln/onion_payment.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,18 @@ pub(super) fn create_recv_pending_htlc_info(
135135
) -> Result<PendingHTLCInfo, InboundHTLCErr> {
136136
let (
137137
payment_data, keysend_preimage, custom_tlvs, onion_amt_msat, onion_cltv_expiry,
138-
payment_metadata, payment_context, requires_blinded_error, has_recipient_created_payment_secret,
139-
authentication,
138+
payment_metadata, payment_context, requires_blinded_error, has_recipient_created_payment_secret
140139
) = match hop_data {
141140
msgs::InboundOnionPayload::Receive {
142141
payment_data, keysend_preimage, custom_tlvs, sender_intended_htlc_amt_msat,
143142
cltv_expiry_height, payment_metadata, ..
144143
} =>
145144
(payment_data, keysend_preimage, custom_tlvs, sender_intended_htlc_amt_msat,
146-
cltv_expiry_height, payment_metadata, None, false, keysend_preimage.is_none(), None),
145+
cltv_expiry_height, payment_metadata, None, false, keysend_preimage.is_none()),
147146
msgs::InboundOnionPayload::BlindedReceive {
148147
sender_intended_htlc_amt_msat, total_msat, cltv_expiry_height, payment_secret,
149148
intro_node_blinding_point, payment_constraints, payment_context, keysend_preimage,
150-
custom_tlvs, authentication,
149+
custom_tlvs
151150
} => {
152151
check_blinded_payment_constraints(
153152
sender_intended_htlc_amt_msat, cltv_expiry, &payment_constraints
@@ -162,7 +161,7 @@ pub(super) fn create_recv_pending_htlc_info(
162161
let payment_data = msgs::FinalOnionHopData { payment_secret, total_msat };
163162
(Some(payment_data), keysend_preimage, custom_tlvs,
164163
sender_intended_htlc_amt_msat, cltv_expiry_height, None, Some(payment_context),
165-
intro_node_blinding_point.is_none(), true, Some(authentication))
164+
intro_node_blinding_point.is_none(), true)
166165
}
167166
msgs::InboundOnionPayload::Forward { .. } => {
168167
return Err(InboundHTLCErr {
@@ -253,7 +252,6 @@ pub(super) fn create_recv_pending_htlc_info(
253252
phantom_shared_secret,
254253
custom_tlvs,
255254
requires_blinded_error,
256-
authentication,
257255
}
258256
} else {
259257
return Err(InboundHTLCErr {

0 commit comments

Comments
 (0)