Skip to content

Commit

Permalink
no tls
Browse files Browse the repository at this point in the history
  • Loading branch information
carlomazzaferro committed Sep 20, 2024
1 parent f2bd9fc commit 78fa47b
Showing 1 changed file with 38 additions and 35 deletions.
73 changes: 38 additions & 35 deletions iris-mpc-upgrade/src/bin/tcp_upgrade_client.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -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() {
Expand All @@ -39,27 +38,29 @@ fn install_tracing() {
.init();
}

async fn prepare_tls_stream_for_writing(
address: &str,
client_config: Arc<ClientConfig>,
) -> eyre::Result<TlsStream<TcpStream>> {
// 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<TcpStream> = tls_connector.connect(dns_name, stream).await?;

Ok(tls_stream)
}
// async fn prepare_tls_stream_for_writing(
// address: &str,
// client_config: Arc<ClientConfig>,
// ) -> eyre::Result<TlsStream<TcpStream>> {
// // 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<TcpStream> = tls_connector.connect(dns_name,
// stream).await?;
//
// Ok(tls_stream)
// }

#[tokio::main]
async fn main() -> eyre::Result<()> {
Expand All @@ -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?;
Expand Down Expand Up @@ -236,9 +239,9 @@ async fn main() -> eyre::Result<()> {

async fn send_batch_and_wait_for_ack(
party_id: u8,
server1: &mut TlsStream<TcpStream>,
server2: &mut TlsStream<TcpStream>,
server3: &mut TlsStream<TcpStream>,
server1: &mut TcpStream,
server2: &mut TcpStream,
server3: &mut TcpStream,
batch: &Vec<(
TwoToThreeIrisCodeMessage,
TwoToThreeIrisCodeMessage,
Expand Down Expand Up @@ -332,7 +335,7 @@ async fn send_batch_and_wait_for_ack(
Ok(())
}

async fn wait_for_ack(server: &mut TlsStream<TcpStream>) -> 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
Expand Down

0 comments on commit 78fa47b

Please sign in to comment.