From 78fa47be6eb97019be270c8c657f84cc6f35a0e4 Mon Sep 17 00:00:00 2001 From: Carlo Mazzaferro Date: Fri, 20 Sep 2024 13:56:10 +0200 Subject: [PATCH] no tls --- .../src/bin/tcp_upgrade_client.rs | 73 ++++++++++--------- 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/iris-mpc-upgrade/src/bin/tcp_upgrade_client.rs b/iris-mpc-upgrade/src/bin/tcp_upgrade_client.rs index 538f4676c..00718707d 100644 --- a/iris-mpc-upgrade/src/bin/tcp_upgrade_client.rs +++ b/iris-mpc-upgrade/src/bin/tcp_upgrade_client.rs @@ -1,5 +1,5 @@ use clap::Parser; -use eyre::{Context, ContextCompat}; +use eyre::ContextCompat; use futures::{Stream, StreamExt}; use futures_concurrency::future::Join; use iris_mpc_common::{ @@ -15,14 +15,13 @@ use iris_mpc_upgrade::{ use mpc_uniqueness_check::{bits::Bits, distance::EncodedBits}; use rand::{Rng, SeedableRng}; use rand_chacha::ChaCha20Rng; -use rustls::{pki_types::ServerName, ClientConfig}; +use rustls::ClientConfig; use std::{array, convert::TryFrom, pin::Pin, sync::Arc, time::Duration}; use tokio::{ io::{AsyncReadExt, AsyncWriteExt}, net::TcpStream, time::timeout, }; -use tokio_rustls::{client::TlsStream, TlsConnector}; use tracing::error; fn install_tracing() { @@ -39,27 +38,29 @@ fn install_tracing() { .init(); } -async fn prepare_tls_stream_for_writing( - address: &str, - client_config: Arc, -) -> eyre::Result> { - // Create a TCP connection - let stream = TcpStream::connect(address).await?; - - let tls_connector = TlsConnector::from(client_config); - - // Hostname for SNI (Server Name Indication) - // throw away the port number if there is one (e.g. "localhost:8080" -> - // "localhost") - let address = address.split(":").next().context("splitting address")?; - let dns_name = - ServerName::try_from(address.to_owned()).context("trying to convert address to SNI")?; - - // Perform the TLS handshake to establish a secure connection - let tls_stream: TlsStream = tls_connector.connect(dns_name, stream).await?; - - Ok(tls_stream) -} +// async fn prepare_tls_stream_for_writing( +// address: &str, +// client_config: Arc, +// ) -> eyre::Result> { +// // Create a TCP connection +// let stream = TcpStream::connect(address).await?; +// +// let tls_connector = TlsConnector::from(client_config); +// +// // Hostname for SNI (Server Name Indication) +// // throw away the port number if there is one (e.g. "localhost:8080" -> +// // "localhost") +// let address = address.split(":").next().context("splitting address")?; +// let dns_name = +// ServerName::try_from(address.to_owned()).context("trying to convert +// address to SNI")?; +// +// // Perform the TLS handshake to establish a secure connection +// let tls_stream: TlsStream = tls_connector.connect(dns_name, +// stream).await?; +// +// Ok(tls_stream) +// } #[tokio::main] async fn main() -> eyre::Result<()> { @@ -73,19 +74,21 @@ async fn main() -> eyre::Result<()> { // read the trusted cert let mut root_cert_store = rustls::RootCertStore::empty(); root_cert_store.extend(webpki_roots::TLS_SERVER_ROOTS.iter().cloned()); - let client_config = Arc::new( + let _ = Arc::new( ClientConfig::builder() .with_root_certificates(root_cert_store) .with_no_client_auth(), ); - let mut server1 = prepare_tls_stream_for_writing(&args.server1, client_config.clone()).await?; - let mut server2 = prepare_tls_stream_for_writing(&args.server2, client_config.clone()).await?; - let mut server3 = prepare_tls_stream_for_writing(&args.server3, client_config).await?; + // let mut server1 = prepare_tls_stream_for_writing(&args.server1, + // client_config.clone()).await?; let mut server2 = + // prepare_tls_stream_for_writing(&args.server2, client_config.clone()).await?; + // let mut server3 = prepare_tls_stream_for_writing(&args.server3, + // client_config).await?; - // let mut server1 = TcpStream::connect(&args.server1).await?; - // let mut server2 = TcpStream::connect(&args.server2).await?; - // let mut server3 = TcpStream::connect(&args.server3).await?; + let mut server1 = TcpStream::connect(&args.server1).await?; + let mut server2 = TcpStream::connect(&args.server2).await?; + let mut server3 = TcpStream::connect(&args.server3).await?; tracing::info!("Connecting to servers and syncing migration task parameters..."); server1.write_u8(args.party_id).await?; @@ -236,9 +239,9 @@ async fn main() -> eyre::Result<()> { async fn send_batch_and_wait_for_ack( party_id: u8, - server1: &mut TlsStream, - server2: &mut TlsStream, - server3: &mut TlsStream, + server1: &mut TcpStream, + server2: &mut TcpStream, + server3: &mut TcpStream, batch: &Vec<( TwoToThreeIrisCodeMessage, TwoToThreeIrisCodeMessage, @@ -332,7 +335,7 @@ async fn send_batch_and_wait_for_ack( Ok(()) } -async fn wait_for_ack(server: &mut TlsStream) -> eyre::Result<()> { +async fn wait_for_ack(server: &mut TcpStream) -> eyre::Result<()> { match timeout(Duration::from_secs(10), server.read_u8()).await { Ok(Ok(1)) => { // Ack received successfully