Browse Source

Merge #567

567: Improve naming of noise protocol parameters r=klochowicz a=klochowicz



Co-authored-by: Mariusz Klochowicz <mariusz@klochowicz.com>
new-http-api
bors[bot] 3 years ago
committed by GitHub
parent
commit
f4d56bcf67
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      daemon/src/connection.rs
  2. 4
      daemon/src/lib.rs
  3. 7
      daemon/src/maker.rs
  4. 5
      daemon/src/seed.rs
  5. 6
      daemon/src/taker.rs
  6. 20
      daemon/tests/harness/mod.rs

19
daemon/src/connection.rs

@ -20,7 +20,7 @@ pub struct Actor {
status_sender: watch::Sender<ConnectionStatus>, status_sender: watch::Sender<ConnectionStatus>,
send_to_maker: Box<dyn MessageChannel<wire::TakerToMaker>>, send_to_maker: Box<dyn MessageChannel<wire::TakerToMaker>>,
send_to_maker_ctx: xtra::Context<send_to_socket::Actor<wire::TakerToMaker>>, send_to_maker_ctx: xtra::Context<send_to_socket::Actor<wire::TakerToMaker>>,
noise_static_sk: x25519_dalek::StaticSecret, identity_sk: x25519_dalek::StaticSecret,
maker_to_taker: Box<dyn MessageChannel<wire::MakerToTaker>>, maker_to_taker: Box<dyn MessageChannel<wire::MakerToTaker>>,
/// Max duration since the last heartbeat until we die. /// Max duration since the last heartbeat until we die.
timeout: Duration, timeout: Duration,
@ -28,7 +28,7 @@ pub struct Actor {
} }
pub struct Connect { pub struct Connect {
pub maker_noise_static_pk: x25519_dalek::PublicKey, pub maker_identity_pk: x25519_dalek::PublicKey,
pub maker_addr: SocketAddr, pub maker_addr: SocketAddr,
} }
@ -49,7 +49,7 @@ impl Actor {
pub fn new( pub fn new(
status_sender: watch::Sender<ConnectionStatus>, status_sender: watch::Sender<ConnectionStatus>,
maker_to_taker: Box<dyn MessageChannel<wire::MakerToTaker>>, maker_to_taker: Box<dyn MessageChannel<wire::MakerToTaker>>,
noise_static_sk: x25519_dalek::StaticSecret, identity_sk: x25519_dalek::StaticSecret,
timeout: Duration, timeout: Duration,
) -> Self { ) -> Self {
let (send_to_maker_addr, send_to_maker_ctx) = xtra::Context::new(None); let (send_to_maker_addr, send_to_maker_ctx) = xtra::Context::new(None);
@ -58,7 +58,7 @@ impl Actor {
status_sender, status_sender,
send_to_maker: Box::new(send_to_maker_addr), send_to_maker: Box::new(send_to_maker_addr),
send_to_maker_ctx, send_to_maker_ctx,
noise_static_sk, identity_sk,
maker_to_taker, maker_to_taker,
timeout, timeout,
connected_state: None, connected_state: None,
@ -79,19 +79,16 @@ impl Actor {
&mut self, &mut self,
Connect { Connect {
maker_addr, maker_addr,
maker_noise_static_pk, maker_identity_pk,
}: Connect, }: Connect,
ctx: &mut xtra::Context<Self>, ctx: &mut xtra::Context<Self>,
) -> Result<()> { ) -> Result<()> {
let (read, write, noise) = { let (read, write, noise) = {
let socket = tokio::net::TcpSocket::new_v4().expect("Be able to create a socket"); let socket = tokio::net::TcpSocket::new_v4().expect("Be able to create a socket");
let mut connection = socket.connect(maker_addr).await?; let mut connection = socket.connect(maker_addr).await?;
let noise = noise::initiator_handshake( let noise =
&mut connection, noise::initiator_handshake(&mut connection, &self.identity_sk, &maker_identity_pk)
&self.noise_static_sk, .await?;
&maker_noise_static_pk,
)
.await?;
let (read, write) = connection.into_split(); let (read, write) = connection.into_split();
(read, write, Arc::new(Mutex::new(noise))) (read, write, Arc::new(Mutex::new(noise)))
}; };

4
daemon/src/lib.rs

@ -186,7 +186,7 @@ where
db: SqlitePool, db: SqlitePool,
wallet_addr: Address<W>, wallet_addr: Address<W>,
oracle_pk: schnorrsig::PublicKey, oracle_pk: schnorrsig::PublicKey,
noise_static_sk: x25519_dalek::StaticSecret, identity_sk: x25519_dalek::StaticSecret,
oracle_constructor: impl FnOnce(Vec<Cfd>, Box<dyn StrongMessageChannel<Attestation>>) -> O, oracle_constructor: impl FnOnce(Vec<Cfd>, Box<dyn StrongMessageChannel<Attestation>>) -> O,
monitor_constructor: impl FnOnce(Box<dyn StrongMessageChannel<monitor::Event>>, Vec<Cfd>) -> F, monitor_constructor: impl FnOnce(Box<dyn StrongMessageChannel<monitor::Event>>, Vec<Cfd>) -> F,
n_payouts: usize, n_payouts: usize,
@ -228,7 +228,7 @@ where
tokio::spawn(connection_actor_ctx.run(connection::Actor::new( tokio::spawn(connection_actor_ctx.run(connection::Actor::new(
maker_online_status_feed_sender, maker_online_status_feed_sender,
Box::new(cfd_actor_addr.clone()), Box::new(cfd_actor_addr.clone()),
noise_static_sk, identity_sk,
HEARTBEAT_INTERVAL * 2, HEARTBEAT_INTERVAL * 2,
))); )));

7
daemon/src/maker.rs

@ -192,14 +192,13 @@ async fn main() -> Result<()> {
let auth_password = seed.derive_auth_password::<auth::Password>(); let auth_password = seed.derive_auth_password::<auth::Password>();
let noise_static_sk = seed.derive_noise_static_secret(); let (identity_pk, identity_sk) = seed.derive_identity();
let noise_static_pk = x25519_dalek::PublicKey::from(&noise_static_sk);
tracing::info!( tracing::info!(
"Authentication details: username='{}' password='{}', noise_public_key='{}'", "Authentication details: username='{}' password='{}', noise_public_key='{}'",
MAKER_USERNAME, MAKER_USERNAME,
auth_password, auth_password,
hex::encode(noise_static_pk.to_bytes()) hex::encode(identity_pk.to_bytes())
); );
// TODO: Actually fetch it from Olivia // TODO: Actually fetch it from Olivia
@ -262,7 +261,7 @@ async fn main() -> Result<()> {
monitor::Actor::new(electrum, channel, cfds) 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), time::Duration::hours(opts.settlement_time_interval_hours as i64),
N_PAYOUTS, N_PAYOUTS,
) )

5
daemon/src/seed.rs

@ -66,14 +66,15 @@ impl Seed {
P::from(password) 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]; let mut secret = [0u8; 32];
Hkdf::<Sha256>::new(None, &self.0) Hkdf::<Sha256>::new(None, &self.0)
.expand(b"NOISE_STATIC_SECRET", &mut secret) .expand(b"NOISE_STATIC_SECRET", &mut secret)
.expect("okm array is of correct length"); .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)
} }
} }

6
daemon/src/taker.rs

@ -166,7 +166,7 @@ async fn main() -> Result<()> {
let bitcoin_network = opts.network.bitcoin_network(); let bitcoin_network = opts.network.bitcoin_network();
let ext_priv_key = seed.derive_extended_priv_key(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( let wallet = wallet::Actor::new(
opts.network.electrum(), opts.network.electrum(),
@ -241,7 +241,7 @@ async fn main() -> Result<()> {
db.clone(), db.clone(),
wallet.clone(), wallet.clone(),
oracle, oracle,
noise_static_sk, identity_sk,
|cfds, channel| oracle::Actor::new(cfds, channel, ANNOUNCEMENT_LOOKAHEAD), |cfds, channel| oracle::Actor::new(cfds, channel, ANNOUNCEMENT_LOOKAHEAD),
{ {
|channel, cfds| { |channel, cfds| {
@ -255,7 +255,7 @@ async fn main() -> Result<()> {
while connection_actor_addr while connection_actor_addr
.send(connection::Connect { .send(connection::Connect {
maker_noise_static_pk: opts.maker_id, maker_identity_pk: opts.maker_id,
maker_addr: opts.maker, maker_addr: opts.maker,
}) })
.await? .await?

20
daemon/tests/harness/mod.rs

@ -33,7 +33,7 @@ pub async fn start_both() -> (Maker, Taker) {
.unwrap(); .unwrap();
let maker = Maker::start(oracle_pk).await; 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) (maker, taker)
} }
@ -51,7 +51,7 @@ pub struct Maker {
pub inc_conn_actor_addr: xtra::Address<maker_inc_connections::Actor>, pub inc_conn_actor_addr: xtra::Address<maker_inc_connections::Actor>,
pub listen_addr: SocketAddr, pub listen_addr: SocketAddr,
pub mocks: mocks::Mocks, pub mocks: mocks::Mocks,
pub noise_static_pk: x25519_dalek::PublicKey, pub identity_pk: x25519_dalek::PublicKey,
} }
impl Maker { impl Maker {
@ -67,9 +67,7 @@ impl Maker {
let settlement_time_interval_hours = time::Duration::hours(24); let settlement_time_interval_hours = time::Duration::hours(24);
let seed = Seed::default(); let seed = Seed::default();
let (identity_pk, identity_sk) = seed.derive_identity();
let noise_static_sk = seed.derive_noise_static_secret();
let noise_static_pk = x25519_dalek::PublicKey::from(&noise_static_sk);
let maker = daemon::MakerActorSystem::new( let maker = daemon::MakerActorSystem::new(
db, db,
@ -77,9 +75,7 @@ impl Maker {
oracle_pk, oracle_pk,
|_, _| oracle, |_, _| oracle,
|_, _| async { Ok(monitor) }, |_, _| async { Ok(monitor) },
|channel0, channel1| { |channel0, channel1| maker_inc_connections::Actor::new(channel0, channel1, identity_sk),
maker_inc_connections::Actor::new(channel0, channel1, noise_static_sk)
},
settlement_time_interval_hours, settlement_time_interval_hours,
N_PAYOUTS_FOR_TEST, N_PAYOUTS_FOR_TEST,
) )
@ -110,7 +106,7 @@ impl Maker {
cfd_feed: maker.cfd_feed_receiver, cfd_feed: maker.cfd_feed_receiver,
inc_conn_actor_addr: maker.inc_conn_addr, inc_conn_actor_addr: maker.inc_conn_addr,
listen_addr: address, listen_addr: address,
noise_static_pk, identity_pk,
mocks, mocks,
} }
} }
@ -158,7 +154,7 @@ impl Taker {
) -> Self { ) -> Self {
let seed = Seed::default(); 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; let db = in_memory_db().await;
@ -172,7 +168,7 @@ impl Taker {
db, db,
wallet_addr, wallet_addr,
oracle_pk, oracle_pk,
noise_static_sk, identity_sk,
|_, _| oracle, |_, _| oracle,
|_, _| async { Ok(monitor) }, |_, _| async { Ok(monitor) },
N_PAYOUTS_FOR_TEST, N_PAYOUTS_FOR_TEST,
@ -183,7 +179,7 @@ impl Taker {
taker taker
.connection_actor_addr .connection_actor_addr
.send(Connect { .send(Connect {
maker_noise_static_pk: maker_noise_pub_key, maker_identity_pk: maker_noise_pub_key,
maker_addr: maker_address, maker_addr: maker_address,
}) })
.await .await

Loading…
Cancel
Save