File tree Expand file tree Collapse file tree 3 files changed +46
-1
lines changed Expand file tree Collapse file tree 3 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -402,6 +402,24 @@ pub enum AsyncPaymentsContext {
402402 /// containing the expected [`PaymentId`].
403403 hmac : Hmac < Sha256 > ,
404404 } ,
405+ /// Context contained within the [`BlindedMessagePath`]s we put in static invoices, provided back
406+ /// to us in corresponding [`HeldHtlcAvailable`] messages.
407+ ///
408+ /// [`HeldHtlcAvailable`]: crate::onion_message::async_payments::HeldHtlcAvailable
409+ InboundPayment {
410+ /// A nonce used for authenticating that a [`HeldHtlcAvailable`] message is valid for a
411+ /// preceding static invoice.
412+ ///
413+ /// [`HeldHtlcAvailable`]: crate::onion_message::async_payments::HeldHtlcAvailable
414+ nonce : Nonce ,
415+ /// Authentication code for the [`HeldHtlcAvailable`] message.
416+ ///
417+ /// Prevents nodes from creating their own blinded path to us, sending a [`HeldHtlcAvailable`]
418+ /// message and trivially getting notified whenever we come online.
419+ ///
420+ /// [`HeldHtlcAvailable`]: crate::onion_message::async_payments::HeldHtlcAvailable
421+ hmac : Hmac < Sha256 > ,
422+ } ,
405423}
406424
407425impl_writeable_tlv_based_enum ! ( MessageContext ,
@@ -433,6 +451,10 @@ impl_writeable_tlv_based_enum!(AsyncPaymentsContext,
433451 ( 2 , nonce, required) ,
434452 ( 4 , hmac, required) ,
435453 } ,
454+ ( 1 , InboundPayment ) => {
455+ ( 0 , nonce, required) ,
456+ ( 2 , hmac, required) ,
457+ } ,
436458) ;
437459
438460/// Contains a simple nonce for use in a blinded path's context.
Original file line number Diff line number Diff line change @@ -12191,7 +12191,12 @@ where
1219112191
1219212192 fn handle_release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) {
1219312193 #[cfg(async_payments)] {
12194- let AsyncPaymentsContext::OutboundPayment { payment_id, hmac, nonce } = _context;
12194+ let (payment_id, nonce, hmac) = match _context {
12195+ AsyncPaymentsContext::OutboundPayment { payment_id, hmac, nonce } => {
12196+ (payment_id, nonce, hmac)
12197+ },
12198+ _ => return
12199+ };
1219512200 if payment_id.verify_for_async_payment(hmac, nonce, &self.inbound_payment_key).is_err() { return }
1219612201 if let Err(e) = self.send_payment_for_static_invoice(payment_id) {
1219712202 log_trace!(
Original file line number Diff line number Diff line change @@ -50,6 +50,11 @@ const PAYMENT_HASH_HMAC_INPUT: &[u8; 16] = &[7; 16];
5050// HMAC input for `ReceiveTlvs`. The HMAC is used in `blinded_path::payment::PaymentContext`.
5151const PAYMENT_TLVS_HMAC_INPUT : & [ u8 ; 16 ] = & [ 8 ; 16 ] ;
5252
53+ // HMAC input used in `AsyncPaymentsContext::InboundPayment` to authenticate inbound
54+ // held_htlc_available onion messages.
55+ #[ cfg( async_payments) ]
56+ const ASYNC_PAYMENTS_HELD_HTLC_HMAC_INPUT : & [ u8 ; 16 ] = & [ 9 ; 16 ] ;
57+
5358/// Message metadata which possibly is derived from [`MetadataMaterial`] such that it can be
5459/// verified.
5560#[ derive( Clone ) ]
@@ -483,3 +488,16 @@ pub(crate) fn verify_payment_tlvs(
483488) -> Result < ( ) , ( ) > {
484489 if hmac_for_payment_tlvs ( receive_tlvs, nonce, expanded_key) == hmac { Ok ( ( ) ) } else { Err ( ( ) ) }
485490}
491+
492+ #[ cfg( async_payments) ]
493+ pub ( crate ) fn hmac_for_held_htlc_available_context (
494+ nonce : Nonce , expanded_key : & ExpandedKey ,
495+ ) -> Hmac < Sha256 > {
496+ const IV_BYTES : & [ u8 ; IV_LEN ] = b"LDK Held HTLC OM" ;
497+ let mut hmac = expanded_key. hmac_for_offer ( ) ;
498+ hmac. input ( IV_BYTES ) ;
499+ hmac. input ( & nonce. 0 ) ;
500+ hmac. input ( ASYNC_PAYMENTS_HELD_HTLC_HMAC_INPUT ) ;
501+
502+ Hmac :: from_engine ( hmac)
503+ }
You can’t perform that action at this time.
0 commit comments