Skip to content

Commit 5ede316

Browse files
committed
handle legacy failure at sender
1 parent ef41804 commit 5ede316

File tree

2 files changed

+46
-39
lines changed

2 files changed

+46
-39
lines changed

lightning/src/ln/onion_route_tests.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,16 @@ fn run_onion_failure_test_with_fail_intercept<F1,F2,F3>(
162162
commitment_signed_dance!(nodes[1], nodes[2], update_2_1.commitment_signed, true);
163163

164164
// backward fail on 1
165-
let update_1_0 = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
165+
let mut update_1_0 = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
166166
assert!(update_1_0.update_fail_htlcs.len() == 1);
167+
168+
// TEST DEBUG: Mutate attributable data.
169+
//
170+
// let mut data = update_1_0.update_fail_htlcs[0].attribution_data.as_mut().unwrap();
171+
// for i in 0..ATTRIBUTION_DATA_LEN {
172+
// data[i] = 1;
173+
// }
174+
167175
update_1_0
168176
},
169177
_ => unreachable!(),

lightning/src/ln/onion_utils.rs

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,55 +1088,54 @@ where
10881088

10891089
let um = gen_um_from_shared_secret(shared_secret.as_ref());
10901090

1091-
// Check attr error hmacs
1092-
1093-
let message = &encrypted_packet.data;
1094-
let payloads = &encrypted_packet.attribution_data.as_ref().unwrap()[..MAX_HOPS * PAYLOAD_LEN]; // XXX: This will break if we get an err from an unupgraded node
1095-
let hmacs = &encrypted_packet.attribution_data.as_ref().unwrap()[MAX_HOPS * PAYLOAD_LEN..]; // XXX: This will break if we get an err from an unupgraded node
1091+
// Check attr error hmacs if present.
1092+
if let Some(ref attribution_data) = encrypted_packet.attribution_data {
1093+
let message = &encrypted_packet.data;
1094+
let payloads = &attribution_data[..MAX_HOPS * PAYLOAD_LEN];
1095+
let hmacs = &attribution_data[MAX_HOPS * PAYLOAD_LEN..];
10961096

1097-
let um = gen_um_from_shared_secret(shared_secret.as_ref());
1098-
let mut hmac = HmacEngine::<Sha256>::new(&um);
1097+
let um = gen_um_from_shared_secret(shared_secret.as_ref());
1098+
let mut hmac = HmacEngine::<Sha256>::new(&um);
10991099

1100-
hmac.input(&message);
1101-
hmac.input(&payloads[..(MAX_HOPS - route_hop_idx) * PAYLOAD_LEN]);
1100+
hmac.input(&message);
1101+
hmac.input(&payloads[..(MAX_HOPS - route_hop_idx) * PAYLOAD_LEN]);
11021102

1103-
let position: usize = MAX_HOPS - route_hop_idx - 1;
1104-
write_downstream_hmacs(position, MAX_HOPS, hmacs, &mut hmac);
1103+
let position: usize = MAX_HOPS - route_hop_idx - 1;
1104+
write_downstream_hmacs(position, MAX_HOPS, hmacs, &mut hmac);
11051105

1106-
let actual_hmac = &hmacs[route_hop_idx * HMAC_LEN..route_hop_idx*HMAC_LEN+HMAC_LEN];
1107-
let expected_hmac= &Hmac::from_engine(hmac).to_byte_array()[..HMAC_LEN];
1106+
let actual_hmac = &hmacs[route_hop_idx * HMAC_LEN..route_hop_idx*HMAC_LEN+HMAC_LEN];
1107+
let expected_hmac= &Hmac::from_engine(hmac).to_byte_array()[..HMAC_LEN];
11081108

1109-
if !fixed_time_eq(expected_hmac, actual_hmac) {
1110-
res = Some(FailureLearnings {
1111-
network_update: None,
1112-
short_channel_id: Some(route_hop.short_channel_id),
1113-
payment_failed_permanently: false,
1114-
failed_within_blinded_path: false,
1115-
});
1109+
if !fixed_time_eq(expected_hmac, actual_hmac) {
1110+
res = Some(FailureLearnings {
1111+
network_update: None,
1112+
short_channel_id: Some(route_hop.short_channel_id),
1113+
payment_failed_permanently: false,
1114+
failed_within_blinded_path: false,
1115+
});
11161116

1117-
// log_debug!(logger, "Invalid HMAC in onion failure packet at pos {}", route_hop_idx);
1117+
log_debug!(logger, "Invalid HMAC in attributable data for node at pos {}", route_hop_idx);
11181118

1119-
return;
1120-
} else {
1121-
// log_debug!(logger, "Valid HMAC in onion failure packet at pos {}", route_hop_idx);
1122-
}
1119+
return;
1120+
}
11231121

1124-
// Shift payloads left.
1125-
let payloads = &mut encrypted_packet.attribution_data.as_mut().unwrap()[..MAX_HOPS * PAYLOAD_LEN]; // XXX: This will break if we get an err from an unupgraded node
1126-
payloads.copy_within(PAYLOAD_LEN.., 0);
1122+
// Shift payloads left.
1123+
let payloads = &mut encrypted_packet.attribution_data.as_mut().unwrap()[..MAX_HOPS * PAYLOAD_LEN]; // XXX: This will break if we get an err from an unupgraded node
1124+
payloads.copy_within(PAYLOAD_LEN.., 0);
11271125

1128-
// Shift hmacs left.
1129-
let hmacs = &mut encrypted_packet.attribution_data.as_mut().unwrap()[MAX_HOPS * PAYLOAD_LEN..]; // XXX: This will break if we get an err from an unupgraded node
1130-
let mut src_idx = MAX_HOPS;
1131-
let mut dest_idx = 1;
1132-
let mut copy_len = MAX_HOPS - 1;
1126+
// Shift hmacs left.
1127+
let hmacs = &mut encrypted_packet.attribution_data.as_mut().unwrap()[MAX_HOPS * PAYLOAD_LEN..]; // XXX: This will break if we get an err from an unupgraded node
1128+
let mut src_idx = MAX_HOPS;
1129+
let mut dest_idx = 1;
1130+
let mut copy_len = MAX_HOPS - 1;
11331131

1134-
for i in 0..MAX_HOPS - 1 {
1135-
hmacs.copy_within(src_idx * HMAC_LEN .. (src_idx + copy_len) * HMAC_LEN, dest_idx * HMAC_LEN);
1132+
for i in 0..MAX_HOPS - 1 {
1133+
hmacs.copy_within(src_idx * HMAC_LEN .. (src_idx + copy_len) * HMAC_LEN, dest_idx * HMAC_LEN);
11361134

1137-
src_idx += copy_len;
1138-
dest_idx += copy_len + 1;
1139-
copy_len -= 1;
1135+
src_idx += copy_len;
1136+
dest_idx += copy_len + 1;
1137+
copy_len -= 1;
1138+
}
11401139
}
11411140

11421141
// Process decrypt result

0 commit comments

Comments
 (0)