@@ -20,21 +20,22 @@ use super::async_payments::AsyncPaymentsMessage;
2020use super :: async_payments:: AsyncPaymentsMessageHandler ;
2121use super :: dns_resolution:: { DNSResolverMessage , DNSResolverMessageHandler } ;
2222use super :: offers:: { OffersMessage , OffersMessageHandler } ;
23- use super :: packet:: OnionMessageContents ;
2423use super :: packet:: ParsedOnionMessageContents ;
24+ use super :: packet:: { DummyControlTlvs , OnionMessageContents } ;
2525use super :: packet:: {
2626 ForwardControlTlvs , Packet , Payload , ReceiveControlTlvs , BIG_PACKET_HOP_DATA_LEN ,
2727 SMALL_PACKET_HOP_DATA_LEN ,
2828} ;
2929#[ cfg( async_payments) ]
3030use crate :: blinded_path:: message:: AsyncPaymentsContext ;
3131use crate :: blinded_path:: message:: {
32- BlindedMessagePath , DNSResolverContext , ForwardTlvs , MessageContext , MessageForwardNode ,
33- NextMessageHop , OffersContext , ReceiveTlvs ,
32+ BlindedMessagePath , DNSResolverContext , DummyTlv , ForwardTlvs , MessageContext ,
33+ MessageForwardNode , NextMessageHop , OffersContext , ReceiveTlvs ,
3434} ;
3535use crate :: blinded_path:: utils;
3636use crate :: blinded_path:: { IntroductionNode , NodeIdLookUp } ;
3737use crate :: events:: { Event , EventHandler , EventsProvider , ReplayEvent } ;
38+ use crate :: ln:: channelmanager:: Verification ;
3839use crate :: ln:: msgs:: {
3940 self , BaseMessageHandler , MessageSendEvent , OnionMessage , OnionMessageHandler , SocketAddress ,
4041} ;
@@ -1099,6 +1100,44 @@ where
10991100 msg. onion_routing_packet . hmac ,
11001101 ( control_tlvs_ss, custom_handler. deref ( ) , logger. deref ( ) ) ,
11011102 ) ;
1103+
1104+ // Constructs the next onion message using packet data and blinding logic.
1105+ let compute_onion_message = |packet_pubkey : PublicKey ,
1106+ next_hop_hmac : [ u8 ; 32 ] ,
1107+ new_packet_bytes : Vec < u8 > ,
1108+ blinding_point_opt : Option < PublicKey > |
1109+ -> Result < OnionMessage , ( ) > {
1110+ let new_pubkey =
1111+ match onion_utils:: next_hop_pubkey ( & secp_ctx, packet_pubkey, & onion_decode_ss) {
1112+ Ok ( pk) => pk,
1113+ Err ( e) => {
1114+ log_trace ! ( logger, "Failed to compute next hop packet pubkey: {}" , e) ;
1115+ return Err ( ( ) ) ;
1116+ } ,
1117+ } ;
1118+ let outgoing_packet = Packet {
1119+ version : 0 ,
1120+ public_key : new_pubkey,
1121+ hop_data : new_packet_bytes,
1122+ hmac : next_hop_hmac,
1123+ } ;
1124+ let blinding_point = match blinding_point_opt {
1125+ Some ( bp) => bp,
1126+ None => match onion_utils:: next_hop_pubkey (
1127+ & secp_ctx,
1128+ msg. blinding_point ,
1129+ control_tlvs_ss. as_ref ( ) ,
1130+ ) {
1131+ Ok ( bp) => bp,
1132+ Err ( e) => {
1133+ log_trace ! ( logger, "Failed to compute next blinding point: {}" , e) ;
1134+ return Err ( ( ) ) ;
1135+ } ,
1136+ } ,
1137+ } ;
1138+ Ok ( OnionMessage { blinding_point, onion_routing_packet : outgoing_packet } )
1139+ } ;
1140+
11021141 match next_hop {
11031142 Ok ( (
11041143 Payload :: Receive {
@@ -1140,54 +1179,34 @@ where
11401179 Err ( ( ) )
11411180 } ,
11421181 } ,
1182+ Ok ( (
1183+ Payload :: Dummy ( DummyControlTlvs :: Unblinded ( DummyTlv { dummy_tlv, authentication } ) ) ,
1184+ Some ( ( next_hop_hmac, new_packet_bytes) ) ,
1185+ ) ) => {
1186+ let expanded_key = node_signer. get_inbound_payment_key ( ) ;
1187+ dummy_tlv. verify_data ( authentication. 0 , authentication. 1 , & expanded_key) ?;
1188+
1189+ let onion_message = compute_onion_message (
1190+ msg. onion_routing_packet . public_key ,
1191+ next_hop_hmac,
1192+ new_packet_bytes,
1193+ None ,
1194+ ) ?;
1195+ peel_onion_message ( & onion_message, secp_ctx, node_signer, logger, custom_handler)
1196+ } ,
11431197 Ok ( (
11441198 Payload :: Forward ( ForwardControlTlvs :: Unblinded ( ForwardTlvs {
11451199 next_hop,
11461200 next_blinding_override,
11471201 } ) ) ,
11481202 Some ( ( next_hop_hmac, new_packet_bytes) ) ,
11491203 ) ) => {
1150- // TODO: we need to check whether `next_hop` is our node, in which case this is a dummy
1151- // blinded hop and this onion message is destined for us. In this situation, we should keep
1152- // unwrapping the onion layers to get to the final payload. Since we don't have the option
1153- // of creating blinded paths with dummy hops currently, we should be ok to not handle this
1154- // for now.
1155- let packet_pubkey = msg. onion_routing_packet . public_key ;
1156- let new_pubkey_opt =
1157- onion_utils:: next_hop_pubkey ( & secp_ctx, packet_pubkey, & onion_decode_ss) ;
1158- let new_pubkey = match new_pubkey_opt {
1159- Ok ( pk) => pk,
1160- Err ( e) => {
1161- log_trace ! ( logger, "Failed to compute next hop packet pubkey: {}" , e) ;
1162- return Err ( ( ) ) ;
1163- } ,
1164- } ;
1165- let outgoing_packet = Packet {
1166- version : 0 ,
1167- public_key : new_pubkey,
1168- hop_data : new_packet_bytes,
1169- hmac : next_hop_hmac,
1170- } ;
1171- let onion_message = OnionMessage {
1172- blinding_point : match next_blinding_override {
1173- Some ( blinding_point) => blinding_point,
1174- None => {
1175- match onion_utils:: next_hop_pubkey (
1176- & secp_ctx,
1177- msg. blinding_point ,
1178- control_tlvs_ss. as_ref ( ) ,
1179- ) {
1180- Ok ( bp) => bp,
1181- Err ( e) => {
1182- log_trace ! ( logger, "Failed to compute next blinding point: {}" , e) ;
1183- return Err ( ( ) ) ;
1184- } ,
1185- }
1186- } ,
1187- } ,
1188- onion_routing_packet : outgoing_packet,
1189- } ;
1190-
1204+ let onion_message = compute_onion_message (
1205+ msg. onion_routing_packet . public_key ,
1206+ next_hop_hmac,
1207+ new_packet_bytes,
1208+ next_blinding_override,
1209+ ) ?;
11911210 Ok ( PeeledOnion :: Forward ( next_hop, onion_message) )
11921211 } ,
11931212 Err ( e) => {
0 commit comments