BONVOYAGE

Bonvoyage protocol, version 1 (draft)

Bonvoyage lets ticket printers in different homes send each other tickets. Nothing at home is reachable from the internet, and the relay that carries the tickets cannot read them.

This document is the whole protocol. Anyone with a ticket printer should be able to implement it from this text and check the result against the test vectors in vectors/.

The words MUST, MUST NOT, SHOULD and MAY are used as in RFC 2119.

1. Overview

 sender printer                relay                recipient printer
       |   POST sealed message   |                          |
       |------------------------>|                          |
       |                         |   GET inbox (signed)     |
       |                         |<-------------------------|
       |                         |   sealed messages        |
       |                         |------------------------->|
       |                         |   DELETE message         |
       |                         |<-------------------------|

1.1 Privacy goals

The relay is not trusted with content.

A relay can never learn: the ticket, who sent it, or the sender's address. All of that is inside the sealed part.

A relay does learn, and no relay design can avoid this: that an inbox received a message, when, its padded size (section 5.3), which drop token was used (section 4), and the network address of the client that connected. A relay SHOULD NOT log network addresses.

1.2 Encodings

2. Cryptography

Bonvoyage uses the NaCl / libsodium primitives, which exist for every common language:

Purpose Primitive libsodium name
Signing Ed25519 crypto_sign_detached
Sealing for a recipient X25519 + XSalsa20-Poly1305 "sealed box" crypto_box_seal
Hashing SHA-256

An identity consists of:

The two key pairs are independent. Private keys never leave the printer.

3. Addresses and contact cards

3.1 Inbox ID and address

The inbox ID is the base64url encoding of the public signing key (43 characters).

An address is <inbox ID>@<relay host>, for example:

m3cX0R1bq0u0m1cX0R1bq0u0m1cX0R1bq0u0m1cX0R1@bonvoyage.kaj.dev

The relay's base URL is https://<relay host>. A relay host MAY include a port. Clients MUST use HTTPS, except for localhost during development.

3.2 Contact card

To let someone send you tickets, you give them a contact card: a URI that is easy to put in a QR code.

bonvoyage://<relay host>/<inbox ID>?k=<encryption key>&t=<drop token>&n=<name>
Part Meaning
relay host, inbox ID your address
k your public encryption key, base64url
t a drop token for your inbox (section 4), base64url
n a display name, percent-encoded, optional

A card contains a drop token and is therefore a secret: whoever holds it can drop messages in your inbox. Hand it over privately. Printing it as a QR code on a ticket for the other person to scan is the intended way.

Each contact SHOULD get their own card with their own drop token, so that one contact can be removed without affecting the others.

3.3 Pairing

Pairing is one-directional: a card lets its holder send to its issuer. For tickets in both directions, both people give each other a card.

The recipient learns who a sender is as follows. When you issue a card you remember which contact its drop token belongs to. The relay tells you which token each message arrived with (section 6.4). The first validly signed message that arrives with a given token pins that sender's signing key to that contact. From then on, messages with that token MUST be signed by the pinned key; others MUST be discarded.

4. Drop tokens

A drop token is 32 random bytes generated by the inbox owner.

The owner registers the token ID, which is the lowercase hex SHA-256 of the 32 token bytes, with the relay. The relay never sees a token until a sender uses it, and stores only token IDs.

Removing a token ID from the inbox revokes that contact's ability to send.

5. Messages

5.1 The message

A message is a JSON object:

Member Type Meaning
v number protocol version, 1
id string 16 random bytes, base64url; unique per message
type string "ticket" (others are reserved; unknown types MUST be ignored)
from string sender's address
from_name string sender's display name, optional
to string recipient's address
created number when it was made
expires number optional; do not print after this time
ticket object the ticket (section 7), for type ticket

5.2 Signing

Let M be the UTF-8 bytes of the message JSON, exactly as the sender serialised them. The signature is Ed25519 over the bytes:

"bonvoyage-v1-message\n" || M

The signed message is the JSON object

{"msg": "<base64url of M>", "sig": "<base64url of the 64-byte signature>"}

Signing the exact bytes avoids any need to canonicalise JSON. Verifiers MUST verify against the decoded bytes of msg, and only then parse them.

5.3 Padding and sealing

Let S be the UTF-8 bytes of the signed message JSON. The padded plaintext is

P = uint32_be(len(S)) || S || zero bytes

with as many zero bytes as needed to make len(P) a multiple of 4096.

The sealed message is crypto_box_seal(P, recipient public encryption key). Its length is len(P) + 48. A sealed message MUST NOT exceed 65536 bytes, which leaves 61436 bytes for S.

5.4 Receiving

For every sealed message collected, a recipient MUST:

  1. open it with its encryption key pair; on failure discard it;
  2. read the length, take S, and parse the signed message;
  3. decode msg to bytes M and parse the message;
  4. check v is 1 and to equals its own address;
  5. take the sender's public signing key from the inbox ID in from and verify sig over "bonvoyage-v1-message\n" || M;
  6. check the sender against the token the message arrived with (section 3.3);
  7. discard it if id was seen before, if created is more than 10 minutes in the future, or if expires has passed;
  8. apply its own policy (section 8), then print or queue it;
  9. delete the message from the relay.

A message that fails any check MUST be deleted from the relay and MUST NOT be printed. Recipients SHOULD remember seen id values for at least 14 days.

6. Relay HTTP interface

All paths are relative to the relay's base URL. Bodies and responses are JSON unless stated. Errors use the matching HTTP status with {"error": "<short text>"}.

6.1 Relay information

GET /v1 returns the relay's limits:

{"bonvoyage": 1, "max_message_bytes": 65536, "max_messages": 50,
 "retention_seconds": 604800, "max_tokens": 64, "registration": "open"}

6.2 Owner authentication

Requests marked owner are signed with the inbox's signing key. The client sends the header

Bonvoyage-Auth: t=<time>,sig=<base64url signature>

where the signature is Ed25519 over the UTF-8 bytes of

"bonvoyage-v1-request\n" || METHOD || "\n" || PATH || "\n" || time || "\n" || hex(SHA-256(body))

METHOD is upper case, PATH is the request path without query string, and body is the exact request body (empty for requests without one). The relay MUST reject a request whose time differs from its own by more than 300 seconds, or whose signature does not verify against the inbox ID in the path (401).

6.3 Inbox management (owner)

PUT /v1/inbox/<inbox ID> creates the inbox or replaces its settings.

{"tokens": ["<token ID>", "..."]}

tokens is the complete list of accepted token IDs. Replacing the list is how tokens are added and revoked. Response 200 with the stored settings.

DELETE /v1/inbox/<inbox ID> removes the inbox and everything in it (204).

A relay MAY refuse new inboxes (403), for example when registration is closed or it is full. A relay MAY remove an inbox that has not been collected from for 180 days.

6.4 Dropping a message (sender)

POST /v1/inbox/<inbox ID>/messages

The relay accepts it (201, body {"id": "<relay message id>"}) when the inbox exists, the SHA-256 of the decoded token is one of the inbox's token IDs, the body is at most max_message_bytes, and the inbox holds fewer than max_messages messages. Otherwise: 401 when the inbox does not exist or the token is not accepted, 413 if the body is too large, 429 if the inbox is full.

The relay MUST NOT reveal whether a 401 was caused by an unknown inbox or by an unknown token; both get the same response.

6.5 Collecting (owner)

GET /v1/inbox/<inbox ID>/messages returns up to 20 of the oldest messages:

{"messages": [
  {"id": "<relay message id>", "received": 1795000000,
   "token": "<token ID it arrived with>", "body": "<base64url sealed message>"}
]}

DELETE /v1/inbox/<inbox ID>/messages/<relay message id> removes one message (204, also when it no longer exists).

Collecting does not remove messages; the recipient deletes each one after handling it. A message that is never deleted is removed by the relay after retention_seconds.

Clients SHOULD poll no more often than once every 30 seconds.

7. Tickets

A ticket describes content, not printer commands. Every recipient renders it in its own way, for its own paper width.

{"blocks": [
  {"type": "text", "text": "Hallo!", "size": "large", "align": "center", "bold": true},
  {"type": "divider"},
  {"type": "list", "style": "check", "items": ["melk", "brood"]},
  {"type": "qr", "data": "https://example.com"}
]}

7.1 Blocks

Type Members Meaning
text text; optional align (left, center, right), bold, underline, size (small, normal, large, huge) A paragraph. Line breaks in text are kept; the recipient wraps long lines.
divider A horizontal rule.
list items (strings); optional style (bullet, number, check) A list. check draws a box to tick.
qr data; optional caption A QR code containing data.
image png (base64url PNG); optional alt, align A picture, at most 576 pixels wide and 1200 high. Recipients scale it to their paper and convert it to black and white.
space optional lines (1 to 5) Blank lines.

Rules:

7.2 What a recipient must never do

8. Recipient policy

Paper comes out in someone's home, so the recipient's rules always win. A recipient:

9. Security notes