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