diff --git a/Cargo.toml b/Cargo.toml index 6807627..e80cc4d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,8 +15,8 @@ structopt = "0.3.14" chrono = "0.4.11" futures = "0.3.5" toml = "0.5.6" -ilmp = { git = "https://github.com/izzabelle/ilmp" } -# ilmp = { path = "../ilmp"} +# ilmp = { git = "https://github.com/izzabelle/ilmp" } +ilmp = { path = "../ilmp"} ring = "0.16.13" thiserror = "1.0.18" orion = "0.15.1" diff --git a/src/client.rs b/src/client.rs index 2f2b63e..6427928 100644 --- a/src/client.rs +++ b/src/client.rs @@ -4,12 +4,8 @@ use crate::Result; use async_std::{io, net::TcpStream, task}; use futures::io::{ReadHalf, WriteHalf}; use futures_util::io::AsyncReadExt; -use ilmp::{ - encrypt::{EncryptKind, Encryption, SymmetricEncrypt}, - Sendable, -}; +use ilmp::{encrypt::SymmetricEncrypt, Sendable}; use lazy_static::lazy_static; -use orion::aead; use std::sync::Mutex; lazy_static! { @@ -47,12 +43,8 @@ pub async fn outgoing(mut write: WriteHalf, encryption: SymmetricEncr pub async fn incoming(mut read: ReadHalf, encryption: SymmetricEncrypt) -> Result<()> { loop { - let packet = ilmp::read(&mut read).await?; - if let Some(mut packet) = packet { - if packet.encrypt_kind == EncryptKind::Symmetric { - packet.contents = aead::open(encryption.key().unwrap(), &packet.contents)?; - } - + let packet = ilmp::read(&mut read, &encryption).await?; + if let Some(packet) = packet { let res = match packet.kind { ilmp::PacketKind::Message => ilmp::Message::from_packet(packet), _ => panic!("bad packet"), diff --git a/src/lib.rs b/src/lib.rs index 451d89a..1ee9c4f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -45,15 +45,16 @@ pub async fn initialize_connection( ilmp::write(write, agreement_packet, &encrypt::NoEncrypt::new()).await?; // receive peer's pub key - let packet = ilmp::read(read).await?.unwrap(); + let packet = ilmp::read(read, &encrypt::NoEncrypt::new()).await?.unwrap(); let agreement_packet = ilmp::Agreement::from_packet(packet)?; let peer_pub_key = agreement::UnparsedPublicKey::new(&agreement::X25519, agreement_packet.public_key); // generate aead key agreement::agree_ephemeral(my_priv_key, &peer_pub_key, MsgError::Ring, |key_material| { - let key_material = - digest::digest(&digest::SHA256, key_material.as_ref().into()).as_ref().to_vec(); + let key_material = digest::digest(&digest::SHA256, key_material.as_ref().into()) + .as_ref() + .to_vec(); Ok(aead::SecretKey::from_slice(&key_material)?) }) } diff --git a/src/server.rs b/src/server.rs index 533f804..877b5e1 100644 --- a/src/server.rs +++ b/src/server.rs @@ -11,7 +11,6 @@ use ilmp::encrypt; use ilmp::encrypt::Encryption; use ilmp::Sendable; use lazy_static::lazy_static; -use orion::aead; use std::collections::HashMap; use uuid::Uuid; @@ -58,12 +57,8 @@ async fn handle_stream( encryption: encrypt::SymmetricEncrypt, ) -> Result<()> { loop { - let packet = ilmp::read(&mut stream).await?; - if let Some(mut packet) = packet { - if packet.encrypt_kind == encrypt::EncryptKind::Symmetric { - packet.contents = aead::open(encryption.key().unwrap(), &packet.contents)?; - } - + let packet = ilmp::read(&mut stream, &encryption).await?; + if let Some(packet) = packet { let res = match packet.kind { ilmp::PacketKind::Message => ilmp::Message::from_packet(packet), _ => panic!("bad packet"), @@ -80,9 +75,10 @@ async fn handle_stream( Ok(()) } -async fn relay_packet(packet: T, encryption: &encrypt::SymmetricEncrypt) -> Result<()> +async fn relay_packet(packet: T, encryption: &E) -> Result<()> where T: Clone + Sendable, + E: Encryption, { let mut locked_write_streams = WRITE_STREAMS.lock().await; let stream = futures::stream::iter(locked_write_streams.iter_mut());