@@ -1120,17 +1120,31 @@ where
1120
1120
} ,
1121
1121
} ,
1122
1122
Ok ( (
1123
- Payload :: Forward ( ForwardControlTlvs :: Unblinded ( ForwardTlvs {
1124
- next_hop,
1125
- next_blinding_override,
1126
- } ) ) ,
1123
+ Payload :: Forward {
1124
+ control_tlvs : ForwardControlTlvs :: Unblinded ( ForwardTlvs {
1125
+ next_hop,
1126
+ next_blinding_override,
1127
+ } ) ,
1128
+ control_tlvs_authenticated,
1129
+ } ,
1127
1130
Some ( ( next_hop_hmac, new_packet_bytes) ) ,
1128
1131
) ) => {
1129
1132
// TODO: we need to check whether `next_hop` is our node, in which case this is a dummy
1130
1133
// blinded hop and this onion message is destined for us. In this situation, we should keep
1131
1134
// unwrapping the onion layers to get to the final payload. Since we don't have the option
1132
1135
// of creating blinded paths with dummy hops currently, we should be ok to not handle this
1133
1136
// for now.
1137
+ if control_tlvs_authenticated {
1138
+ // TODO: When we start adding dummy hops, we should require the use of
1139
+ // authenticated control TLVs, as it prevents a DoS attack where someone builds a
1140
+ // blinded path to us which requires we decode hundreds of dummy hops only to find
1141
+ // that we don't actually have a message inside to read.
1142
+ // However, we should never accept a `control_tlvs_authenticated` packet which is
1143
+ // *not* a dummy blinded hop we added, though it shouldn't be possible to reach in
1144
+ // any case.
1145
+ log_trace ! ( logger, "Received an authenticated to-forward onion message" ) ;
1146
+ return Err ( ( ) )
1147
+ }
1134
1148
let packet_pubkey = msg. onion_routing_packet . public_key ;
1135
1149
let new_pubkey_opt =
1136
1150
onion_utils:: next_hop_pubkey ( & secp_ctx, packet_pubkey, & onion_decode_ss) ;
@@ -2251,10 +2265,13 @@ fn packet_payloads_and_keys<
2251
2265
if num_unblinded_hops != 0 && unblinded_path_idx < num_unblinded_hops {
2252
2266
if let Some ( ss) = prev_control_tlvs_ss. take ( ) {
2253
2267
payloads. push ( (
2254
- Payload :: Forward ( ForwardControlTlvs :: Unblinded ( ForwardTlvs {
2255
- next_hop : NextMessageHop :: NodeId ( unblinded_pk_opt. unwrap ( ) ) ,
2256
- next_blinding_override : None ,
2257
- } ) ) ,
2268
+ Payload :: Forward {
2269
+ control_tlvs : ForwardControlTlvs :: Unblinded ( ForwardTlvs {
2270
+ next_hop : NextMessageHop :: NodeId ( unblinded_pk_opt. unwrap ( ) ) ,
2271
+ next_blinding_override : None ,
2272
+ } ) ,
2273
+ control_tlvs_authenticated : false ,
2274
+ } ,
2258
2275
ss,
2259
2276
) ) ;
2260
2277
}
@@ -2263,17 +2280,23 @@ fn packet_payloads_and_keys<
2263
2280
} else if let Some ( ( intro_node_id, blinding_pt) ) = intro_node_id_blinding_pt. take ( ) {
2264
2281
if let Some ( control_tlvs_ss) = prev_control_tlvs_ss. take ( ) {
2265
2282
payloads. push ( (
2266
- Payload :: Forward ( ForwardControlTlvs :: Unblinded ( ForwardTlvs {
2267
- next_hop : NextMessageHop :: NodeId ( intro_node_id) ,
2268
- next_blinding_override : Some ( blinding_pt) ,
2269
- } ) ) ,
2283
+ Payload :: Forward {
2284
+ control_tlvs : ForwardControlTlvs :: Unblinded ( ForwardTlvs {
2285
+ next_hop : NextMessageHop :: NodeId ( intro_node_id) ,
2286
+ next_blinding_override : Some ( blinding_pt) ,
2287
+ } ) ,
2288
+ control_tlvs_authenticated : false ,
2289
+ } ,
2270
2290
control_tlvs_ss,
2271
2291
) ) ;
2272
2292
}
2273
2293
}
2274
2294
if blinded_path_idx < num_blinded_hops. saturating_sub ( 1 ) && enc_payload_opt. is_some ( ) {
2275
2295
payloads. push ( (
2276
- Payload :: Forward ( ForwardControlTlvs :: Blinded ( enc_payload_opt. unwrap ( ) ) ) ,
2296
+ Payload :: Forward {
2297
+ control_tlvs : ForwardControlTlvs :: Blinded ( enc_payload_opt. unwrap ( ) ) ,
2298
+ control_tlvs_authenticated : false ,
2299
+ } ,
2277
2300
control_tlvs_ss,
2278
2301
) ) ;
2279
2302
blinded_path_idx += 1 ;
0 commit comments