@@ -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
} ;
@@ -1074,6 +1075,44 @@ where
1074
1075
msg. onion_routing_packet . hmac ,
1075
1076
( control_tlvs_ss, custom_handler. deref ( ) , logger. deref ( ) ) ,
1076
1077
) ;
1078
+
1079
+ // Constructs the next onion message using packet data and blinding logic.
1080
+ let compute_onion_message = |packet_pubkey : PublicKey ,
1081
+ next_hop_hmac : [ u8 ; 32 ] ,
1082
+ new_packet_bytes : Vec < u8 > ,
1083
+ blinding_point_opt : Option < PublicKey > |
1084
+ -> Result < OnionMessage , ( ) > {
1085
+ let new_pubkey =
1086
+ match onion_utils:: next_hop_pubkey ( & secp_ctx, packet_pubkey, & onion_decode_ss) {
1087
+ Ok ( pk) => pk,
1088
+ Err ( e) => {
1089
+ log_trace ! ( logger, "Failed to compute next hop packet pubkey: {}" , e) ;
1090
+ return Err ( ( ) ) ;
1091
+ } ,
1092
+ } ;
1093
+ let outgoing_packet = Packet {
1094
+ version : 0 ,
1095
+ public_key : new_pubkey,
1096
+ hop_data : new_packet_bytes,
1097
+ hmac : next_hop_hmac,
1098
+ } ;
1099
+ let blinding_point = match blinding_point_opt {
1100
+ Some ( bp) => bp,
1101
+ None => match onion_utils:: next_hop_pubkey (
1102
+ & secp_ctx,
1103
+ msg. blinding_point ,
1104
+ control_tlvs_ss. as_ref ( ) ,
1105
+ ) {
1106
+ Ok ( bp) => bp,
1107
+ Err ( e) => {
1108
+ log_trace ! ( logger, "Failed to compute next blinding point: {}" , e) ;
1109
+ return Err ( ( ) ) ;
1110
+ } ,
1111
+ } ,
1112
+ } ;
1113
+ Ok ( OnionMessage { blinding_point, onion_routing_packet : outgoing_packet } )
1114
+ } ;
1115
+
1077
1116
match next_hop {
1078
1117
Ok ( (
1079
1118
Payload :: Receive {
@@ -1115,54 +1154,34 @@ where
1115
1154
Err ( ( ) )
1116
1155
} ,
1117
1156
} ,
1157
+ Ok ( (
1158
+ Payload :: Dummy ( DummyControlTlvs :: Unblinded ( DummyTlv { dummy_tlv, authentication } ) ) ,
1159
+ Some ( ( next_hop_hmac, new_packet_bytes) ) ,
1160
+ ) ) => {
1161
+ let expanded_key = node_signer. get_expanded_key ( ) ;
1162
+ dummy_tlv. verify_data ( authentication. 0 , authentication. 1 , & expanded_key) ?;
1163
+
1164
+ let onion_message = compute_onion_message (
1165
+ msg. onion_routing_packet . public_key ,
1166
+ next_hop_hmac,
1167
+ new_packet_bytes,
1168
+ None ,
1169
+ ) ?;
1170
+ peel_onion_message ( & onion_message, secp_ctx, node_signer, logger, custom_handler)
1171
+ } ,
1118
1172
Ok ( (
1119
1173
Payload :: Forward ( ForwardControlTlvs :: Unblinded ( ForwardTlvs {
1120
1174
next_hop,
1121
1175
next_blinding_override,
1122
1176
} ) ) ,
1123
1177
Some ( ( next_hop_hmac, new_packet_bytes) ) ,
1124
1178
) ) => {
1125
- // TODO: we need to check whether `next_hop` is our node, in which case this is a dummy
1126
- // blinded hop and this onion message is destined for us. In this situation, we should keep
1127
- // unwrapping the onion layers to get to the final payload. Since we don't have the option
1128
- // of creating blinded paths with dummy hops currently, we should be ok to not handle this
1129
- // for now.
1130
- let packet_pubkey = msg. onion_routing_packet . public_key ;
1131
- let new_pubkey_opt =
1132
- onion_utils:: next_hop_pubkey ( & secp_ctx, packet_pubkey, & onion_decode_ss) ;
1133
- let new_pubkey = match new_pubkey_opt {
1134
- Ok ( pk) => pk,
1135
- Err ( e) => {
1136
- log_trace ! ( logger, "Failed to compute next hop packet pubkey: {}" , e) ;
1137
- return Err ( ( ) ) ;
1138
- } ,
1139
- } ;
1140
- let outgoing_packet = Packet {
1141
- version : 0 ,
1142
- public_key : new_pubkey,
1143
- hop_data : new_packet_bytes,
1144
- hmac : next_hop_hmac,
1145
- } ;
1146
- let onion_message = OnionMessage {
1147
- blinding_point : match next_blinding_override {
1148
- Some ( blinding_point) => blinding_point,
1149
- None => {
1150
- match onion_utils:: next_hop_pubkey (
1151
- & secp_ctx,
1152
- msg. blinding_point ,
1153
- control_tlvs_ss. as_ref ( ) ,
1154
- ) {
1155
- Ok ( bp) => bp,
1156
- Err ( e) => {
1157
- log_trace ! ( logger, "Failed to compute next blinding point: {}" , e) ;
1158
- return Err ( ( ) ) ;
1159
- } ,
1160
- }
1161
- } ,
1162
- } ,
1163
- onion_routing_packet : outgoing_packet,
1164
- } ;
1165
-
1179
+ let onion_message = compute_onion_message (
1180
+ msg. onion_routing_packet . public_key ,
1181
+ next_hop_hmac,
1182
+ new_packet_bytes,
1183
+ next_blinding_override,
1184
+ ) ?;
1166
1185
Ok ( PeeledOnion :: Forward ( next_hop, onion_message) )
1167
1186
} ,
1168
1187
Err ( e) => {
0 commit comments