X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=fuzz%2Fsrc%2Fonion_message.rs;h=a86734d4575a6fb7f4c65ea74a2844e9b3d60bca;hb=ce6bcf68a15331c082b34d09902241583bc6ff71;hp=b1f8fc33637f948cc0a6cf1c8b30ccfeaa45a0a1;hpb=4a0010d7393bb32305bdb3d859735b7b563462eb;p=rust-lightning diff --git a/fuzz/src/onion_message.rs b/fuzz/src/onion_message.rs index b1f8fc33..a86734d4 100644 --- a/fuzz/src/onion_message.rs +++ b/fuzz/src/onion_message.rs @@ -1,11 +1,11 @@ // Imports that need to be added manually use bitcoin::bech32::u5; use bitcoin::blockdata::script::Script; -use bitcoin::secp256k1::{PublicKey, Scalar, SecretKey}; +use bitcoin::secp256k1::{PublicKey, Scalar, Secp256k1, SecretKey}; use bitcoin::secp256k1::ecdh::SharedSecret; use bitcoin::secp256k1::ecdsa::RecoverableSignature; -use lightning::chain::keysinterface::{Recipient, KeyMaterial, KeysInterface}; +use lightning::chain::keysinterface::{Recipient, KeyMaterial, EntropySource, NodeSigner, SignerProvider}; use lightning::ln::msgs::{self, DecodeError, OnionMessageHandler}; use lightning::ln::script::ShutdownScript; use lightning::util::enforcing_trait_impls::EnforcingSigner; @@ -30,7 +30,7 @@ pub fn do_test(data: &[u8], logger: &L) { counter: AtomicU64::new(0), }; let custom_msg_handler = TestCustomMessageHandler {}; - let onion_messenger = OnionMessenger::new(&keys_manager, logger, &custom_msg_handler); + let onion_messenger = OnionMessenger::new(&keys_manager, &keys_manager, logger, &custom_msg_handler); let mut pk = [2; 33]; pk[1] = 0xff; let peer_node_id_not_used = PublicKey::from_slice(&pk).unwrap(); onion_messenger.handle_onion_message(&peer_node_id_not_used, &msg); @@ -90,13 +90,25 @@ struct KeyProvider { node_secret: SecretKey, counter: AtomicU64, } -impl KeysInterface for KeyProvider { - type Signer = EnforcingSigner; +impl EntropySource for KeyProvider { + fn get_secure_random_bytes(&self) -> [u8; 32] { + let ctr = self.counter.fetch_add(1, Ordering::Relaxed); + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + (ctr >> 8*7) as u8, (ctr >> 8*6) as u8, (ctr >> 8*5) as u8, (ctr >> 8*4) as u8, (ctr >> 8*3) as u8, (ctr >> 8*2) as u8, (ctr >> 8*1) as u8, 14, (ctr >> 8*0) as u8] + } +} + +impl NodeSigner for KeyProvider { fn get_node_secret(&self, _recipient: Recipient) -> Result { Ok(self.node_secret.clone()) } + fn get_node_id(&self, recipient: Recipient) -> Result { + let secp_ctx = Secp256k1::signing_only(); + Ok(PublicKey::from_secret_key(&secp_ctx, &self.get_node_secret(recipient)?)) + } + fn ecdh(&self, recipient: Recipient, other_key: &PublicKey, tweak: Option<&Scalar>) -> Result { let mut node_secret = self.get_node_secret(recipient)?; if let Some(tweak) = tweak { @@ -107,9 +119,13 @@ impl KeysInterface for KeyProvider { fn get_inbound_payment_key_material(&self) -> KeyMaterial { unreachable!() } - fn get_destination_script(&self) -> Script { unreachable!() } + fn sign_invoice(&self, _hrp_bytes: &[u8], _invoice_data: &[u5], _recipient: Recipient) -> Result { + unreachable!() + } +} - fn get_shutdown_scriptpubkey(&self) -> ShutdownScript { unreachable!() } +impl SignerProvider for KeyProvider { + type Signer = EnforcingSigner; fn generate_channel_keys_id(&self, _inbound: bool, _channel_value_satoshis: u64, _user_channel_id: u128) -> [u8; 32] { unreachable!() } @@ -117,17 +133,11 @@ impl KeysInterface for KeyProvider { unreachable!() } - fn get_secure_random_bytes(&self) -> [u8; 32] { - let ctr = self.counter.fetch_add(1, Ordering::Relaxed); - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - (ctr >> 8*7) as u8, (ctr >> 8*6) as u8, (ctr >> 8*5) as u8, (ctr >> 8*4) as u8, (ctr >> 8*3) as u8, (ctr >> 8*2) as u8, (ctr >> 8*1) as u8, 14, (ctr >> 8*0) as u8] - } - fn read_chan_signer(&self, _data: &[u8]) -> Result { unreachable!() } - fn sign_invoice(&self, _hrp_bytes: &[u8], _invoice_data: &[u5], _recipient: Recipient) -> Result { - unreachable!() - } + fn get_destination_script(&self) -> Script { unreachable!() } + + fn get_shutdown_scriptpubkey(&self) -> ShutdownScript { unreachable!() } } #[cfg(test)]