diff --git a/libepf/src/ca_pool.rs b/libepf/src/ca_pool.rs index 0553d07..527abc2 100644 --- a/libepf/src/ca_pool.rs +++ b/libepf/src/ca_pool.rs @@ -1,6 +1,6 @@ use crate::pki::{EPFCertificate, EpfPkiSerializable, EpfPublicKey}; use crate::util::verifying_key; -use log::trace; + use std::collections::HashMap; use std::error::Error; use std::ffi::OsStr; diff --git a/libepf/src/handshake_stream.rs b/libepf/src/handshake_stream.rs index f1a443a..ccb47e4 100644 --- a/libepf/src/handshake_stream.rs +++ b/libepf/src/handshake_stream.rs @@ -1,8 +1,8 @@ -use crate::ca_pool::{load_ca_pool, EpfCaPool}; +use crate::ca_pool::{EpfCaPool}; use crate::danger_trace; use crate::error::EpfHandshakeError; use crate::pki::{ - EPFCertificate, EpfPkiCertificateOps, EpfPrivateKey, EpfPublicKey, EPFPKI_PUBLIC_KEY_LENGTH, + EPFCertificate, EpfPkiCertificateOps, EpfPrivateKey, EpfPublicKey, }; use crate::protocol::{ encode_packet, recv_packet, EpfApplicationData, EpfClientHello, EpfClientState, EpfFinished, @@ -12,14 +12,14 @@ use crate::protocol::{ use async_trait::async_trait; use chacha20poly1305::aead::{Aead, Payload}; use chacha20poly1305::{AeadCore, Key, KeyInit, XChaCha20Poly1305, XNonce}; -use ed25519_dalek::{SecretKey, SigningKey}; -use log::{debug, trace}; +use ed25519_dalek::{SigningKey}; +use log::{trace}; use rand::rngs::OsRng; use rand::Rng; use std::error::Error; use std::io; use tokio::io::{AsyncReadExt, AsyncWriteExt}; -use x25519_dalek::{x25519, PublicKey, StaticSecret}; +use x25519_dalek::{PublicKey, StaticSecret}; ///// CLIENT ///// @@ -38,7 +38,7 @@ pub struct EpfClientUpgraded { #[derive(Debug)] pub enum ClientAuthentication { - Cert(Box, EpfPrivateKey), + Cert(Box, Box), Ephemeral, } @@ -68,7 +68,7 @@ where ClientAuthentication::Cert(cert_d, key) => { trace!("----!!!!! CERT AUTHENTICATION !!!!!----"); cert = Some(cert_d); - private_key = key.clone(); + private_key = key; public_key = PublicKey::from(&StaticSecret::from(private_key.to_bytes())); } ClientAuthentication::Ephemeral => { @@ -76,7 +76,7 @@ where let private_key_l: [u8; 32] = OsRng.gen(); let private_key_real = SigningKey::from(private_key_l); public_key = PublicKey::from(&StaticSecret::from(private_key_real.to_bytes())); - private_key = private_key_real; + private_key = Box::new(private_key_real); } } @@ -89,7 +89,7 @@ where server_cert: None, packet_queue: vec![], cipher: None, - private_key, + private_key: *private_key, public_key, } } @@ -277,13 +277,13 @@ impl EpfClientHandshaker where Self: Sized, { - let aad = self.server_random.clone(); + let aad = self.server_random; let client_cert = self.client_cert.clone(); let packet_queue = self.packet_queue.clone(); - let server_cert = self.server_cert.unwrap().clone(); - let cipher = self.cipher.unwrap().clone(); + let server_cert = self.server_cert.unwrap(); + let cipher = self.cipher.unwrap(); let private_key = self.private_key.clone(); - let public_key = self.public_key.clone(); + let public_key = self.public_key; let raw_stream = self.inner; EpfClientStream { raw_stream, @@ -298,6 +298,7 @@ impl EpfClientHandshaker } } +#[allow(dead_code)] pub struct EpfClientStream { raw_stream: S, aad: [u8; 16], @@ -622,6 +623,7 @@ impl EpfServerHandshaker } } +#[allow(dead_code)] pub struct EpfServerStream { raw_stream: S, aad: [u8; 16], @@ -699,13 +701,13 @@ mod tests { EpfServerHandshaker, EpfServerUpgradable, EpfServerUpgraded, EpfStreamOps, }; use crate::pki::{EPFCertificate, EPFCertificateDetails, EpfPkiCertificateOps}; - use ed25519_dalek::{SecretKey, SigningKey}; + use ed25519_dalek::{SigningKey}; use log::{debug, trace}; - use rand::rngs::OsRng; + use std::net::SocketAddr; use std::str::FromStr; use std::time::{SystemTime, UNIX_EPOCH}; - use tcp_test::channel; + use tokio::io::{AsyncReadExt, AsyncWriteExt}; use tokio::join; use tokio::net::{TcpListener, TcpSocket, TcpStream}; @@ -779,7 +781,7 @@ mod tests { let mut c: EpfClientUpgraded = EpfClientUpgradable::upgrade( c, - ClientAuthentication::Cert(Box::new(client_cert), client_private_key), + ClientAuthentication::Cert(Box::new(client_cert), Box::new(client_private_key)), ) .await; let mut s: EpfServerUpgraded = diff --git a/libepf/src/protocol.rs b/libepf/src/protocol.rs index e6b50ca..30564de 100644 --- a/libepf/src/protocol.rs +++ b/libepf/src/protocol.rs @@ -1,5 +1,5 @@ use crate::pki::{EPFCertificate, EPFPKI_PUBLIC_KEY_LENGTH}; -use log::debug; + use serde::{Deserialize, Serialize}; use std::error::Error; use tokio::io::AsyncReadExt;