]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Correct excess-data handling in ChannelAnnouncement verif in Router
authorMatt Corallo <git@bluematt.me>
Wed, 29 Aug 2018 18:31:50 +0000 (14:31 -0400)
committerMatt Corallo <git@bluematt.me>
Wed, 29 Aug 2018 21:59:25 +0000 (17:59 -0400)
src/ln/channel.rs
src/ln/msgs.rs
src/ln/router.rs

index b59379aa74fdbab50589ad9ba424a17fab916ab4..f890f03968903b137b99e34db09f6f4e4f4890ee 100644 (file)
@@ -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();
index 6a005f528c45773bdc20e1edc4e2d599ee829d65..00095cd15ab2ea2badc9941e7b7f84453b9b0be5 100644 (file)
@@ -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<u8>,
 }
 #[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<u8> {
                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
        }
 }
index 1ca55fa260004c25e2cfafbe3856f1923257220a..1f713f69de8287fd298776179c51c3f4389e69be 100644 (file)
@@ -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) {