@@ -20,21 +20,22 @@ use super::async_payments::AsyncPaymentsMessage;
20
20
use super :: async_payments:: AsyncPaymentsMessageHandler ;
21
21
use super :: dns_resolution:: { DNSResolverMessage , DNSResolverMessageHandler } ;
22
22
use super :: offers:: { OffersMessage , OffersMessageHandler } ;
23
- use super :: packet:: OnionMessageContents ;
24
23
use super :: packet:: ParsedOnionMessageContents ;
24
+ use super :: packet:: { DummyControlTlvs , OnionMessageContents } ;
25
25
use super :: packet:: {
26
26
ForwardControlTlvs , Packet , Payload , ReceiveControlTlvs , BIG_PACKET_HOP_DATA_LEN ,
27
27
SMALL_PACKET_HOP_DATA_LEN ,
28
28
} ;
29
29
#[ cfg( async_payments) ]
30
30
use crate :: blinded_path:: message:: AsyncPaymentsContext ;
31
31
use 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 ,
34
34
} ;
35
35
use crate :: blinded_path:: utils;
36
36
use crate :: blinded_path:: { IntroductionNode , NodeIdLookUp } ;
37
37
use crate :: events:: { Event , EventHandler , EventsProvider , ReplayEvent } ;
38
+ use crate :: ln:: channelmanager:: Verification ;
38
39
use crate :: ln:: msgs:: {
39
40
self , BaseMessageHandler , MessageSendEvent , OnionMessage , OnionMessageHandler , SocketAddress ,
40
41
} ;
@@ -1099,6 +1100,44 @@ where
1099
1100
msg. onion_routing_packet . hmac ,
1100
1101
( control_tlvs_ss, custom_handler. deref ( ) , logger. deref ( ) ) ,
1101
1102
) ;
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
+
1102
1141
match next_hop {
1103
1142
Ok ( (
1104
1143
Payload :: Receive {
@@ -1140,54 +1179,34 @@ where
1140
1179
Err ( ( ) )
1141
1180
} ,
1142
1181
} ,
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
+ } ,
1143
1197
Ok ( (
1144
1198
Payload :: Forward ( ForwardControlTlvs :: Unblinded ( ForwardTlvs {
1145
1199
next_hop,
1146
1200
next_blinding_override,
1147
1201
} ) ) ,
1148
1202
Some ( ( next_hop_hmac, new_packet_bytes) ) ,
1149
1203
) ) => {
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
+ ) ?;
1191
1210
Ok ( PeeledOnion :: Forward ( next_hop, onion_message) )
1192
1211
} ,
1193
1212
Err ( e) => {
0 commit comments