Use swapi.dev as TLS server instead of notary.pse.dev

This commit is contained in:
Hendrik Eeckhaut
2024-04-05 14:56:57 +02:00
parent 4b29bf854a
commit 1643bdb4fb
3 changed files with 17 additions and 10 deletions

View File

@@ -19,7 +19,7 @@ const VERIFIER_PORT: u16 = 9816;
const SECRET: &str = "TLSNotary's private key 🤡";
/// Make sure the following url's domain is the same as SERVER_DOMAIN on the verifier side
const SERVER_URL: &str = "https://notary.pse.dev/info";
const SERVER_URL: &str = "https://swapi.dev/api/people/1";
/// Make sure this is the same on the verifier side
const VERIFICATION_SESSION_ID: &str = "interactive-verifier-demo";
@@ -92,6 +92,7 @@ async fn prover<T: AsyncWrite + AsyncRead + Send + Unpin + 'static>(
.unwrap();
// Connect to TLS Server.
info!("Connect to TLS Server");
let tls_client_socket = tokio::net::TcpStream::connect((server_domain, server_port))
.await
.unwrap();
@@ -109,6 +110,7 @@ async fn prover<T: AsyncWrite + AsyncRead + Send + Unpin + 'static>(
let connection_task = tokio::spawn(connection.without_shutdown());
// MPC-TLS: Send Request and wait for Response.
info!("Send Request and wait for Response");
let request = Request::builder()
.uri(uri.clone())
.header("Host", server_domain)
@@ -119,19 +121,24 @@ async fn prover<T: AsyncWrite + AsyncRead + Send + Unpin + 'static>(
.unwrap();
let response = request_sender.send_request(request).await.unwrap();
debug!("TLS response: {:?}", response);
assert!(response.status() == StatusCode::OK);
// Close TLS Connection.
let tls_connection = connection_task.await.unwrap().unwrap().io.into_inner();
tls_connection.compat().close().await.unwrap();
// let tls_connection = connection_task.await.unwrap().unwrap().io.into_inner();
// debug!("TLS connection: {:?}", tls_connection);
// tls_connection.compat().close().await.unwrap();
// info!("TLS Connection closed");
// Create proof for the Verifier.
info!("Create proof for the Verifier");
let mut prover = prover_task.await.unwrap().unwrap().start_prove();
redact_and_reveal_received_data(&mut prover);
redact_and_reveal_sent_data(&mut prover);
prover.prove().await.unwrap();
// Finalize.
info!("Finalize prover");
prover.finalize().await.unwrap()
}
@@ -139,12 +146,12 @@ async fn prover<T: AsyncWrite + AsyncRead + Send + Unpin + 'static>(
fn redact_and_reveal_received_data(prover: &mut Prover<Prove>) {
let recv_transcript_len = prover.recv_transcript().data().len();
// Get the commit hash from the received data.
// Get the homeworld from the received data.
let received_string = String::from_utf8(prover.recv_transcript().data().to_vec()).unwrap();
let re = Regex::new(r#""gitCommitHash"\s?:\s?"(.*?)""#).unwrap();
let re = Regex::new(r#""homeworld"\s?:\s?"(.*?)""#).unwrap();
let commit_hash_match = re.captures(&received_string).unwrap().get(1).unwrap();
// Reveal everything except for the commit hash.
// Reveal everything except for the homeworld.
_ = prover.reveal(0..commit_hash_match.start(), Direction::Received);
_ = prover.reveal(
commit_hash_match.end()..recv_transcript_len,

View File

@@ -139,9 +139,10 @@ async fn verifier<T: AsyncWrite + AsyncRead + Send + Unpin + 'static>(
// Check received data: check json and version number.
let response = String::from_utf8(received.data().to_vec())
.map_err(|err| eyre!("Failed to parse received data: {err}"))?;
debug!("Received data: {:?}", response);
response
.find("BEGIN PUBLIC KEY")
.ok_or_else(|| eyre!("Verification failed: invalid public key in JSON response"))?;
.find("eye_color")
.ok_or_else(|| eyre!("Verification failed: missing eye_color in received data"))?;
// Check Session info: server name.
if session_info.server_name.as_str() != server_domain {
return Err(eyre!("Verification failed: server name mismatches"));

View File

@@ -7,11 +7,10 @@ const VERIFIER_HOST: &str = "0.0.0.0";
const VERIFIER_PORT: u16 = 9816;
/// Make sure the following domain is the same in SERVER_URL on the prover side
const SERVER_DOMAIN: &str = "notary.pse.dev";
const SERVER_DOMAIN: &str = "swapi.dev";
/// Make sure this is the same on the prover side
const VERIFICATION_SESSION_ID: &str = "interactive-verifier-demo";
#[tokio::main]
async fn main() -> Result<(), eyre::ErrReport> {
tracing_subscriber::registry()