From 8d53f397a2fe5f4a1eb7aa3c72b5ee0c690d7fe6 Mon Sep 17 00:00:00 2001 From: Mariusz Klochowicz Date: Mon, 15 Nov 2021 15:56:16 +1030 Subject: [PATCH] Improve naming of noise protocol parameters --- daemon/src/connection.rs | 19 ++++++++----------- daemon/src/lib.rs | 4 ++-- daemon/src/maker.rs | 7 +++---- daemon/src/seed.rs | 5 +++-- daemon/src/taker.rs | 6 +++--- daemon/tests/harness/mod.rs | 20 ++++++++------------ 6 files changed, 27 insertions(+), 34 deletions(-) diff --git a/daemon/src/connection.rs b/daemon/src/connection.rs index f41c462..2094fa1 100644 --- a/daemon/src/connection.rs +++ b/daemon/src/connection.rs @@ -20,7 +20,7 @@ pub struct Actor { status_sender: watch::Sender, send_to_maker: Box>, send_to_maker_ctx: xtra::Context>, - noise_static_sk: x25519_dalek::StaticSecret, + identity_sk: x25519_dalek::StaticSecret, maker_to_taker: Box>, /// Max duration since the last heartbeat until we die. timeout: Duration, @@ -28,7 +28,7 @@ pub struct Actor { } pub struct Connect { - pub maker_noise_static_pk: x25519_dalek::PublicKey, + pub maker_identity_pk: x25519_dalek::PublicKey, pub maker_addr: SocketAddr, } @@ -49,7 +49,7 @@ impl Actor { pub fn new( status_sender: watch::Sender, maker_to_taker: Box>, - noise_static_sk: x25519_dalek::StaticSecret, + identity_sk: x25519_dalek::StaticSecret, timeout: Duration, ) -> Self { let (send_to_maker_addr, send_to_maker_ctx) = xtra::Context::new(None); @@ -58,7 +58,7 @@ impl Actor { status_sender, send_to_maker: Box::new(send_to_maker_addr), send_to_maker_ctx, - noise_static_sk, + identity_sk, maker_to_taker, timeout, connected_state: None, @@ -79,19 +79,16 @@ impl Actor { &mut self, Connect { maker_addr, - maker_noise_static_pk, + maker_identity_pk, }: Connect, ctx: &mut xtra::Context, ) -> Result<()> { let (read, write, noise) = { let socket = tokio::net::TcpSocket::new_v4().expect("Be able to create a socket"); let mut connection = socket.connect(maker_addr).await?; - let noise = noise::initiator_handshake( - &mut connection, - &self.noise_static_sk, - &maker_noise_static_pk, - ) - .await?; + let noise = + noise::initiator_handshake(&mut connection, &self.identity_sk, &maker_identity_pk) + .await?; let (read, write) = connection.into_split(); (read, write, Arc::new(Mutex::new(noise))) }; diff --git a/daemon/src/lib.rs b/daemon/src/lib.rs index e648895..dda322c 100644 --- a/daemon/src/lib.rs +++ b/daemon/src/lib.rs @@ -186,7 +186,7 @@ where db: SqlitePool, wallet_addr: Address, oracle_pk: schnorrsig::PublicKey, - noise_static_sk: x25519_dalek::StaticSecret, + identity_sk: x25519_dalek::StaticSecret, oracle_constructor: impl FnOnce(Vec, Box>) -> O, monitor_constructor: impl FnOnce(Box>, Vec) -> F, n_payouts: usize, @@ -228,7 +228,7 @@ where tokio::spawn(connection_actor_ctx.run(connection::Actor::new( maker_online_status_feed_sender, Box::new(cfd_actor_addr.clone()), - noise_static_sk, + identity_sk, HEARTBEAT_INTERVAL * 2, ))); diff --git a/daemon/src/maker.rs b/daemon/src/maker.rs index 8746a95..c1185f7 100644 --- a/daemon/src/maker.rs +++ b/daemon/src/maker.rs @@ -192,14 +192,13 @@ async fn main() -> Result<()> { let auth_password = seed.derive_auth_password::(); - let noise_static_sk = seed.derive_noise_static_secret(); - let noise_static_pk = x25519_dalek::PublicKey::from(&noise_static_sk); + let (identity_pk, identity_sk) = seed.derive_identity(); tracing::info!( "Authentication details: username='{}' password='{}', noise_public_key='{}'", MAKER_USERNAME, auth_password, - hex::encode(noise_static_pk.to_bytes()) + hex::encode(identity_pk.to_bytes()) ); // TODO: Actually fetch it from Olivia @@ -262,7 +261,7 @@ async fn main() -> Result<()> { monitor::Actor::new(electrum, channel, cfds) } }, - |channel0, channel1| maker_inc_connections::Actor::new(channel0, channel1, noise_static_sk), + |channel0, channel1| maker_inc_connections::Actor::new(channel0, channel1, identity_sk), time::Duration::hours(opts.settlement_time_interval_hours as i64), N_PAYOUTS, ) diff --git a/daemon/src/seed.rs b/daemon/src/seed.rs index e9a299e..bcc0747 100644 --- a/daemon/src/seed.rs +++ b/daemon/src/seed.rs @@ -66,14 +66,15 @@ impl Seed { P::from(password) } - pub fn derive_noise_static_secret(&self) -> x25519_dalek::StaticSecret { + pub fn derive_identity(&self) -> (x25519_dalek::PublicKey, x25519_dalek::StaticSecret) { let mut secret = [0u8; 32]; Hkdf::::new(None, &self.0) .expand(b"NOISE_STATIC_SECRET", &mut secret) .expect("okm array is of correct length"); - x25519_dalek::StaticSecret::from(secret) + let identity_sk = x25519_dalek::StaticSecret::from(secret); + (x25519_dalek::PublicKey::from(&identity_sk), identity_sk) } } diff --git a/daemon/src/taker.rs b/daemon/src/taker.rs index 7be0a97..876e9b5 100644 --- a/daemon/src/taker.rs +++ b/daemon/src/taker.rs @@ -166,7 +166,7 @@ async fn main() -> Result<()> { let bitcoin_network = opts.network.bitcoin_network(); let ext_priv_key = seed.derive_extended_priv_key(bitcoin_network)?; - let noise_static_sk = seed.derive_noise_static_secret(); + let (_, identity_sk) = seed.derive_identity(); let wallet = wallet::Actor::new( opts.network.electrum(), @@ -241,7 +241,7 @@ async fn main() -> Result<()> { db.clone(), wallet.clone(), oracle, - noise_static_sk, + identity_sk, |cfds, channel| oracle::Actor::new(cfds, channel, ANNOUNCEMENT_LOOKAHEAD), { |channel, cfds| { @@ -255,7 +255,7 @@ async fn main() -> Result<()> { while connection_actor_addr .send(connection::Connect { - maker_noise_static_pk: opts.maker_id, + maker_identity_pk: opts.maker_id, maker_addr: opts.maker, }) .await? diff --git a/daemon/tests/harness/mod.rs b/daemon/tests/harness/mod.rs index 3587867..48c9861 100644 --- a/daemon/tests/harness/mod.rs +++ b/daemon/tests/harness/mod.rs @@ -33,7 +33,7 @@ pub async fn start_both() -> (Maker, Taker) { .unwrap(); let maker = Maker::start(oracle_pk).await; - let taker = Taker::start(oracle_pk, maker.listen_addr, maker.noise_static_pk).await; + let taker = Taker::start(oracle_pk, maker.listen_addr, maker.identity_pk).await; (maker, taker) } @@ -51,7 +51,7 @@ pub struct Maker { pub inc_conn_actor_addr: xtra::Address, pub listen_addr: SocketAddr, pub mocks: mocks::Mocks, - pub noise_static_pk: x25519_dalek::PublicKey, + pub identity_pk: x25519_dalek::PublicKey, } impl Maker { @@ -67,9 +67,7 @@ impl Maker { let settlement_time_interval_hours = time::Duration::hours(24); let seed = Seed::default(); - - let noise_static_sk = seed.derive_noise_static_secret(); - let noise_static_pk = x25519_dalek::PublicKey::from(&noise_static_sk); + let (identity_pk, identity_sk) = seed.derive_identity(); let maker = daemon::MakerActorSystem::new( db, @@ -77,9 +75,7 @@ impl Maker { oracle_pk, |_, _| oracle, |_, _| async { Ok(monitor) }, - |channel0, channel1| { - maker_inc_connections::Actor::new(channel0, channel1, noise_static_sk) - }, + |channel0, channel1| maker_inc_connections::Actor::new(channel0, channel1, identity_sk), settlement_time_interval_hours, N_PAYOUTS_FOR_TEST, ) @@ -110,7 +106,7 @@ impl Maker { cfd_feed: maker.cfd_feed_receiver, inc_conn_actor_addr: maker.inc_conn_addr, listen_addr: address, - noise_static_pk, + identity_pk, mocks, } } @@ -158,7 +154,7 @@ impl Taker { ) -> Self { let seed = Seed::default(); - let noise_static_sk = seed.derive_noise_static_secret(); + let (_, identity_sk) = seed.derive_identity(); let db = in_memory_db().await; @@ -172,7 +168,7 @@ impl Taker { db, wallet_addr, oracle_pk, - noise_static_sk, + identity_sk, |_, _| oracle, |_, _| async { Ok(monitor) }, N_PAYOUTS_FOR_TEST, @@ -183,7 +179,7 @@ impl Taker { taker .connection_actor_addr .send(Connect { - maker_noise_static_pk: maker_noise_pub_key, + maker_identity_pk: maker_noise_pub_key, maker_addr: maker_address, }) .await