Skip to content

Commit 4048c12

Browse files
Add get_inbound_payment_secret to KeysInterface
This will allow us to retrieve a key for encrypting/decrypting inbound payment info, in upcoming commits
1 parent ba50dd5 commit 4048c12

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ impl KeysInterface for KeyProvider {
164164
SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, self.node_id]).unwrap()
165165
}
166166

167+
fn get_inbound_payment_secret(&self) -> SecretKey {
168+
SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, self.node_id]).unwrap()
169+
}
170+
167171
fn get_destination_script(&self) -> Script {
168172
let secp_ctx = Secp256k1::signing_only();
169173
let channel_monitor_claim_key = SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, self.node_id]).unwrap();

fuzz/src/full_stack.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ impl<'a> Drop for MoneyLossDetector<'a> {
257257

258258
struct KeyProvider {
259259
node_secret: SecretKey,
260+
inbound_payment_secret: SecretKey,
260261
counter: AtomicU64,
261262
}
262263
impl KeysInterface for KeyProvider {
@@ -266,6 +267,10 @@ impl KeysInterface for KeyProvider {
266267
self.node_secret.clone()
267268
}
268269

270+
fn get_inbound_payment_secret(&self) -> SecretKey {
271+
self.inbound_payment_secret.clone()
272+
}
273+
269274
fn get_destination_script(&self) -> Script {
270275
let secp_ctx = Secp256k1::signing_only();
271276
let channel_monitor_claim_key = SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
@@ -365,11 +370,16 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
365370
Err(_) => return,
366371
};
367372

373+
let inbound_payment_key = match SecretKey::from_slice(get_slice!(32)) {
374+
Ok(key) => key,
375+
Err(_) => return,
376+
};
377+
368378
let broadcast = Arc::new(TestBroadcaster{ txn_broadcasted: Mutex::new(Vec::new()) });
369379
let monitor = Arc::new(chainmonitor::ChainMonitor::new(None, broadcast.clone(), Arc::clone(&logger), fee_est.clone(),
370380
Arc::new(TestPersister { update_ret: Mutex::new(Ok(())) })));
371381

372-
let keys_manager = Arc::new(KeyProvider { node_secret: our_network_key.clone(), counter: AtomicU64::new(0) });
382+
let keys_manager = Arc::new(KeyProvider { node_secret: our_network_key.clone(), inbound_payment_secret: inbound_payment_key, counter: AtomicU64::new(0) });
373383
let mut config = UserConfig::default();
374384
config.channel_options.forwarding_fee_proportional_millionths = slice_to_be32(get_slice!(4));
375385
config.channel_options.announced_channel = get_slice!(1)[0] != 0;

lightning/src/chain/keysinterface.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,11 @@ pub trait KeysInterface {
397397
/// this trait to parse the invoice and make sure they're signing what they expect, rather than
398398
/// blindly signing the hash.
399399
fn sign_invoice(&self, invoice_preimage: Vec<u8>) -> Result<RecoverableSignature, ()>;
400+
401+
/// Get a secret key for use in encrypting and decrypting inbound payment data.
402+
///
403+
/// This method must return the same value each time it is called.
404+
fn get_inbound_payment_secret(&self) -> SecretKey;
400405
}
401406

402407
#[derive(Clone)]
@@ -760,6 +765,7 @@ impl Readable for InMemorySigner {
760765
pub struct KeysManager {
761766
secp_ctx: Secp256k1<secp256k1::All>,
762767
node_secret: SecretKey,
768+
inbound_payments_secret: SecretKey,
763769
destination_script: Script,
764770
shutdown_pubkey: PublicKey,
765771
channel_master_key: ExtendedPrivKey,
@@ -800,6 +806,7 @@ impl KeysManager {
800806
match ExtendedPrivKey::new_master(Network::Testnet, seed) {
801807
Ok(master_key) => {
802808
let node_secret = master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx(0).unwrap()).expect("Your RNG is busted").private_key.key;
809+
let inbound_payments_secret = master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx(1).unwrap()).expect("Your RNG is busted").private_key.key;
803810
let destination_script = match master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx(1).unwrap()) {
804811
Ok(destination_key) => {
805812
let wpubkey_hash = WPubkeyHash::hash(&ExtendedPubKey::from_private(&secp_ctx, &destination_key).public_key.to_bytes());
@@ -824,6 +831,7 @@ impl KeysManager {
824831
let mut res = KeysManager {
825832
secp_ctx,
826833
node_secret,
834+
inbound_payments_secret,
827835

828836
destination_script,
829837
shutdown_pubkey,
@@ -1032,6 +1040,10 @@ impl KeysInterface for KeysManager {
10321040
self.node_secret.clone()
10331041
}
10341042

1043+
fn get_inbound_payment_secret(&self) -> SecretKey {
1044+
self.inbound_payments_secret.clone()
1045+
}
1046+
10351047
fn get_destination_script(&self) -> Script {
10361048
self.destination_script.clone()
10371049
}

lightning/src/ln/channel.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5788,6 +5788,7 @@ mod tests {
57885788
type Signer = InMemorySigner;
57895789

57905790
fn get_node_secret(&self) -> SecretKey { panic!(); }
5791+
fn get_inbound_payment_secret(&self) -> SecretKey { panic!(); }
57915792
fn get_destination_script(&self) -> Script {
57925793
let secp_ctx = Secp256k1::signing_only();
57935794
let channel_monitor_claim_key = SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();

lightning/src/util/test_utils.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ impl keysinterface::KeysInterface for OnlyReadsKeysInterface {
7070
type Signer = EnforcingSigner;
7171

7272
fn get_node_secret(&self) -> SecretKey { unreachable!(); }
73+
fn get_inbound_payment_secret(&self) -> SecretKey { unreachable!(); }
7374
fn get_destination_script(&self) -> Script { unreachable!(); }
7475
fn get_shutdown_scriptpubkey(&self) -> ShutdownScript { unreachable!(); }
7576
fn get_channel_signer(&self, _inbound: bool, _channel_value_satoshis: u64) -> EnforcingSigner { unreachable!(); }
@@ -461,6 +462,7 @@ impl keysinterface::KeysInterface for TestKeysInterface {
461462
type Signer = EnforcingSigner;
462463

463464
fn get_node_secret(&self) -> SecretKey { self.backing.get_node_secret() }
465+
fn get_inbound_payment_secret(&self) -> SecretKey { self.backing.get_inbound_payment_secret() }
464466
fn get_destination_script(&self) -> Script { self.backing.get_destination_script() }
465467

466468
fn get_shutdown_scriptpubkey(&self) -> ShutdownScript {

0 commit comments

Comments
 (0)