grappa

Encryption

grappa is a bouncer: it stays on IRC for you and keeps your channels and queries, so it reads them, as any IRC server does. An encrypted query is the exception. It runs between two browsers, or a browser and a bot, and grappa and the IRC network carry it without being able to read it. This page describes how that is built, from the code and the wire spec.

live Encrypted queries between grappa users, and with bots built on irc-olm. Up to three devices per identity. Key verification.

coming Encrypted channels and encrypted file attachments. Their server side is written; cicchetto's side is still being built.

The pieces

The keys exist only at the two ends. Everything in between carries ciphertext.

Your browser holds the keys and the plaintext. Ciphertext goes over HTTPS to your grappa, which holds no key, then as CTCP lines inside PRIVMSG across the IRC network, where a bot built on irc-olm holds its own keys, then to the other person's grappa, which holds no key either, and finally to their browser, which decrypts it YOUR BROWSER cicchetto ยท vodozemac in WebAssembly keys + plaintext ciphertext, over HTTPS YOUR GRAPPA splits, paces, queues per device no key CTCP lines in PRIVMSG IRC NETWORK relays, can't read ircd irc-olm bot its own keys same lines, their side THEIR GRAPPA joins lines, queues per device no key ciphertext, over HTTPS THEIR BROWSER decrypts its own copy keys + plaintext

Outlined in blue: what holds keys. A bot on irc-olm speaks the same wire straight to the IRC network.

Your browser

The plaintext and the keys. The cryptography is vodozemac, Matrix's Rust implementation of Olm, compiled to about 300 KB of WebAssembly and loaded the first time an encrypted chat needs it.

No home-made cryptography: Olm, the Ed25519 signatures and the pairing channel come from vodozemac, the storage seal from the browser's WebCrypto.

grappa

Cuts each message into IRC lines and paces them, joins them back on the way in, answers key requests with the keys your devices uploaded, and queues each message per device until that device reads it. It never parses the payload and holds no key.

An encrypted line is never written to scrollback or search, and never into a push notification: that one says only the nick and "encrypted message".

The IRC network

Sees CTCP lines going from one nick to another: when, how many, how long, and the device ids written in each frame. Not what they say.

One identity, several devices

On each network you have one identity: a master key, and up to three devices it vouches for.

A master Ed25519 key, the one peers pin, signs a versioned list of devices. The list names up to three devices, for example a phone, a laptop and a tablet, each an Olm account that signs its own id block and keeps fifty one-time keys and a fallback key on grappa master key Ed25519 ยท what peers pin signed device list its version only goes up phone Olm account laptop Olm account tablet Olm account each device: an id block it signs, and 50 one-time keys + a fallback key on grappa

The master is an Ed25519 key, and it is what other people pin. Each device is an Olm account with its own Curve25519 and Ed25519 keys. A device signs an id block that covers its Curve25519 key and the master, so no other master can claim it. The master signs a list of its devices with a version number, and each new list must raise it. A device a newer list leaves out is revoked: grappa deletes its keys and its queue, and peers stop encrypting to it.

Each device uploads to grappa up to 50 one-time keys and a fallback key, each signed by the device. That is what lets someone start a conversation with you while every tab of yours is closed: grappa answers for you with your list and one key per device, and hands out each one-time key only once. grappa checks a single signature, the list's, so a stolen login cannot quietly rewrite your devices; every other signature is checked by the peer.

The master stays in the browser that created the identity. Adding a device or revoking one is done from there.

Starting an encrypted chat

First consent, then keys. Neither needs both people online at the same time.

Alice's cicchetto sends REQUEST to Bob's grappa, which shows Bob a banner; Bob's ACCEPT comes back to Alice. Alice sends KEYREQ, and Bob's grappa answers KEYS with his list and a one-time key per device. Alice checks the keys, pins Bob's master and opens Olm sessions, then sends a PKMSG with one body per device. Bob's grappa queues it per device, Bob's cicchetto reads it from the inbox, decrypts its body and acknowledges it, and replies with MSG IRC Alice cicchetto grappa Alice's grappa Bob's Bob cicchetto REQUEST banner ACCEPT KEYREQ KEYS list + a one-time key per device check, pin, open sessions PKMSG one body per device queue per device inbox decrypt, ack MSG, the reply

1 Asking

From a query, you ask the other person to chat securely. That sends REQUEST, a CTCP to their nick. Their grappa keeps it and shows them a banner, and the asking waits 24 hours. ACCEPT comes back the same way. Consent is not trust: accepting only says you are willing to talk.

2 Keys

Your device sends KEYREQ, and their grappa answers KEYS for them, with or without a tab of theirs open: the master, its signed list, and for each device its id block and one one-time key, or the fallback key once those run out.

3 Pinning

Your device checks every signature and pins their master to the nick: trust on first use, marked unverified until you verify it (below).

4 The first message

For each of their devices, yours opens an Olm session from that one-time key and encrypts the message once per device. The PKMSG carries those bodies, your device's id block and the master's certificate for it. Each body also binds your device key to the recipient's, so a body handed to another device is refused.

5 Delivery

Their grappa joins the lines back and queues the message for each of their devices. A device that is online gets it at once; one that is not finds it when it connects, for up to 7 days. Each device decrypts its own body and acknowledges it, and grappa deletes the entry.

6 From then on

MSG, on the sessions now open. Olm is a Double Ratchet: every message is encrypted under a key of its own, and keys move forward as the two sides talk.

On the wire

An encrypted message is ordinary IRC: PRIVMSGs to the other person's nick, each carrying one CTCP line.

# the frame, one per IRC line
\x01E2E <verb> <msgid> <i>/<n> <from> <to> <chunk>\x01

# a message in three lines, from one device to every listed device (*)
PRIVMSG bob :\x01E2E MSG q83vEjRWeJA 1/3 AaZaARRDyBk * {"v":2,"ck":"โ€ฆ","bodies":{"BoBBoBBoBBo":"Awogโ€ฆ
PRIVMSG bob :\x01E2E MSG q83vEjRWeJA 2/3 AaZaARRDyBk * โ€ฆ
PRIVMSG bob :\x01E2E MSG q83vEjRWeJA 3/3 AaZaARRDyBk * โ€ฆ"}}\x01
an encrypted query in cicchetto with the ciphertext view switched on: every line shown as the E2E MSG envelope grappa relayed, base64 only
cicchetto's ciphertext view: the same chat as grappa and the network carried it

Is it really them?

Pins are on keys, never on nicks. The nick only says where to send.

The first master a nick presents is pinned and marked unverified. You verify it in one of two ways: compare seven emoji with the other person, a SAS exchange modelled on Matrix's m.sas.v1 and run inside the Olm session, or compare the key cicchetto shows you with the one they read you some other way. Verification is recorded on the master, so it covers all of their devices, now and later.

If a different master shows up on a pinned nick, cicchetto raises an alarm and ignores it: a pin never changes on its own, only when you change it. If the other side's grappa says a message reached none of their devices, cicchetto tells you and does not fetch new keys by itself, because the nick may belong to someone else now.

the side panel of an encrypted query: the other person's key, marked verified; your own key with a copy button; your devices, each with a revoke button
The other person's key, yours, and your devices

More than one browser

Pairing brings a new browser into your identity, and the master never leaves the old one.

The old browser, which holds the master, opens a rendezvous on grappa with a one-off key, and grappa offers it to the new browser of the same account. The new browser says hello and an ECIES channel starts. The new browser shows a two-digit code that you type on the old one. The old browser offers its networks, the new one registers a device and joins, the old one sends back a signed certificate and list and puts the new list on grappa, and the new browser says done. grappa relays every step without reading it old browser holds the master grappa blind relay new browser same account open + key offer hello ยท ECIES starts you type 47 shows 47 networks on offer register device join signed: certificate + list put new list done

Every message between the two browsers goes through grappa, encrypted between them.

The browser holding the master opens a rendezvous on grappa with a one-off Curve25519 key, and grappa offers it, as a banner, to the other browsers logged in to your account. The new browser joins, and the two talk over a channel encrypted between them (vodozemac's ECIES, the shape of Matrix's MSC4108) that grappa relays without reading. The new browser shows a two-digit code and you type it on the old one: that code is what stops a grappa sitting in the middle. Then the new browser registers a device on each network, the master signs it in with a certificate and a new list, and it is part of the identity. A rendezvous lives five minutes, in grappa's memory only.

Up to three devices per identity. A message to you carries one encrypted body for each of them, so every device costs a little on every message. What you send from one device is also encrypted to your other devices, so they show your side of the conversation too.

On your device

cicchetto keeps your keys, its session state and your decrypted history in IndexedDB, in records sealed with AES-GCM under a key the browser created as non-extractable: a copy of the browser profile alone does not give up the keys, and not even the page can read the wrapping key's bytes, only ask the browser to use it. Tabs take turns through Web Locks, so two tabs never write over each other's keys.

The decrypted history exists only there. grappa deleted the ciphertext when your device acknowledged it, and the key that opened it is spent. Clear the browser's storage and that history is gone; that is the design.

Bots, and orders with a second factor

Bots speak the same wire through irc-olm, a separate implementation in Python on the same vodozemac, tested against cicchetto on every push. A bot has nobody to compare emoji with, so its operator pins the keys it talks to by hand, and it answers nobody else.

A bot that takes orders can also ask for proof. When a pinned person sends it a line in plain text, the bot sends a challenge inside the encrypted session, naming the network, the channel and the SHA-256 of the line, and cicchetto answers only if this very device sent that exact line moments earlier. A line someone else typed in your nick gets no answer, and the bot refuses the order.

What it does not cover

Coming next

coming Encrypted channels

A channel message is encrypted once and sent once, as a PRIVMSG to the channel, and IRC's own fan-out delivers it: one line per message, not one per member. Each sender has its own Megolm-style group session, and its key travels only inside the pairwise Olm chats between members, never through the server, which has nothing that serves it.

The key rotates when someone parts or is kicked, and periodically. Whoever left keeps what they had already received, nothing after. Being in the channel is what grants the key. grappa's side is written; cicchetto's is being built, and details may still change.

coming Encrypted files

cicchetto seals the file with AES-256-GCM under a fresh key and uploads only the ciphertext, which grappa stores with no name and no type. The key, the real name and the type travel inside the encrypted message. grappa's door for it is already in production; cicchetto's side is in review.

Read the source

Ready?

Log in with a nick โ€” you're on IRC in seconds.

Try it now โ†’