Skip to content

Commit 04c5f2b

Browse files
committed
Introduce parsing logic for DummyTlvs
1 parent 5d24087 commit 04c5f2b

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

lightning/src/onion_message/messenger.rs

+42-7
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,20 @@ use super::async_payments::AsyncPaymentsMessage;
2020
use super::async_payments::AsyncPaymentsMessageHandler;
2121
use super::dns_resolution::{DNSResolverMessage, DNSResolverMessageHandler};
2222
use super::offers::OffersMessageHandler;
23-
use super::packet::OnionMessageContents;
2423
use super::packet::ParsedOnionMessageContents;
24+
use super::packet::{DummyControlTlvs, OnionMessageContents};
2525
use super::packet::{
2626
ForwardControlTlvs, Packet, Payload, ReceiveControlTlvs, BIG_PACKET_HOP_DATA_LEN,
2727
SMALL_PACKET_HOP_DATA_LEN,
2828
};
2929
use crate::blinded_path::message::{
30-
BlindedMessagePath, ForwardTlvs, MessageContext, MessageForwardNode, NextMessageHop,
30+
BlindedMessagePath, DummyTlvs, ForwardTlvs, MessageContext, MessageForwardNode, NextMessageHop,
3131
ReceiveTlvs,
3232
};
3333
use crate::blinded_path::utils;
3434
use crate::blinded_path::{IntroductionNode, NodeIdLookUp};
3535
use crate::events::{Event, EventHandler, EventsProvider, ReplayEvent};
36+
use crate::ln::channelmanager::Verification;
3637
use crate::ln::msgs::{
3738
self, BaseMessageHandler, MessageSendEvent, OnionMessage, OnionMessageHandler, SocketAddress,
3839
};
@@ -1122,18 +1123,52 @@ where
11221123
Err(())
11231124
},
11241125
},
1126+
Ok((
1127+
Payload::Dummy(DummyControlTlvs::Unblinded(DummyTlvs { dummy_tlvs, authentication })),
1128+
Some((next_hop_hmac, new_packet_bytes)),
1129+
)) => {
1130+
let expanded_key = node_signer.get_inbound_payment_key();
1131+
dummy_tlvs.verify_data(authentication.0, authentication.1, &expanded_key)?;
1132+
1133+
let packet_pubkey = msg.onion_routing_packet.public_key;
1134+
let new_pubkey_opt =
1135+
onion_utils::next_hop_pubkey(&secp_ctx, packet_pubkey, &onion_decode_ss);
1136+
let new_pubkey = match new_pubkey_opt {
1137+
Ok(pk) => pk,
1138+
Err(e) => {
1139+
log_trace!(logger, "Failed to compute next hop packet pubkey: {}", e);
1140+
return Err(());
1141+
},
1142+
};
1143+
let outgoing_packet = Packet {
1144+
version: 0,
1145+
public_key: new_pubkey,
1146+
hop_data: new_packet_bytes,
1147+
hmac: next_hop_hmac,
1148+
};
1149+
let onion_message = OnionMessage {
1150+
blinding_point: 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+
onion_routing_packet: outgoing_packet,
1162+
};
1163+
peel_onion_message(&onion_message, secp_ctx, node_signer, logger, custom_handler)
1164+
},
11251165
Ok((
11261166
Payload::Forward(ForwardControlTlvs::Unblinded(ForwardTlvs {
11271167
next_hop,
11281168
next_blinding_override,
11291169
})),
11301170
Some((next_hop_hmac, new_packet_bytes)),
11311171
)) => {
1132-
// TODO: we need to check whether `next_hop` is our node, in which case this is a dummy
1133-
// blinded hop and this onion message is destined for us. In this situation, we should keep
1134-
// unwrapping the onion layers to get to the final payload. Since we don't have the option
1135-
// of creating blinded paths with dummy hops currently, we should be ok to not handle this
1136-
// for now.
11371172
let packet_pubkey = msg.onion_routing_packet.public_key;
11381173
let new_pubkey_opt =
11391174
onion_utils::next_hop_pubkey(&secp_ctx, packet_pubkey, &onion_decode_ss);

0 commit comments

Comments
 (0)