Skip to content

Commit

Permalink
Set ProtocolConfigValidator where needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
th4s committed Sep 11, 2024
1 parent 48f3d97 commit 892a827
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 21 deletions.
4 changes: 0 additions & 4 deletions crates/examples/discord/discord_dm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 12 additions & 6 deletions crates/examples/interactive/interactive.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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
Expand Down Expand Up @@ -130,7 +126,17 @@ async fn verifier<T: AsyncWrite + AsyncRead + Send + Sync + Unpin + 'static>(
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.
Expand Down
20 changes: 18 additions & 2 deletions crates/examples/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<T: AsyncWrite + AsyncRead + Send + Unpin + 'static>(conn: T) {
// Load the notary signing key
Expand All @@ -11,9 +17,19 @@ pub async fn run_notary<T: AsyncWrite + AsyncRead + Send + Unpin + 'static>(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)
Expand Down
4 changes: 0 additions & 4 deletions crates/examples/twitter/twitter_dm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions crates/tests-integration/tests/defer_decryption.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -83,7 +83,19 @@ async fn prover<T: AsyncWrite + AsyncRead + Send + Unpin + 'static>(notary_socke

#[instrument(skip(socket))]
async fn notary<T: AsyncWrite + AsyncRead + Send + Sync + Unpin + 'static>(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
Expand Down
16 changes: 14 additions & 2 deletions crates/tests-integration/tests/notarize.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -101,7 +101,19 @@ async fn prover<T: AsyncWrite + AsyncRead + Send + Unpin + 'static>(notary_socke

#[instrument(skip(socket))]
async fn notary<T: AsyncWrite + AsyncRead + Send + Sync + Unpin + 'static>(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
Expand Down
9 changes: 8 additions & 1 deletion crates/tests-integration/tests/verify.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -120,8 +120,15 @@ async fn verifier<T: AsyncWrite + AsyncRead + Send + Sync + Unpin + 'static>(
.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();
Expand Down

0 comments on commit 892a827

Please sign in to comment.