improved workshop + bin->example

This commit is contained in:
Hendrik Eeckhaut
2023-11-08 15:20:44 +01:00
parent 3a0955b890
commit f099b9d49b
7 changed files with 92 additions and 57 deletions

View File

@@ -32,3 +32,11 @@ rustls = { version = "0.21" }
tokio-rustls = { version = "0.24.1" }
tracing = "0.1.40"
rustls-pemfile = { version = "1.0.2" }
[[example]]
name = "discord_dm"
path = "src/examples/discord_dm.rs"
[[example]]
name = "discord_dm_verifier"
path = "src/examples/discord_dm_verifier.rs"

View File

@@ -31,3 +31,11 @@ futures = "0.3.28"
# Verifier
elliptic-curve = { version = "0.13.5", features = ["pkcs8"] }
chrono = "0.4.31"
[[example]]
name = "simple_prover"
path = "src/examples/simple_prover.rs"
[[example]]
name = "simple_verifier"
path = "src/examples/simple_verifier.rs"

View File

@@ -4,18 +4,17 @@
# Progcrypto 2023: TLSNotary workshop
TODO short intro
This workshop helps you getting started with TLSNotary, in native Rust and in the Browser.
## TLSNotary in Rust
1. [Most basic example: Proof and Verify public data (Rust)](#rust-simple)
2. [Proof and Verify a private Discord DM (Rust)](#rust-discord)
3. [Proof and Verify a private Twitter DM (Browser)](#browser)
TODO short intro
Objectives of this workshop:
* Have a better feeling about what you can do with TLSNotary
* Learn the basics on how to proof and verify data with TLSNotary
### Install Rust
If you don't have `rust` installed yet, install it with [rustup](https://rustup.rs/):
```shell
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```
## Setup
### Clone workshop repository
@@ -25,18 +24,29 @@ Clone this repository first
git clone git@github.com:heeckhau/progcrypto_workshop.git
```
### Simple example: Notarize public data from example.com
### Install Rust
TODO intro
If you don't have `rust` installed yet, install it with [rustup](https://rustup.rs/):
```shell
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```
https://example.com/
## Simple example: Notarize public data from example.com (Rust) <a name="rust-simple"></a>
#### 1. Notarize <https://example.com/>
We start with the simplest possible use case for TLSNotary:
1. Fetch <https://example.com/> and create a proof of its content
2. Verify the proof
Next we will redact the content and verify again:
1. Redact the `USER_AGENT` and titles
2. Verify the redacted proof
### 1. Notarize <https://example.com/>
Run a simple prover
```shell
cargo run --release --bin simple_prover
cargo run --release --example simple_prover
```
Note: you can also run the `simple_prover` by clicking the **▶️ Run** button in VS Code. However, this will run without the `--release` by default and the execution will be a lot slower.
@@ -44,7 +54,7 @@ Note: you can also run the `simple_prover` by clicking the **▶️ Run** button
![](images/run_vs_code.png)
If the notarization went file you should see this output in the console
If the notarization went fine, you should see this output in the console:
```log
Listening on: 127.0.0.1:8080
Connected to the Notary
@@ -55,12 +65,12 @@ Notarization completed successfully!
The proof has been written to `simple_proof.json`
```
#### 2. Verify the proof
### 2. Verify the proof
When you open `simple_proof.json` in an editor, you will see a json file with lots of non-human readable byte arrays. You can decode this file by running:
```shell
cargo run --release --bin simple_verifier
cargo run --release --example simple_verifier
```
This will output the TLS=transaction in clear text:
@@ -72,7 +82,7 @@ Bytes sent:
...
```
#### 3. Redact information
### 3. Redact information
Open `simple_prover.rs` and locate the line with:
```rust
@@ -85,8 +95,8 @@ and change it to
Next, if you run the `simple_prover` and `simple_verifier` again, you'll notice redacted `X`'s in the output:
```shell
cargo run --release --bin simple_prover
cargo run --release --bin simple_verifier
cargo run --release --example simple_prover
cargo run --release --example simple_verifier
```
```log
@@ -103,22 +113,25 @@ Open <https://tlsnotary.github.io/proof_viz/> and drag and drop `simple_proof.js
Redacted bytes are marked with <span style="color:red">red █ characters</span>.
#### (Optional) Extra experiments
### (Optional) Extra experiments
If the above steps were easy for you and you are waiting for the others: feel free to try these extra challenges:
- [ ] Modify the `server_name` (or any other data) in `simple_proof.json` and verify the proof is no longer valid
- [ ] Modify `build_proof_with_redactions` function in `simple_prover.rs` to redact more or different data
### Notarize private information: Discord message
Notarize private information
## Notarize private information: Discord message (Rust)<a name="rust-discord"></a>
Next we will use TLSNotary to generate a proof of private information: a private Discord DM.
We will also use an explicit (locally hosted) notary server this time.
#### 1. Start a local notary server
### 1. Start a local notary server
-> start a real local notary server (keep it running for the Browser extension)
The notary server used in this example is more functional compared to the (implicit) simple notary service, used in the example above. The simple version is easier to integrate with from prover perspective, whereas this notary server provides additional features like TLS connection with prover, WebSocket endpoint, API endpoints for further customisation etc.
The notary server used in this example is more functional compared to the (implicit) simple notary service, used in the example above. The simple notary version is easier to integrate from a prover's perspective, whereas this notary server provides additional features like TLS connection with prover, WebSocket endpoint, API endpoints for further customisation etc.
```shell
cd notary
@@ -127,17 +140,13 @@ cargo run --release
The notary server will now be running in the background waiting for connections.
keep it running and switch to a new terminal
Keep it running and open a new terminal.
#### 2. Get Authorization token and channel ID
### 2. Get Authorization token and channel ID
In the main 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).
In the main folder, copy a `.env.example` file and name it `.env`.
```env
AUTHORIZATION="..."
CHANNEL_ID="..."
```
In this `.env` we will input the `USER_AGENT`, `AUTHORIZATION` token and `CHANNEL_ID`.
| Name | Example | Location |
| ------------- | -------------------------------------------------------------------------------- | --------------------------------------------- |
@@ -145,7 +154,9 @@ CHANNEL_ID="..."
| AUTHORIZATION | `MTE1NDe1Otg4N6NxNjczOTM2OA.GYbUBf.aDtcMUKDOmg6C2kxxFtlFSN1pgdMMBtpHgBBEs` | Look for `Authorization` in a request headers |
| CHANNEL_ID | `1154750485639745567` | URL |
You can obtain these parameters by opening [Discord](https://discord.com/channels/@me) 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.
You can obtain these parameters by opening [Discord](https://discord.com/channels/@me) in your browser and accessing the message history you want to notarize.
> **_NOTE:_** ⚠️ 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 `/api` to filter results to Discord API requests. From there you can copy the needed information into your `.env` as indicated above.
@@ -153,12 +164,13 @@ You can find the `CHANNEL_ID` directly in the url:
`https://discord.com/channels/@me/{CHANNEL_ID)`
TODO: Browser screenshot
![](./images/discord_authentication_token.png)
#### 3. Create proof
### 3. Create proof
Next run the `discord_dm` example to generate a proof:
```shell
RUST_LOG=debug,yamux=info cargo run --release --bin discord_dm
RUST_LOG=debug,yamux=info cargo run --release --example discord_dm
```
If all goes well, you get this output:
@@ -182,37 +194,26 @@ If the transcript was too long, you may encounter the following error. This occu
thread 'tokio-runtime-worker' panicked at 'called `Result::unwrap()` on an `Err` value: IOError(Custom { kind: InvalidData, error: BackendError(DecryptionError("Other: KOSReceiverActor is not setup")) })', /Users/heeckhau/tlsnotary/tlsn/tlsn/tlsn-prover/src/lib.rs:173:50
```
The Discord example code redacts the `auth_token`, but feel free to change the redacted regions.
The proof is written to `discord_dm_proof.json`
#### Verify
### Verify
Verify the proof by dropping the json file into <https://tlsnotary.github.io/proof_viz/> or by running:
```shell
cargo run --release --bin discord_dm_verifier
cargo run --release --example discord_dm_verifier
```
TODO conclusion...
Good job! You have successfully used TLSNotary in Rust.
## TLSNotary browser extension
### Install browser extension
### Run a local proxy
### Notarize twitter account access
> **_NOTE:_** Leave the local notary server running for the next part of this workshop: testing the Browser extension.
The MPC between the prover and the notary requires a lot of bandwidth, certainly too much for all of us to use a publicly hosted notary server at the same time.
### (Optional) Notarize more private data
## (Optional) Notarize more private data
Try to notarize data from other websites such as:
If the examples above were too easy for you, try to notarize data from other websites such as:
- [ ] Amazon purchase
- [ ] Twitter dm
@@ -221,3 +222,21 @@ Try to notarize data from other websites such as:
- [ ] Garmin.connect achievement
- [ ] AirBnB score
- [ ] Tesla ownership
## TLSNotary browser extension <a name="browser"></a>
TODO
### Install browser extension
TODO
### Run a local proxy
TODO
### Notarize twitter account access
TODO