diff --git a/ipa-core/src/bin/helper.rs b/ipa-core/src/bin/helper.rs index fca149caf..56fdd904f 100644 --- a/ipa-core/src/bin/helper.rs +++ b/ipa-core/src/bin/helper.rs @@ -18,7 +18,7 @@ use ipa_core::{ error::BoxError, executor::IpaRuntime, helpers::HelperIdentity, - net::{ClientIdentity, MpcHelperClient, MpcHttpTransport, ShardHttpTransport}, + net::{ClientIdentity, IpaHttpClient, MpcHttpTransport, ShardHttpTransport}, sharding::ShardIndex, AppConfig, AppSetup, NonZeroU32PowerOfTwo, }; @@ -167,7 +167,7 @@ async fn server(args: ServerArgs, logging_handle: LoggingHandle) -> Result<(), B // --- let http_runtime = new_http_runtime(&logging_handle); - let clients = MpcHelperClient::from_conf( + let clients = IpaHttpClient::from_conf( &IpaRuntime::from_tokio_runtime(&http_runtime), &network_config, &identity, diff --git a/ipa-core/src/bin/report_collector.rs b/ipa-core/src/bin/report_collector.rs index 38750e578..126004fcc 100644 --- a/ipa-core/src/bin/report_collector.rs +++ b/ipa-core/src/bin/report_collector.rs @@ -22,7 +22,7 @@ use ipa_core::{ config::{KeyRegistries, NetworkConfig}, ff::{boolean_array::BA32, FieldType}, helpers::query::{DpMechanism, IpaQueryConfig, QueryConfig, QuerySize, QueryType}, - net::{Helper, MpcHelperClient}, + net::{Helper, IpaHttpClient}, report::{EncryptedOprfReportStreams, DEFAULT_KEY_ID}, test_fixture::{ ipa::{ipa_in_the_clear, CappingOrder, IpaSecurityModel, TestRawDataRecord}, @@ -333,7 +333,7 @@ async fn ipa( args: &Args, security_model: IpaSecurityModel, ipa_query_config: IpaQueryConfig, - helper_clients: &[MpcHelperClient; 3], + helper_clients: &[IpaHttpClient; 3], encrypted_inputs: &EncryptedInputs, ) -> Result<(), Box> { let query_type = get_query_type(security_model, ipa_query_config); @@ -383,7 +383,7 @@ async fn ipa_test( network: &NetworkConfig, security_model: IpaSecurityModel, ipa_query_config: IpaQueryConfig, - helper_clients: &[MpcHelperClient; 3], + helper_clients: &[IpaHttpClient; 3], ) -> Result<(), Box> { let input = InputSource::from(&args.input); let query_type = get_query_type(security_model, ipa_query_config); diff --git a/ipa-core/src/bin/test_mpc.rs b/ipa-core/src/bin/test_mpc.rs index 9da4afbb2..1f8484ac7 100644 --- a/ipa-core/src/bin/test_mpc.rs +++ b/ipa-core/src/bin/test_mpc.rs @@ -13,7 +13,7 @@ use ipa_core::{ QueryConfig, QueryType::{TestAddInPrimeField, TestMultiply}, }, - net::MpcHelperClient, + net::{Helper, IpaHttpClient}, secret_sharing::{replicated::semi_honest::AdditiveShare, IntoShares}, }; @@ -113,7 +113,7 @@ async fn main() -> Result<(), Box> { Ok(()) } -async fn multiply_in_field(args: &Args, helper_clients: &[MpcHelperClient; 3]) +async fn multiply_in_field(args: &Args, helper_clients: &[IpaHttpClient; 3]) where F: Field + U128Conversions + IntoShares>, ::Size: Add<::Size>, @@ -130,14 +130,14 @@ where validate(&expected, &actual); } -async fn multiply(args: &Args, helper_clients: &[MpcHelperClient; 3]) { +async fn multiply(args: &Args, helper_clients: &[IpaHttpClient; 3]) { match args.input.field { FieldType::Fp31 => multiply_in_field::(args, helper_clients).await, FieldType::Fp32BitPrime => multiply_in_field::(args, helper_clients).await, }; } -async fn add_in_field(args: &Args, helper_clients: &[MpcHelperClient; 3]) +async fn add_in_field(args: &Args, helper_clients: &[IpaHttpClient; 3]) where F: Field + U128Conversions + IntoShares>, ::Size: Add<::Size>, @@ -159,13 +159,13 @@ where validate(&vec![expected], &vec![actual]); } -async fn add(args: &Args, helper_clients: &[MpcHelperClient; 3]) { +async fn add(args: &Args, helper_clients: &[IpaHttpClient; 3]) { match args.input.field { FieldType::Fp31 => add_in_field::(args, helper_clients).await, FieldType::Fp32BitPrime => add_in_field::(args, helper_clients).await, }; } -async fn sharded_shuffle(_args: &Args, _helper_clients: &[MpcHelperClient; 3]) { +async fn sharded_shuffle(_args: &Args, _helper_clients: &[IpaHttpClient; 3]) { unimplemented!() } diff --git a/ipa-core/src/cli/playbook/add.rs b/ipa-core/src/cli/playbook/add.rs index 46967f69a..eafa1da8d 100644 --- a/ipa-core/src/cli/playbook/add.rs +++ b/ipa-core/src/cli/playbook/add.rs @@ -9,7 +9,7 @@ use typenum::Unsigned; use crate::{ ff::{Field, Serializable}, helpers::{query::QueryInput, BodyStream}, - net::MpcHelperClient, + net::{Helper, IpaHttpClient}, protocol::QueryId, secret_sharing::{replicated::semi_honest::AdditiveShare as Replicated, IntoShares}, test_fixture::Reconstruct, @@ -19,7 +19,7 @@ use crate::{ #[allow(clippy::missing_panics_doc, clippy::disallowed_methods)] pub async fn secure_add( input: impl Iterator, - clients: &[MpcHelperClient; 3], + clients: &[IpaHttpClient; 3], query_id: QueryId, ) -> F where diff --git a/ipa-core/src/cli/playbook/ipa.rs b/ipa-core/src/cli/playbook/ipa.rs index 5f56911f0..6f3691306 100644 --- a/ipa-core/src/cli/playbook/ipa.rs +++ b/ipa-core/src/cli/playbook/ipa.rs @@ -23,7 +23,7 @@ use crate::{ BodyStream, }, hpke::PublicKeyRegistry, - net::MpcHelperClient, + net::{Helper, IpaHttpClient}, protocol::{ipa_prf::OPRFIPAInputRow, QueryId}, query::QueryStatus, report::{KeyIdentifier, OprfReport}, @@ -37,7 +37,7 @@ use crate::{ /// If report encryption fails pub async fn playbook_oprf_ipa( records: Vec, - clients: &[MpcHelperClient; 3], + clients: &[IpaHttpClient; 3], query_id: QueryId, query_config: IpaQueryConfig, encryption: Option<(KeyIdentifier, [&KR; 3])>, @@ -101,7 +101,7 @@ where pub async fn run_query_and_validate( inputs: [BodyStream; 3], query_size: usize, - clients: &[MpcHelperClient; 3], + clients: &[IpaHttpClient; 3], query_id: QueryId, query_config: IpaQueryConfig, ) -> IpaQueryResult diff --git a/ipa-core/src/cli/playbook/mod.rs b/ipa-core/src/cli/playbook/mod.rs index 4b5164f56..0d679771a 100644 --- a/ipa-core/src/cli/playbook/mod.rs +++ b/ipa-core/src/cli/playbook/mod.rs @@ -20,7 +20,7 @@ use crate::{ executor::IpaRuntime, ff::boolean_array::{BA20, BA3, BA8}, helpers::query::DpMechanism, - net::{ClientIdentity, Helper, MpcHelperClient}, + net::{ClientIdentity, Helper, IpaHttpClient}, protocol::{dp::NoiseParams, ipa_prf::oprf_padding::insecure::OPRFPaddingDp}, }; @@ -194,7 +194,7 @@ pub async fn make_clients( network_path: Option<&Path>, scheme: Scheme, wait: usize, -) -> ([MpcHelperClient; 3], NetworkConfig) { +) -> ([IpaHttpClient; 3], NetworkConfig) { let mut wait = wait; let network = if let Some(path) = network_path { NetworkConfig::from_toml_str(&fs::read_to_string(path).unwrap()).unwrap() @@ -212,8 +212,7 @@ pub async fn make_clients( // Note: This closure is only called when the selected action uses clients. - let clients = - MpcHelperClient::from_conf(&IpaRuntime::current(), &network, &ClientIdentity::None); + let clients = IpaHttpClient::from_conf(&IpaRuntime::current(), &network, &ClientIdentity::None); while wait > 0 && !clients_ready(&clients).await { tracing::debug!("waiting for servers to come up"); sleep(Duration::from_secs(1)).await; @@ -222,7 +221,7 @@ pub async fn make_clients( (clients, network) } -async fn clients_ready(clients: &[MpcHelperClient; 3]) -> bool { +async fn clients_ready(clients: &[IpaHttpClient; 3]) -> bool { clients[0].echo("").await.is_ok() && clients[1].echo("").await.is_ok() && clients[2].echo("").await.is_ok() diff --git a/ipa-core/src/cli/playbook/multiply.rs b/ipa-core/src/cli/playbook/multiply.rs index 2ef5700db..ec777005a 100644 --- a/ipa-core/src/cli/playbook/multiply.rs +++ b/ipa-core/src/cli/playbook/multiply.rs @@ -9,7 +9,7 @@ use typenum::Unsigned; use crate::{ ff::{Field, Serializable}, helpers::{query::QueryInput, BodyStream}, - net::MpcHelperClient, + net::{Helper, IpaHttpClient}, protocol::QueryId, secret_sharing::{replicated::semi_honest::AdditiveShare as Replicated, IntoShares}, test_fixture::Reconstruct, @@ -21,7 +21,7 @@ use crate::{ pub async fn secure_mul( // I couldn't make `share` work with `&[(F, F)]` input: Vec<(F, F)>, - clients: &[MpcHelperClient; 3], + clients: &[IpaHttpClient; 3], query_id: QueryId, ) -> Vec where diff --git a/ipa-core/src/net/client/mod.rs b/ipa-core/src/net/client/mod.rs index 0b47fb03e..9de581fbb 100644 --- a/ipa-core/src/net/client/mod.rs +++ b/ipa-core/src/net/client/mod.rs @@ -169,13 +169,16 @@ async fn response_to_bytes(resp: ResponseFromEndpoint) -> Result { Ok(resp.into_body().collect().await?.to_bytes()) } +/// HTTP Client for calls to IPA hosts. It supports calls from Report Collector to Helper Network, +/// from one Helper to another Helper and from one Shard to another Shard. Handles authentication. +/// /// TODO: we need a client that can be used by any system that is not aware of the internals /// of the helper network. That means that create query and send inputs API need to be /// separated from prepare/step data etc. /// TODO: It probably isn't necessary to always use `[MpcHelperClient; 3]`. Instead, a single /// client can be configured to talk to all three helpers. #[derive(Debug, Clone)] -pub struct MpcHelperClient { +pub struct IpaHttpClient { client: Client, Body>, scheme: uri::Scheme, authority: uri::Authority, @@ -183,7 +186,7 @@ pub struct MpcHelperClient { _restriction: PhantomData, } -impl MpcHelperClient { +impl IpaHttpClient { /// Create a new client with the given configuration /// /// `identity`, if present, configures whether and how the client will authenticate to the server @@ -371,7 +374,7 @@ impl MpcHelperClient { } } -impl MpcHelperClient { +impl IpaHttpClient { /// Create a set of clients for the MPC helpers in the supplied helper network configuration. /// /// This function returns a set of three clients, which may be used to talk to each of the @@ -469,7 +472,7 @@ impl MpcHelperClient { } } -impl MpcHelperClient { +impl IpaHttpClient { /// This is a mirror of [`MpcHelperClient::from_config`] but for Shards. This creates /// set of Shard clients in the supplied helper network configuration, which can be used to /// talk to each of the shards in this helper. @@ -544,7 +547,7 @@ pub(crate) mod tests { certificate: None, hpke_config: None, }; - let client = MpcHelperClient::new( + let client = IpaHttpClient::new( IpaRuntime::current(), &ClientConfig::default(), peer_config, @@ -573,7 +576,7 @@ pub(crate) mod tests { where ClientOut: Eq + Debug, ClientFut: Future, - ClientF: Fn(MpcHelperClient) -> ClientFut, + ClientF: Fn(IpaHttpClient) -> ClientFut, HandlerF: Fn() -> Arc>, { let mut results = Vec::with_capacity(4); diff --git a/ipa-core/src/net/mod.rs b/ipa-core/src/net/mod.rs index c71c609ea..ea9d9194f 100644 --- a/ipa-core/src/net/mod.rs +++ b/ipa-core/src/net/mod.rs @@ -23,7 +23,7 @@ mod server; pub mod test; mod transport; -pub use client::{ClientIdentity, MpcHelperClient}; +pub use client::{ClientIdentity, IpaHttpClient}; pub use error::Error; pub use server::{MpcHelperServer, TracingSpanMaker}; pub use transport::{HttpTransport, MpcHttpTransport, ShardHttpTransport}; diff --git a/ipa-core/src/net/test.rs b/ipa-core/src/net/test.rs index e39c0c109..ea98dbdc5 100644 --- a/ipa-core/src/net/test.rs +++ b/ipa-core/src/net/test.rs @@ -26,7 +26,7 @@ use crate::{ executor::{IpaJoinHandle, IpaRuntime}, helpers::{HandlerBox, HelperIdentity, RequestHandler, TransportIdentity}, hpke::{Deserializable as _, IpaPublicKey}, - net::{ClientIdentity, Helper, MpcHelperClient, MpcHelperServer}, + net::{ClientIdentity, Helper, IpaHttpClient, MpcHelperServer}, sharding::{ShardIndex, ShardedHelperIdentity}, sync::Arc, test_fixture::metrics::MetricsHandle, @@ -394,7 +394,7 @@ pub struct TestServer { pub handle: IpaJoinHandle<()>, pub transport: MpcHttpTransport, pub server: MpcHelperServer, - pub client: MpcHelperClient, + pub client: IpaHttpClient, pub request_handler: Option>>, } @@ -471,7 +471,7 @@ impl TestServerBuilder { .build(); let leaders_ring = test_config.rings.pop().unwrap(); let first_server = leaders_ring.servers.into_iter().next().unwrap(); - let clients = MpcHelperClient::from_conf( + let clients = IpaHttpClient::from_conf( &IpaRuntime::current(), &leaders_ring.network, &identities.helper.clone_with_key(), diff --git a/ipa-core/src/net/transport.rs b/ipa-core/src/net/transport.rs index 0aedcb937..7075a1bf3 100644 --- a/ipa-core/src/net/transport.rs +++ b/ipa-core/src/net/transport.rs @@ -20,7 +20,7 @@ use crate::{ NoResourceIdentifier, NoStep, QueryIdBinding, ReceiveRecords, RequestHandler, RouteParams, StepBinding, StreamCollection, Transport, TransportIdentity, }, - net::{client::MpcHelperClient, error::Error, MpcHelperServer}, + net::{client::IpaHttpClient, error::Error, MpcHelperServer}, protocol::{Gate, QueryId}, sharding::ShardIndex, sync::Arc, @@ -30,7 +30,7 @@ use crate::{ pub struct HttpTransport { http_runtime: IpaRuntime, identity: F::Identity, - clients: Vec>, + clients: Vec>, record_streams: StreamCollection, handler: Option>, } @@ -196,7 +196,7 @@ impl MpcHttpTransport { identity: HelperIdentity, server_config: ServerConfig, network_config: NetworkConfig, - clients: &[MpcHelperClient; 3], + clients: &[IpaHttpClient; 3], handler: Option>, ) -> (Self, MpcHelperServer) { let transport = Self { @@ -292,7 +292,7 @@ impl ShardHttpTransport { identity: ShardIndex, server_config: ServerConfig, network_config: NetworkConfig, - clients: Vec>, + clients: Vec>, handler: Option>, ) -> (Self, MpcHelperServer) { let transport = Self { @@ -458,7 +458,7 @@ mod tests { let identities = ClientIdentities::new(conf.disable_https, sid); // Ring config - let clients = MpcHelperClient::from_conf( + let clients = IpaHttpClient::from_conf( &IpaRuntime::current(), &leaders_ring.network, &identities.helper, @@ -476,7 +476,7 @@ mod tests { let helper_shards = conf.get_shards_for_helper(id); let addr_shard = helper_shards.get_first_shard(); let shard_network_config = helper_shards.network.clone(); - let shard_clients = MpcHelperClient::::shards_from_conf( + let shard_clients = IpaHttpClient::::shards_from_conf( &IpaRuntime::current(), &shard_network_config, &identities.shard, @@ -512,7 +512,7 @@ mod tests { } async fn test_three_helpers(conf: TestConfig) { - let clients = MpcHelperClient::from_conf( + let clients = IpaHttpClient::from_conf( &IpaRuntime::current(), &conf.leaders_ring().network, &ClientIdentity::None, @@ -524,7 +524,7 @@ mod tests { #[tokio::test(flavor = "multi_thread")] async fn happy_case_twice() { let conf = TestConfigBuilder::default().build(); - let clients = MpcHelperClient::from_conf( + let clients = IpaHttpClient::from_conf( &IpaRuntime::current(), &conf.leaders_ring().network, &ClientIdentity::None, @@ -535,7 +535,7 @@ mod tests { test_multiply(&clients).await; } - async fn test_multiply(clients: &[MpcHelperClient; 3]) { + async fn test_multiply(clients: &[IpaHttpClient; 3]) { const SZ: usize = as Serializable>::Size::USIZE; // send a create query command