Skip to content

Commit cbeff7e

Browse files
author
Antoine Riard
committed
Implement KeyError for bad key in channel announcement process
1 parent 6919cd3 commit cbeff7e

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

fuzz/fuzz_targets/channel_target.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ pub fn do_test(data: &[u8]) {
249249
Some(ErrorAction::DisconnectPeer {..}) => return,
250250
Some(ErrorAction::IgnoreError) => None,
251251
Some(ErrorAction::SendErrorMessage {..}) => None,
252+
Some(ErrorAction::KeyError) => None,
252253
},
253254
}
254255
}

src/ln/channelmanager.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ macro_rules! secp_call {
175175
match $res {
176176
Ok(key) => key,
177177
//TODO: Make the err a parameter!
178-
Err(_) => return Err(HandleError{err: "Key error", action: None})
178+
Err(_) => return Err(HandleError{err: "Key error", action: Some(msgs::ErrorAction::KeyError)}),
179179
}
180180
};
181181
}
@@ -1145,9 +1145,18 @@ impl ChainListener for ChannelManager {
11451145
if let Ok(Some(funding_locked)) = chan_res {
11461146
let announcement_sigs = match self.get_announcement_sigs(channel) {
11471147
Ok(res) => res,
1148-
Err(_e) => {
1149-
//TODO: push e on events and blow up the channel (it has bad keys)
1150-
return true;
1148+
Err(e) => {
1149+
if e.action.is_some() {
1150+
new_events.push(events::Event::DisconnectPeer {
1151+
node_id: channel.get_their_node_id(),
1152+
msg: None,
1153+
});
1154+
failed_channels.push(channel.force_shutdown());
1155+
short_to_id.remove(&channel.get_short_channel_id().unwrap());
1156+
return false;
1157+
} else {
1158+
return true;
1159+
}
11511160
}
11521161
};
11531162
new_events.push(events::Event::SendFundingLocked {
@@ -3106,4 +3115,5 @@ mod tests {
31063115
assert_eq!(channel_state.by_id.len(), 0);
31073116
assert_eq!(channel_state.short_to_id.len(), 0);
31083117
}
3118+
31093119
}

src/ln/msgs.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,8 @@ pub enum ErrorAction {
391391
SendErrorMessage {
392392
msg: ErrorMessage
393393
},
394+
/// The peer send us invalid keys for a given action. Disconnect them or tell them. Your call.
395+
KeyError,
394396
}
395397

396398
pub struct HandleError { //TODO: rename me

src/ln/peer_handler.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
312312
encode_and_send_msg!(msg, 17);
313313
continue;
314314
},
315+
msgs::ErrorAction::KeyError => {
316+
continue; //TODO : return a PeerHandleError and disconnect socket ?
317+
}
315318
}
316319
} else {
317320
return Err(PeerHandleError{ no_connection_possible: false });

0 commit comments

Comments
 (0)