From: Valentine Wallace Date: Mon, 8 May 2023 18:23:56 +0000 (-0400) Subject: Fix onion messages of size BIG_PACKET_HOP_DATA_LEN X-Git-Tag: v0.0.116-alpha1~46^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=f18661f6f6c51e67c4eac1443a50f4be72356386;p=rust-lightning Fix onion messages of size BIG_PACKET_HOP_DATA_LEN This was previously broken and would result in an invalid HMAC error, because we had a hardcoded assumption that OM hop data would always be of size 1300. --- diff --git a/lightning/src/ln/onion_utils.rs b/lightning/src/ln/onion_utils.rs index ebcf83bd9..b7759d26f 100644 --- a/lightning/src/ln/onion_utils.rs +++ b/lightning/src/ln/onion_utils.rs @@ -324,7 +324,8 @@ fn construct_onion_packet_with_init_noise( chacha.process_in_place(packet_data); if i == 0 { - packet_data[ONION_DATA_LEN - filler.len()..ONION_DATA_LEN].copy_from_slice(&filler[..]); + let onion_data_len = packet_data.len(); + packet_data[onion_data_len - filler.len()..onion_data_len].copy_from_slice(&filler[..]); } let mut hmac = HmacEngine::::new(&keys.mu); diff --git a/lightning/src/onion_message/functional_tests.rs b/lightning/src/onion_message/functional_tests.rs index e7cf4e87d..98fcdb680 100644 --- a/lightning/src/onion_message/functional_tests.rs +++ b/lightning/src/onion_message/functional_tests.rs @@ -284,3 +284,20 @@ fn peer_buffer_full() { let err = nodes[0].messenger.send_onion_message(&[], Destination::Node(nodes[1].get_node_pk()), OnionMessageContents::Custom(test_msg), None).unwrap_err(); assert_eq!(err, SendError::BufferFull); } + +#[test] +fn many_hops() { + // Check we can send over a route with many hops. This will exercise our logic for onion messages + // of size [`crate::onion_message::packet::BIG_PACKET_HOP_DATA_LEN`]. + let num_nodes: usize = 25; + let nodes = create_nodes(num_nodes as u8); + let test_msg = OnionMessageContents::Custom(TestCustomMessage {}); + + let mut intermediates = vec![]; + for i in 1..(num_nodes-1) { + intermediates.push(nodes[i].get_node_pk()); + } + + nodes[0].messenger.send_onion_message(&intermediates, Destination::Node(nodes[num_nodes-1].get_node_pk()), test_msg, None).unwrap(); + pass_along_path(&nodes); +} diff --git a/pending_changelog/big-om-error.txt b/pending_changelog/big-om-error.txt new file mode 100644 index 000000000..6f2ce899e --- /dev/null +++ b/pending_changelog/big-om-error.txt @@ -0,0 +1,4 @@ +## Bug Fixes + +* Fixed sending large onion messages, which previously would result in an HMAC error on the second + hop (#2277).