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.
This commit is contained in:
Valentine Wallace 2023-05-08 14:23:56 -04:00
parent 408b12f034
commit f18661f6f6
No known key found for this signature in database
GPG key ID: FD3E106A2CE099B4
3 changed files with 23 additions and 1 deletions

View file

@ -324,7 +324,8 @@ fn construct_onion_packet_with_init_noise<HD: Writeable, P: Packet>(
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::<Sha256>::new(&keys.mu);

View file

@ -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);
}

View file

@ -0,0 +1,4 @@
## Bug Fixes
* Fixed sending large onion messages, which previously would result in an HMAC error on the second
hop (#2277).