Selaa lähdekoodia

removed initialize_connection and put it in ilmp

master
Isabelle L. 5 vuotta sitten
vanhempi
commit
6dbcc641f6
3 muutettua tiedostoa jossa 3 lisäystä ja 38 poistoa
  1. +1
    -3
      src/client.rs
  2. +1
    -34
      src/lib.rs
  3. +1
    -1
      src/server.rs

+ 1
- 3
src/client.rs Näytä tiedosto

@@ -6,10 +6,8 @@ use futures::io::{ReadHalf, WriteHalf};
use futures_util::io::AsyncReadExt;
use ilmp::{encrypt::SymmetricEncrypt, Sendable};
use lazy_static::lazy_static;
use std::sync::Mutex;

lazy_static! {
static ref MESSAGE_BUFFER: Mutex<Vec<ilmp::Message>> = Mutex::new(Vec::new());
static ref CONFIG: Config = Config::load().expect("failed to load config");
}

@@ -23,7 +21,7 @@ pub async fn client(port: u16) -> Result<()> {
);
let (mut read, mut write) = stream.split();

let key = crate::initialize_connection(&mut read, &mut write).await?;
let key = ilmp::initialize_connection(&mut read, &mut write).await?;
let encryption = SymmetricEncrypt::new(key);
println!("successfully hardened connection");



+ 1
- 34
src/lib.rs Näytä tiedosto

@@ -3,12 +3,7 @@ mod client;
mod config;
mod server;

use async_std::net::TcpStream;
use futures::io::{ReadHalf, WriteHalf};
use ilmp::encrypt;
use ilmp::Sendable;
use orion::aead;
use ring::{agreement, digest, rand};
// namespacing
use thiserror::Error;

// re-exports
@@ -30,31 +25,3 @@ pub enum MsgError {
#[error("orion error")]
Orion(#[from] orion::errors::UnknownCryptoError),
}

/// uses ring's agreement to generate key material and key
pub async fn initialize_connection(
read: &mut ReadHalf<TcpStream>,
write: &mut WriteHalf<TcpStream>,
) -> Result<aead::SecretKey> {
// create / send agreement key
let rng = rand::SystemRandom::new();
let my_priv_key =
agreement::EphemeralPrivateKey::generate(&agreement::X25519, &rng).expect("ring broke");
let my_pub_key = my_priv_key.compute_public_key().expect("ring broke");
let agreement_packet = ilmp::Agreement::new(my_pub_key.as_ref().into());
ilmp::write(write, agreement_packet, &encrypt::NoEncrypt::new()).await?;

// receive peer's pub key
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();
Ok(aead::SecretKey::from_slice(&key_material)?)
})
}

+ 1
- 1
src/server.rs Näytä tiedosto

@@ -40,7 +40,7 @@ pub async fn server(port: u16) -> Result<()> {
let (mut read, mut write) = stream.split();
let stream_id = Uuid::new_v4();

let key = crate::initialize_connection(&mut read, &mut write).await?;
let key = ilmp::initialize_connection(&mut read, &mut write).await?;
let encryption = encrypt::SymmetricEncrypt::new(key);
println!("successfully hardened connection");



Ladataan…
Peruuta
Tallenna