From 892a82752784e77e549c750867fefc25b61eda14 Mon Sep 17 00:00:00 2001 From: th4s Date: Wed, 11 Sep 2024 12:16:26 +0200 Subject: [PATCH] Set `ProtocolConfigValidator` where needed. --- crates/examples/discord/discord_dm.rs | 4 ---- crates/examples/interactive/interactive.rs | 18 +++++++++++------ crates/examples/src/lib.rs | 20 +++++++++++++++++-- crates/examples/twitter/twitter_dm.rs | 4 ---- .../tests/defer_decryption.rs | 16 +++++++++++++-- crates/tests-integration/tests/notarize.rs | 16 +++++++++++++-- crates/tests-integration/tests/verify.rs | 9 ++++++++- 7 files changed, 66 insertions(+), 21 deletions(-) diff --git a/crates/examples/discord/discord_dm.rs b/crates/examples/discord/discord_dm.rs index 722bc17ac6..3f4bffee8f 100644 --- a/crates/examples/discord/discord_dm.rs +++ b/crates/examples/discord/discord_dm.rs @@ -21,10 +21,6 @@ const SERVER_DOMAIN: &str = "discord.com"; const NOTARY_HOST: &str = "127.0.0.1"; const NOTARY_PORT: u16 = 7047; -// P/S: If the following limits are increased, please ensure max-transcript-size of -// the notary server's config (../../notary/server) is increased too, where -// max-transcript-size = MAX_SENT_DATA + MAX_RECV_DATA -// // Maximum number of bytes that can be sent from prover to server const MAX_SENT_DATA: usize = 1 << 12; // Maximum number of bytes that can be received by prover from server diff --git a/crates/examples/interactive/interactive.rs b/crates/examples/interactive/interactive.rs index 497c0191ce..7ad9be4b22 100644 --- a/crates/examples/interactive/interactive.rs +++ b/crates/examples/interactive/interactive.rs @@ -1,7 +1,7 @@ use http_body_util::Empty; use hyper::{body::Bytes, Request, StatusCode, Uri}; use hyper_util::rt::TokioIo; -use tlsn_common::config::ProtocolConfig; +use tlsn_common::config::{ProtocolConfig, ProtocolConfigValidator}; use tlsn_core::{proof::SessionInfo, Direction, RedactedTranscript}; use tlsn_prover::tls::{state::Prove, Prover, ProverConfig}; use tlsn_verifier::tls::{Verifier, VerifierConfig}; @@ -12,10 +12,6 @@ use tracing::instrument; const SECRET: &str = "TLSNotary's private key 🤡"; const SERVER_DOMAIN: &str = "example.com"; -// P/S: If the following limits are increased, please ensure max-transcript-size of -// the notary server's config (../../notary/server) is increased too, where -// max-transcript-size = MAX_SENT_DATA + MAX_RECV_DATA -// // Maximum number of bytes that can be sent from prover to server const MAX_SENT_DATA: usize = 1 << 12; // Maximum number of bytes that can be received by prover from server @@ -130,7 +126,17 @@ async fn verifier( id: &str, ) -> (RedactedTranscript, RedactedTranscript, SessionInfo) { // Setup Verifier. - let verifier_config = VerifierConfig::builder().id(id).build().unwrap(); + let config_validator = ProtocolConfigValidator::builder() + .max_sent_data(MAX_SENT_DATA) + .max_recv_data(MAX_RECV_DATA) + .build() + .unwrap(); + + let verifier_config = VerifierConfig::builder() + .id(id) + .protocol_config_validator(config_validator) + .build() + .unwrap(); let verifier = Verifier::new(verifier_config); // Verify MPC-TLS and wait for (redacted) data. diff --git a/crates/examples/src/lib.rs b/crates/examples/src/lib.rs index a90b707bad..ff59f313c0 100644 --- a/crates/examples/src/lib.rs +++ b/crates/examples/src/lib.rs @@ -1,7 +1,13 @@ use elliptic_curve::pkcs8::DecodePrivateKey; use futures::{AsyncRead, AsyncWrite}; +use tlsn_common::config::ProtocolConfigValidator; use tlsn_verifier::tls::{Verifier, VerifierConfig}; +// Maximum number of bytes that can be sent from prover to server +const MAX_SENT_DATA: usize = 1 << 12; +// Maximum number of bytes that can be received by prover from server +const MAX_RECV_DATA: usize = 1 << 14; + /// Runs a simple Notary with the provided connection to the Prover. pub async fn run_notary(conn: T) { // Load the notary signing key @@ -11,9 +17,19 @@ pub async fn run_notary(conn .unwrap(); let signing_key = p256::ecdsa::SigningKey::from_pkcs8_pem(signing_key_str).unwrap(); - // Setup default config. Normally a different ID would be generated + // Setup the config. Normally a different ID would be generated // for each notarization. - let config = VerifierConfig::builder().id("example").build().unwrap(); + let config_validator = ProtocolConfigValidator::builder() + .max_sent_data(MAX_SENT_DATA) + .max_recv_data(MAX_RECV_DATA) + .build() + .unwrap(); + + let config = VerifierConfig::builder() + .id("example") + .protocol_config_validator(config_validator) + .build() + .unwrap(); Verifier::new(config) .notarize::<_, p256::ecdsa::Signature>(conn, &signing_key) diff --git a/crates/examples/twitter/twitter_dm.rs b/crates/examples/twitter/twitter_dm.rs index ed87f3542d..ccee197a0b 100644 --- a/crates/examples/twitter/twitter_dm.rs +++ b/crates/examples/twitter/twitter_dm.rs @@ -23,10 +23,6 @@ const USER_AGENT: &str = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KH const NOTARY_HOST: &str = "127.0.0.1"; const NOTARY_PORT: u16 = 7047; -// P/S: If the following limits are increased, please ensure max-transcript-size of -// the notary server's config (../../notary/server) is increased too, where -// max-transcript-size = MAX_SENT_DATA + MAX_RECV_DATA -// // Maximum number of bytes that can be sent from prover to server const MAX_SENT_DATA: usize = 1 << 12; // Maximum number of bytes that can be received by prover from server diff --git a/crates/tests-integration/tests/defer_decryption.rs b/crates/tests-integration/tests/defer_decryption.rs index 59a29ae739..0740775c9e 100644 --- a/crates/tests-integration/tests/defer_decryption.rs +++ b/crates/tests-integration/tests/defer_decryption.rs @@ -1,4 +1,4 @@ -use tlsn_common::config::ProtocolConfig; +use tlsn_common::config::{ProtocolConfig, ProtocolConfigValidator}; use tlsn_prover::tls::{Prover, ProverConfig}; use tlsn_server_fixture::bind; use tlsn_server_fixture_certs::{CA_CERT_DER, SERVER_DOMAIN}; @@ -83,7 +83,19 @@ async fn prover(notary_socke #[instrument(skip(socket))] async fn notary(socket: T) { - let verifier = Verifier::new(VerifierConfig::builder().id("test").build().unwrap()); + let config_validator = ProtocolConfigValidator::builder() + .max_sent_data(MAX_SENT_DATA) + .max_recv_data(MAX_RECV_DATA) + .build() + .unwrap(); + + let verifier = Verifier::new( + VerifierConfig::builder() + .id("test") + .protocol_config_validator(config_validator) + .build() + .unwrap(), + ); let signing_key = p256::ecdsa::SigningKey::from_bytes(&[1u8; 32].into()).unwrap(); _ = verifier diff --git a/crates/tests-integration/tests/notarize.rs b/crates/tests-integration/tests/notarize.rs index b64d37ca10..583514e89d 100644 --- a/crates/tests-integration/tests/notarize.rs +++ b/crates/tests-integration/tests/notarize.rs @@ -1,4 +1,4 @@ -use tlsn_common::config::ProtocolConfig; +use tlsn_common::config::{ProtocolConfig, ProtocolConfigValidator}; use tlsn_prover::tls::{Prover, ProverConfig}; use tlsn_server_fixture::bind; use tlsn_server_fixture_certs::{CA_CERT_DER, SERVER_DOMAIN}; @@ -101,7 +101,19 @@ async fn prover(notary_socke #[instrument(skip(socket))] async fn notary(socket: T) { - let verifier = Verifier::new(VerifierConfig::builder().id("test").build().unwrap()); + let config_validator = ProtocolConfigValidator::builder() + .max_sent_data(MAX_SENT_DATA) + .max_recv_data(MAX_RECV_DATA) + .build() + .unwrap(); + + let verifier = Verifier::new( + VerifierConfig::builder() + .id("test") + .protocol_config_validator(config_validator) + .build() + .unwrap(), + ); let signing_key = p256::ecdsa::SigningKey::from_bytes(&[1u8; 32].into()).unwrap(); _ = verifier diff --git a/crates/tests-integration/tests/verify.rs b/crates/tests-integration/tests/verify.rs index b1a9b239c5..f924771359 100644 --- a/crates/tests-integration/tests/verify.rs +++ b/crates/tests-integration/tests/verify.rs @@ -1,5 +1,5 @@ use tls_core::{anchors::RootCertStore, verify::WebPkiVerifier}; -use tlsn_common::config::ProtocolConfig; +use tlsn_common::config::{ProtocolConfig, ProtocolConfigValidator}; use tlsn_core::{proof::SessionInfo, Direction, RedactedTranscript}; use tlsn_prover::tls::{Prover, ProverConfig}; use tlsn_server_fixture::bind; @@ -120,8 +120,15 @@ async fn verifier( .add(&tls_core::key::Certificate(CA_CERT_DER.to_vec())) .unwrap(); + let config_validator = ProtocolConfigValidator::builder() + .max_sent_data(MAX_SENT_DATA) + .max_recv_data(MAX_RECV_DATA) + .build() + .unwrap(); + let verifier_config = VerifierConfig::builder() .id("test") + .protocol_config_validator(config_validator) .cert_verifier(WebPkiVerifier::new(root_store, None)) .build() .unwrap();