Initial commit
This commit is contained in:
commit
feb1ec51c8
11 changed files with 2559 additions and 0 deletions
149
src/client.rs
Normal file
149
src/client.rs
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
use crate::{
|
||||
TlsMode,
|
||||
record::{Direction, Records},
|
||||
};
|
||||
|
||||
use std::{net::ToSocketAddrs, sync::Arc};
|
||||
use tokio::{
|
||||
io::{AsyncReadExt, AsyncWriteExt},
|
||||
net::TcpStream,
|
||||
sync::oneshot,
|
||||
};
|
||||
use tokio_rustls::{
|
||||
TlsConnector,
|
||||
rustls::{
|
||||
SignatureScheme,
|
||||
client::danger::{HandshakeSignatureValid, ServerCertVerifier},
|
||||
pki_types::ServerName,
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
struct DummyCertVerifier;
|
||||
|
||||
impl ServerCertVerifier for DummyCertVerifier {
|
||||
fn verify_server_cert(
|
||||
&self,
|
||||
_end_entity: &tokio_rustls::rustls::pki_types::CertificateDer<'_>,
|
||||
_intermediates: &[tokio_rustls::rustls::pki_types::CertificateDer<'_>],
|
||||
_server_name: &tokio_rustls::rustls::pki_types::ServerName<'_>,
|
||||
_ocsp_response: &[u8],
|
||||
_now: tokio_rustls::rustls::pki_types::UnixTime,
|
||||
) -> Result<tokio_rustls::rustls::client::danger::ServerCertVerified, tokio_rustls::rustls::Error>
|
||||
{
|
||||
Ok(tokio_rustls::rustls::client::danger::ServerCertVerified::assertion())
|
||||
}
|
||||
fn supported_verify_schemes(&self) -> Vec<tokio_rustls::rustls::SignatureScheme> {
|
||||
vec![
|
||||
SignatureScheme::RSA_PKCS1_SHA1,
|
||||
SignatureScheme::ECDSA_SHA1_Legacy,
|
||||
SignatureScheme::RSA_PKCS1_SHA256,
|
||||
SignatureScheme::ECDSA_NISTP256_SHA256,
|
||||
SignatureScheme::RSA_PKCS1_SHA384,
|
||||
SignatureScheme::ECDSA_NISTP384_SHA384,
|
||||
SignatureScheme::RSA_PKCS1_SHA512,
|
||||
SignatureScheme::ECDSA_NISTP521_SHA512,
|
||||
SignatureScheme::RSA_PSS_SHA256,
|
||||
SignatureScheme::RSA_PSS_SHA384,
|
||||
SignatureScheme::RSA_PSS_SHA512,
|
||||
SignatureScheme::ED25519,
|
||||
SignatureScheme::ED448,
|
||||
SignatureScheme::ML_DSA_44,
|
||||
SignatureScheme::ML_DSA_65,
|
||||
SignatureScheme::ML_DSA_87,
|
||||
]
|
||||
}
|
||||
fn verify_tls12_signature(
|
||||
&self,
|
||||
_message: &[u8],
|
||||
_cert: &tokio_rustls::rustls::pki_types::CertificateDer<'_>,
|
||||
_dss: &tokio_rustls::rustls::DigitallySignedStruct,
|
||||
) -> Result<
|
||||
tokio_rustls::rustls::client::danger::HandshakeSignatureValid,
|
||||
tokio_rustls::rustls::Error,
|
||||
> {
|
||||
Ok(HandshakeSignatureValid::assertion())
|
||||
}
|
||||
fn verify_tls13_signature(
|
||||
&self,
|
||||
_message: &[u8],
|
||||
_cert: &tokio_rustls::rustls::pki_types::CertificateDer<'_>,
|
||||
_dss: &tokio_rustls::rustls::DigitallySignedStruct,
|
||||
) -> Result<HandshakeSignatureValid, tokio_rustls::rustls::Error> {
|
||||
Ok(HandshakeSignatureValid::assertion())
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn play(
|
||||
records: &'static Records,
|
||||
tls_mode: TlsMode,
|
||||
connect_to: (String, u16),
|
||||
sync_receiver: oneshot::Receiver<()>,
|
||||
repeat: u32,
|
||||
) {
|
||||
sync_receiver.await.unwrap();
|
||||
let mut handles = Vec::new();
|
||||
let connect_to = connect_to.to_socket_addrs().unwrap().next().unwrap();
|
||||
match tls_mode {
|
||||
TlsMode::Both | TlsMode::Client => {
|
||||
let config = Arc::new(
|
||||
tokio_rustls::rustls::ClientConfig::builder()
|
||||
.dangerous()
|
||||
.with_custom_certificate_verifier(Arc::new(DummyCertVerifier))
|
||||
.with_no_client_auth(),
|
||||
);
|
||||
for (_id, (server_name, records)) in records.iter() {
|
||||
let connector = TlsConnector::from(config.clone());
|
||||
handles.push(tokio::spawn(async move {
|
||||
let server_name =
|
||||
ServerName::try_from(String::from_utf8(server_name.clone()).unwrap())
|
||||
.unwrap();
|
||||
for _i in 0..repeat {
|
||||
let stream = TcpStream::connect(connect_to).await.unwrap();
|
||||
let mut stream = connector
|
||||
.connect(server_name.clone(), stream)
|
||||
.await
|
||||
.unwrap();
|
||||
for (direction, data) in records {
|
||||
match direction {
|
||||
Direction::ClientToServer => {
|
||||
stream.write_all(data).await.unwrap();
|
||||
}
|
||||
Direction::ServerToClient => {
|
||||
let mut buf = Vec::new();
|
||||
stream.read_buf(&mut buf).await.ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
stream.shutdown().await.unwrap();
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
TlsMode::None | TlsMode::Server => {
|
||||
for (_id, (_server_name, records)) in records.iter() {
|
||||
handles.push(tokio::spawn(async move {
|
||||
for _i in 0..repeat {
|
||||
let mut stream = TcpStream::connect(connect_to).await.unwrap();
|
||||
for (direction, data) in records {
|
||||
match direction {
|
||||
Direction::ClientToServer => {
|
||||
stream.write_all(data).await.unwrap();
|
||||
}
|
||||
Direction::ServerToClient => {
|
||||
let mut buf = Vec::new();
|
||||
stream.read_buf(&mut buf).await.ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
stream.shutdown().await.unwrap();
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
for handle in handles {
|
||||
handle.await.unwrap();
|
||||
}
|
||||
//std::process::exit(0);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue