From: Matt Corallo Date: Wed, 29 Aug 2018 18:31:50 +0000 (-0400) Subject: Correct excess-data handling in ChannelAnnouncement verif in Router X-Git-Tag: v0.0.12~334^2~5 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=0881bf4b7460921eff425f0b4833b994922064a5;p=rust-lightning Correct excess-data handling in ChannelAnnouncement verif in Router --- diff --git a/src/ln/channel.rs b/src/ln/channel.rs index b59379aa7..f890f0396 100644 --- a/src/ln/channel.rs +++ b/src/ln/channel.rs @@ -2303,6 +2303,7 @@ impl Channel { node_id_2: if were_node_one { self.get_their_node_id() } else { our_node_id }, bitcoin_key_1: if were_node_one { our_bitcoin_key } else { self.their_funding_pubkey.unwrap() }, bitcoin_key_2: if were_node_one { self.their_funding_pubkey.unwrap() } else { our_bitcoin_key }, + excess_data: Vec::new(), }; let msghash = Message::from_slice(&Sha256dHash::from_data(&msg.encode()[..])[..]).unwrap(); diff --git a/src/ln/msgs.rs b/src/ln/msgs.rs index 6a005f528..00095cd15 100644 --- a/src/ln/msgs.rs +++ b/src/ln/msgs.rs @@ -352,6 +352,7 @@ pub struct UnsignedChannelAnnouncement { pub node_id_2: PublicKey, pub bitcoin_key_1: PublicKey, pub bitcoin_key_2: PublicKey, + pub excess_data: Vec, } #[derive(PartialEq, Clone)] pub struct ChannelAnnouncement { @@ -1369,6 +1370,8 @@ impl MsgDecodable for UnsignedChannelAnnouncement { } let start = features.encoded_len(); let secp_ctx = Secp256k1::without_caps(); + let mut excess_data = Vec::with_capacity(v.len() - start - 172); + excess_data.extend_from_slice(&v[start + 172..]); Ok(Self { features, chain_hash: deserialize(&v[start..start + 32]).unwrap(), @@ -1377,13 +1380,14 @@ impl MsgDecodable for UnsignedChannelAnnouncement { node_id_2: secp_pubkey!(&secp_ctx, &v[start + 73..start + 106]), bitcoin_key_1: secp_pubkey!(&secp_ctx, &v[start + 106..start + 139]), bitcoin_key_2: secp_pubkey!(&secp_ctx, &v[start + 139..start + 172]), + excess_data, }) } } impl MsgEncodable for UnsignedChannelAnnouncement { fn encode(&self) -> Vec { let features = self.features.encode(); - let mut res = Vec::with_capacity(172 + features.len()); + let mut res = Vec::with_capacity(172 + features.len() + self.excess_data.len()); res.extend_from_slice(&features[..]); res.extend_from_slice(&self.chain_hash[..]); res.extend_from_slice(&byte_utils::be64_to_array(self.short_channel_id)); @@ -1391,6 +1395,7 @@ impl MsgEncodable for UnsignedChannelAnnouncement { res.extend_from_slice(&self.node_id_2.serialize()); res.extend_from_slice(&self.bitcoin_key_1.serialize()); res.extend_from_slice(&self.bitcoin_key_2.serialize()); + res.extend_from_slice(&self.excess_data[..]); res } } diff --git a/src/ln/router.rs b/src/ln/router.rs index 1ca55fa26..1f713f69d 100644 --- a/src/ln/router.rs +++ b/src/ln/router.rs @@ -263,7 +263,7 @@ impl RoutingMessageHandler for Router { add_channel_to_node!(msg.contents.node_id_1); add_channel_to_node!(msg.contents.node_id_2); - Ok(!msg.contents.features.supports_unknown_bits()) + Ok(msg.contents.excess_data.is_empty() && !msg.contents.features.supports_unknown_bits()) } fn handle_htlc_fail_channel_update(&self, update: &msgs::HTLCFailChannelUpdate) {