+
+ run_onion_failure_test_with_fail_intercept("bogus err packet with valid hmac", 200, &nodes,
+ &route, &payment_hash, &payment_secret, |_msg| {}, |msg| {
+ let session_priv = SecretKey::from_slice(&[3; 32]).unwrap();
+ let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap();
+ let mut decoded_err_packet = msgs::DecodedOnionErrorPacket {
+ failuremsg: vec![0],
+ pad: vec![0; 255],
+ hmac: [0; 32],
+ };
+ let um = onion_utils::gen_um_from_shared_secret(&onion_keys[1].shared_secret.as_ref());
+ let mut hmac = HmacEngine::<Sha256>::new(&um);
+ hmac.input(&decoded_err_packet.encode()[32..]);
+ decoded_err_packet.hmac = Hmac::from_engine(hmac).into_inner();
+ msg.reason = onion_utils::encrypt_failure_packet(
+ &onion_keys[1].shared_secret.as_ref(), &decoded_err_packet.encode()[..])
+ }, || nodes[2].node.fail_htlc_backwards(&payment_hash), false, None,
+ Some(NetworkUpdate::NodeFailure { node_id: route.paths[0].hops[1].pubkey, is_permanent: true }),
+ Some(channels[1].0.contents.short_channel_id));
+ run_onion_failure_test_with_fail_intercept("0-length channel update in UPDATE onion failure", 200, &nodes,
+ &route, &payment_hash, &payment_secret, |_msg| {}, |msg| {
+ let session_priv = SecretKey::from_slice(&[3; 32]).unwrap();
+ let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap();
+ let mut decoded_err_packet = msgs::DecodedOnionErrorPacket {
+ failuremsg: vec![
+ 0x10, 0x7, // UPDATE|7
+ 0x0, 0x0 // 0-len channel update
+ ],
+ pad: vec![0; 255 - 4 /* 4-byte error message */],
+ hmac: [0; 32],
+ };
+ let um = onion_utils::gen_um_from_shared_secret(&onion_keys[1].shared_secret.as_ref());
+ let mut hmac = HmacEngine::<Sha256>::new(&um);
+ hmac.input(&decoded_err_packet.encode()[32..]);
+ decoded_err_packet.hmac = Hmac::from_engine(hmac).into_inner();
+ msg.reason = onion_utils::encrypt_failure_packet(
+ &onion_keys[1].shared_secret.as_ref(), &decoded_err_packet.encode()[..])
+ }, || nodes[2].node.fail_htlc_backwards(&payment_hash), true, Some(0x1000|7),
+ Some(NetworkUpdate::ChannelFailure {
+ short_channel_id: channels[1].0.contents.short_channel_id,
+ is_permanent: false,
+ }),
+ Some(channels[1].0.contents.short_channel_id));
+}
+
+#[test]
+fn test_overshoot_final_cltv() {
+ let chanmon_cfgs = create_chanmon_cfgs(3);
+ let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
+ let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None; 3]);
+ let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs);
+ create_announced_chan_between_nodes(&nodes, 0, 1);
+ create_announced_chan_between_nodes(&nodes, 1, 2);
+ let (route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], 40000);
+
+ let payment_id = PaymentId(nodes[0].keys_manager.backing.get_secure_random_bytes());
+ nodes[0].node.send_payment_with_route(&route, payment_hash, RecipientOnionFields::secret_only(payment_secret), payment_id).unwrap();
+
+ check_added_monitors!(nodes[0], 1);
+ let update_0 = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id());
+ let mut update_add_0 = update_0.update_add_htlcs[0].clone();
+ nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &update_add_0);
+ commitment_signed_dance!(nodes[1], nodes[0], &update_0.commitment_signed, false, true);
+
+ assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
+ for (_, pending_forwards) in nodes[1].node.forward_htlcs.lock().unwrap().iter_mut() {
+ for f in pending_forwards.iter_mut() {
+ match f {
+ &mut HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo { ref mut forward_info, .. }) =>
+ forward_info.outgoing_cltv_value += 1,
+ _ => {},
+ }
+ }
+ }
+ expect_pending_htlcs_forwardable!(nodes[1]);
+
+ check_added_monitors!(&nodes[1], 1);
+ let update_1 = get_htlc_update_msgs!(nodes[1], nodes[2].node.get_our_node_id());
+ let mut update_add_1 = update_1.update_add_htlcs[0].clone();
+ nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &update_add_1);
+ commitment_signed_dance!(nodes[2], nodes[1], update_1.commitment_signed, false, true);
+
+ expect_pending_htlcs_forwardable!(nodes[2]);
+ expect_payment_claimable!(nodes[2], payment_hash, payment_secret, 40_000);
+ claim_payment(&nodes[0], &[&nodes[1], &nodes[2]], payment_preimage);