Slide 1

Slide 1 text

Nik Graf https://mastodon.social/@nikgraf nikgraf.bsky.social @nikgraf

Slide 2

Slide 2 text

Utility to persit & relay end-to-end encrypted CRDTs

Slide 3

Slide 3 text

Demo

Slide 4

Slide 4 text

Let’s e2e encrypt CRDTs

Slide 5

Slide 5 text

Two online participants

Slide 6

Slide 6 text

What about the offline use-case?

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

How to store unenrypted Yjs / Automerge? • Store the document in a blob • Append changes and sometimes compress the doc -> on the server • We can’t do that with e2e encryption. Must happen on the client.

Slide 9

Slide 9 text

Let’s what we can do with Yjs & Automerge A B D C A B D C A B D C = =

Slide 10

Slide 10 text

Let’s encrypt each change A B D C xyz asd poi jkl encrypt

Slide 11

Slide 11 text

Best part Use Signal, MegOlm, MLS Don’t roll your own crypto!

Slide 12

Slide 12 text

Performance (250k changes) 250k changes Document Automerge 2.0.3 Yjs (update v2) Size
 (base64 encoded) 38.7MB 11.1MB Construct Document 1377ms 979ms https://github.com/SerenityNotes/naisho/tree/main/benchmarks/snapshots Numbers on a M1 Macbook 2020

Slide 13

Slide 13 text

Performance (10k changes) 10k changes Document Automerge 2.0.3 Yjs (update v2) Size
 (base64 encoded) 1.44MB 0.4MB Construct Document 52ms 59ms https://github.com/SerenityNotes/naisho/tree/main/benchmarks/snapshots Numbers on a M1 Macbook 2020

Slide 14

Slide 14 text

Problems • Documents can get large and take a long time to load • (decryption not even accounted for) • Messaging protocols are not a good fit • Use-case: fetch a document again and decrypt it • Solution: one encryption key?

Slide 15

Slide 15 text

Snapshots (with updates?) Automerge.save Yjs.encodeStateAsUpdate

Slide 16

Slide 16 text

Performance (Automerge 2.0.3) 10k changes Document Changes Snapshot Snapshot w/ 1000 Changes Size
 (base64 encoded) 1.44MB 0.001MB 0.15MB Construct Document 52ms 45ms 74ms https://github.com/SerenityNotes/naisho/tree/main/benchmarks/snapshots Numbers on a M1 Macbook 2020

Slide 17

Slide 17 text

Performance (Automerge 2.0.3) 250k changes Document Changes Snapshot Snapshot w/ 1000 Changes Size
 (base64 encoded) 38.7MB 0.17KB 0.3MB Construct Document 1377ms 1423ms 1466ms https://github.com/SerenityNotes/naisho/tree/main/benchmarks/snapshots Numbers on a M1 Macbook 2020

Slide 18

Slide 18 text

Performance (Yjs 13.5.28) 10k changes Document Changes Snapshot Snapshot w/ 1000 Changes Size
 (base64 encoded) 0.4MB 0.02MB 0.5MB Construct Document 59ms 0.8ms 247ms https://github.com/SerenityNotes/naisho/tree/main/benchmarks/snapshots Numbers on a M1 Macbook 2020

Slide 19

Slide 19 text

Performance (Yjs 13.5.28) 250k changes Document Changes Snapshot Snapshot w/ 1000 Changes Size
 (base64 encoded) 11.1MB 0.21MB 0.25MB Construct Document 979ms 11ms 127ms https://github.com/SerenityNotes/naisho/tree/main/benchmarks/snapshots Numbers on a M1 Macbook 2020

Slide 20

Slide 20 text

Snapshots only (serial) xyz xyz asd jkl xyz asd • Server must ensure you have the most recent snapshot before accepting yours • Easy protocol, lots of data overhead, real-time collaboration not feasible • Requires a central service, delta fetching is easy

Slide 21

Slide 21 text

Snapshots + Updates (serial) xyz jkl asd • Server must ensure you have the most recent snapshot before accepting yours • Easy protocol, lots of overhead due retries when using real-time collaboration • Requires a central service, delta fetching is easy xyz asd poi

Slide 22

Slide 22 text

Snapshots + Updates (per client) xyz jkl asd • Server must ensure you have the most recent snapshot before accepting yours • Easy protocol, scaling issue with many clients, real-time collaboration works, UX nightmare • Works decentralized, delta fetching is tricky xyz asd poi jkl hjk

Slide 23

Slide 23 text

Snapshots (serial) + Updates (serial per client) xyz jkl asd • Server must ensure you have the most recent data before accepting your snapshot • More tricky protocol, little data overhead, real-time collaboration works well • Requires a central service, delta fetching is ok xyz asd poi jkl hjk poi

Slide 24

Slide 24 text

Desired properties • Offline collaboration - without multiple parties being online • Real-time collaboration incl. ephemeral state • Privacy • Be able to remove content - through Snapshots & Tombstones (if supported) • Snapshot History • Good loading times for fetching a document • Integrity checking!

Slide 25

Slide 25 text

Entities • Document -> ID • Snapshot -> Automerge.save, Y.encodeStateAsUpdate • Update -> Automerge change, Yjs Update • EphemeralMessage -> Yjs Awarness

Slide 26

Slide 26 text

Cryptography • Key rotation for Snapshots • Verify authors • Prevent against server leaving out updates or manipulating message • Prevent against server sending an older snapshot (reply attack) • Ignores reply attacks (snapshots, updates & ephemeral messages)

Slide 27

Slide 27 text

Cryptography Doc encryption

Slide 28

Slide 28 text

Cryptography EphemeralMessages Auth

Slide 29

Slide 29 text

Don’t roll you own crypto! (I shouldn’t do too)

Slide 30

Slide 30 text

Thanks! https://www.secsync.com/ https://github.com/serenity-kit/secsync

Slide 31

Slide 31 text

Resources • Inspiration: Snapdoc: Authenticated snapshots with history privacy in peer-to- peer collaborative editing https://martin.kleppmann.com/papers/snapdoc- pets19.pdf

Slide 32

Slide 32 text

Desired properties • Async collaboration - without multiple parties being online • Real-time collaboration incl. ephemeral state • Privacy • Be able to remove content - through Snapshots and Tombstones (if supported) • Solid Performance for loading a document • Confidentiality - content only accessible to participants • Authenticity - all changes can be verified to come from participants • Integrity - no change missing • Offline editing • Two modes: • Public Key Infrastructure based • Shared Symmetric Key (e.g. via PAKE) • Confidential and authenticated information who created which section • Meta data: not in scope for 1.0 to hide who is participating (Zero-knowledge proofs)