From a9a6ea50a3fb9f00d5e78f7e6a96728df397aa70 Mon Sep 17 00:00:00 2001 From: Christopher Chong Date: Thu, 17 Aug 2023 18:39:58 +0800 Subject: [PATCH] Modify documentation and add comments. --- tlsn/examples/Cargo.toml | 4 ++-- tlsn/examples/{notary.rs => simple_notary.rs} | 2 ++ tlsn/examples/twitter_dm.md | 22 +++++++++---------- tlsn/examples/twitter_dm.rs | 6 +++++ 4 files changed, 20 insertions(+), 14 deletions(-) rename tlsn/examples/{notary.rs => simple_notary.rs} (87%) diff --git a/tlsn/examples/Cargo.toml b/tlsn/examples/Cargo.toml index 1abdef1f90..ff8f3a8e9c 100644 --- a/tlsn/examples/Cargo.toml +++ b/tlsn/examples/Cargo.toml @@ -45,5 +45,5 @@ name = "twitter_dm" path = "twitter_dm.rs" [[example]] -name = "notary" -path = "notary.rs" +name = "simple_notary" +path = "simple_notary.rs" diff --git a/tlsn/examples/notary.rs b/tlsn/examples/simple_notary.rs similarity index 87% rename from tlsn/examples/notary.rs rename to tlsn/examples/simple_notary.rs index 57e84526a1..6955a8082a 100644 --- a/tlsn/examples/notary.rs +++ b/tlsn/examples/simple_notary.rs @@ -1,3 +1,5 @@ +/// This is a simple implementation of the notary server with minimal functionalities (without TLS, does not support WebSocket and configuration etc.) +/// For a more functional notary server implementation, please use https://github.com/tlsnotary/notary-server use std::env; use tokio::net::TcpListener; diff --git a/tlsn/examples/twitter_dm.md b/tlsn/examples/twitter_dm.md index 0bb726f847..caf7d4a532 100644 --- a/tlsn/examples/twitter_dm.md +++ b/tlsn/examples/twitter_dm.md @@ -12,28 +12,26 @@ This involves 3 steps: In this tlsn/examples folder, create a `.env` file. Then in that `.env` file, set the values of the following constants by following the format shown in this [example env file](./.env.example). -| Name | Example | -| --------------- | ------------------------------------------------------- | -| CONVERSATION_ID | `20124652-973145016511139841` | -| CLIENT_UUID | `e6f00000-cccc-dddd-bbbb-eeeeeefaaa27` | -| AUTH_TOKEN | `670ccccccbe2bbbbbbbc1025aaaaaafa55555551` | -| ACCESS_TOKEN | `AAAAAAAAAAAAAAAAAAAAANRILgAA...4puTs%3D1Zv7...WjCpTnA` | -| CSRF_TOKEN | `77d8ef46bd57f722ea7e9f...f4235a713040bfcaac1cd6909` | +| Name | Example | Location in Request Headers Section (within Network Tab of Developer Tools) | +| --------------- | ------------------------------------------------------- |---------------------------------------------------------------------------------- | +| CONVERSATION_ID | `20124652-973145016511139841` | Look for `Referer`, then extract the `ID` in `https://twitter.com/messages/` | +| CLIENT_UUID | `e6f00000-cccc-dddd-bbbb-eeeeeefaaa27` | Look for `X-Client-Uuid`, then copy the entire value | +| AUTH_TOKEN | `670ccccccbe2bbbbbbbc1025aaaaaafa55555551` | Look for `Cookie`, then extract the `token` in `;auth_token=;` | +| ACCESS_TOKEN | `AAAAAAAAAAAAAAAAAAAAANRILgAA...4puTs%3D1Zv7...WjCpTnA` | Look for `Authorization`, then extract the `token` in `Bearer ` | +| CSRF_TOKEN | `77d8ef46bd57f722ea7e9f...f4235a713040bfcaac1cd6909` | Look for `X-Csrf-Token`, then copy the entire value | -You can obtain these parameters by opening [Twitter](https://twitter.com/messages/) in your browser and accessing the message history you want to notarize. Please note that notarizing only works for short transcripts at the moment, so choose a contact with a short history. The `CONVERSATION_ID` corresponds to the last part of the URL. +You can obtain these parameters by opening [Twitter](https://twitter.com/messages/) in your browser and accessing the message history you want to notarize. Please note that notarizing only works for short transcripts at the moment, so choose a contact with a short history. -Next, open the **Developer Tools**, go to the **Network** tab, and refresh the page. Then, click on **Search** and type `uuid` as shown in the screenshot below: +Next, open the **Developer Tools**, go to the **Network** tab, and refresh the page. Then, click on **Search** and type `uuid` as shown in the screenshot below — all of these constants should be under the **Request Headers** section. Refer to the table above on where to find each of the constant value. ![Screenshot](twitter_dm_browser.png) -Repeat the process for the other constants. - ## Start the notary server ``` git clone https://github.com/tlsnotary/notary-server cd notary-server -cargo run +cargo run --release ``` The notary server will now be running in the background waiting for connections. diff --git a/tlsn/examples/twitter_dm.rs b/tlsn/examples/twitter_dm.rs index f49e2ce474..297fd2b4ad 100644 --- a/tlsn/examples/twitter_dm.rs +++ b/tlsn/examples/twitter_dm.rs @@ -1,3 +1,4 @@ +/// This prover implementation talks to the notary server implemented in https://github.com/tlsnotary/notary-server, instead of the simple_notary.rs in this example directory use eyre::Result; use futures::AsyncWriteExt; use hyper::{body::to_bytes, client::conn::Parts, Body, Request, StatusCode}; @@ -18,13 +19,17 @@ use tracing::debug; use tlsn_prover::{bind_prover, ProverConfig}; +// Setting of the application server const SERVER_DOMAIN: &str = "twitter.com"; const ROUTE: &str = "i/api/1.1/dm/conversation"; const USER_AGENT: &str = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"; +// Setting of the notary server — make sure these are the same with those in the notary-server repository used (https://github.com/tlsnotary/notary-server) const NOTARY_DOMAIN: &str = "127.0.0.1"; const NOTARY_PORT: u16 = 7047; const NOTARY_CA_CERT_PATH: &str = "./rootCA.crt"; + +// Configuration of notarization const NOTARY_MAX_TRANSCRIPT_SIZE: usize = 16384; /// Response object of the /session API @@ -90,6 +95,7 @@ async fn main() { .unwrap(); let notary_tls_socket = notary_connector + // Require the domain name of notary server to be the same as that in the server cert .connect("tlsnotaryserver.io".try_into().unwrap(), notary_socket) .await .unwrap();