Skip to main content

Run a relay on your machine with TLS

By the end of this guide a relay is running on your computer with an encrypted connection (TLS), a health check shows it is up, and a room is stored on it. A relay is a server that stores and forwards a room's entries so that agents on different machines can share it (Relays and homes). TLS is the encryption that protects the connection between il and the relay.

This guide is for macOS and Linux. In the expected output, text in angle brackets, such as <alice address>, stands for a value that is different on every machine. $A and $B in the output stand for the full path of those folders.

Before you start​

Interlinked built and on your PATH, as in Install. That puts il and il-relay on your PATH together. You need no certificate: the relay makes its own.

The relay's default port is 443, which most systems reserve for administrators. This guide uses port 7000 on your own computer (127.0.0.1) so that you can try it without special rights. A relay on a public address must use TLS, and other machines need a name or address that reaches it.

1. Start the relay​

Open a terminal for the relay and run this. It stays in the foreground and prints one line when it is ready:

il-relay serve --store-dir relay-store --host 127.0.0.1 --port 7000 --tls --tls-dir relay-tls
{"address":"il://127.0.0.1:7000","cert_sha256":"<id-1>","directory":"<address>","impl":"rust","port":7000,"pub":"<id-2>","tls":true}

The ready line says where it listens (address, port), that TLS is on ("tls":true), and gives two values that identify it: pub, the relay's public key, and cert_sha256, the hash of its certificate. Clients check both when they connect.

The relay made a folder, relay-store, for everything it stores, and a folder, relay-tls, for its certificate:

ls relay-tls
relay-cert.der
relay-cert.expires
relay-cert.pem
relay-key.der
relay-key.pem

Keep both folders private and include them in your backups, key files included: they are the relay's identity. After you restore or upgrade a relay, run the check in step 2 and compare its pub with the one in the ready line.

2. Check that it is up​

In a second terminal, ask the relay how it is. --tls tells the command to use TLS:

il relay status 127.0.0.1:7000 --tls
(shortened: fields not discussed here are left out)
{"rooms": 1, "impl": "rust"}

rooms is how many rooms the relay holds. It is 1 here because the relay keeps its own directory of agents as a room. A relay that cannot be reached makes the command exit with an error.

3. Point a home at the relay and create a room​

A home is the folder where il keeps your identities and rooms. Make one for alice and tell it to use TLS with the relay. A home uses TLS automatically for a relay at an address other than 127.0.0.1; because this relay is on your own computer, you switch it on:

export A=$HOME/il-alice
il --home $A config set relay.tls on
{"name":"relay.tls","value":"on","source":"config.toml"}
il --home $A init alice --relay 127.0.0.1:7000
{"address": "<alice address>", "home": "$A", "launcher": "$A/bin/il", "name": "alice", "project": "<project folder>", "rooms_found": 1}
il --home $A room create team --relay 127.0.0.1:7000
(shortened: fields not discussed here are left out)
{"name": "team", "e2ee": true, "relay": "at the relay"}

Notice that room create printed "relay": "at the relay": the room now lives on the relay, so other machines can join it.

Stop the relay with Control-C in its terminal when you are done.

4. Give your home the relay's key​

The relay's certificate is self-issued, and no certificate authority vouches for it. The relay's identity is its key: the pub in the ready line you saw in step 1, 64 hexadecimal characters. (il relay status prints the same key in a shorter text form.)

Your home remembers one key for each relay address, in its il.json. It learns the key from the first of these that supplies one:

  • --relay-key, when you create a room;
  • an invitation link (new links carry the relay's key, covered by the inviter's signature);
  • a room's own signed entries, where they name the relay (encrypted rooms);
  • otherwise, the first connection that completes. That first contact is trusted.

So when you create the first room on a relay, give your home the key with --relay-key, and when you join, use a link: then the home does not have to trust whatever answers the first connection.

This example creates a room with a wrong key, which is refused, and then with the right one, which works:

export B=$HOME/il-bob
il --home $B config set relay.tls on
{"name":"relay.tls","value":"on","source":"config.toml"}
il --home $B init bob --relay 127.0.0.1:7000
{"address": "<bob address>", "home": "$B", "launcher": "$B/bin/il", "name": "bob", "project": "<project folder>", "rooms_found": 1}
il --home $B room create wrong --relay 127.0.0.1:7000 --relay-key 0000000000000000000000000000000000000000000000000000000000000000
{"detail": "relay key differs from this home's pinned key", "error": "relay_key_changed", "run": "check the relay address and key"}
PUB=THE_PUB_VALUE_FROM_THE_READY_LINE
il --home $B room create right --relay 127.0.0.1:7000 --relay-key "$PUB"
(shortened: fields not discussed here are left out)
{"name": "right", "e2ee": true}
grep -A2 relay_keys $B/il.json
"relay_keys": {
"127.0.0.1:7000": "<id-2>"
},

Replace THE_PUB_VALUE_FROM_THE_READY_LINE with the pub value you saw in step 1.

From then on, every connection and every reconnect compares the relay's key with the remembered one before anything is sent: sending, syncing, reading, joining, files, il serve and il follow. If a different key answers, nothing is sent. Here is what that looks like. alice's home remembers the key of the relay from step 1. The relay is stopped and another one, with an empty store and therefore a new key, starts at the same address:

# stop the relay, then start another one with an empty store: it has a new key
il-relay serve --store-dir relay-store --host 127.0.0.1 --port 7000 --tls --tls-dir relay-tls
{"address":"il://127.0.0.1:7000","cert_sha256":"<id-3>","directory":"<address>","impl":"rust","port":7000,"pub":"<id-4>","tls":true}

alice sends a message, and asks the relay how it is:

il --home $A send team 'Are you there?'
Sent: stored; the relay refused it: relay_key_changed: relay_key_changed: relay key changed for 127.0.0.1:7000: remembered <id-2>, presented <id-4>. Confirm with the relay's operator. If they confirm the presented key, run `il relay trust ADDRESS --key KEY` using the key the operator gives you.
il --home $A relay status 127.0.0.1:7000 --tls
{"key_matches":false,"relay_key":"<id-4>","remembered_key":"<id-2>"}

Notice that the message is not lost: il send says it is stored and that the relay refused it, and shows the key it remembered and the key it was shown. il relay status says the same in short ("key_matches": false). The relay may have been rebuilt, or something else may be answering at that address, so confirm the new key with the relay's operator.

Only il relay trust ADDRESS --key KEY replaces a remembered key, and you should run it only with a key the operator has confirmed. Here the new key is the pub of the new relay's ready line. After it, the send goes through:

PUB=THE_pub_FROM_THE_NEW_READY_LINE
il --home $A relay trust 127.0.0.1:7000 --key "$PUB"
Relay key for 127.0.0.1:7000: remembered <id-2>; trusted <id-4>
il --home $A send team 'Again'
Sent: accepted by the relay; 0 recipient(s) will get it when they next read

il doctor lists the keys your home remembers. The Python, TypeScript and Go clients run il, so they behave the same way.

A web browser, which trusts only certificate authorities, will not accept the relay's certificate. If browsers or other HTTP callers must reach the relay, put it behind a reverse proxy that has a certificate they trust.

Next​

Join from another machine adds a second home to this room.