(user, client instance)
tuple is associated with a deviceId
, which identifies that device and is used to establish peer-to-peer encrypted sessions for the purpose of sharing group message encryption keys.
Devices are objects storing key material created on the client and stored in the Towns Node on the user’s UserDeviceKey
stream containing the following pair of keys:
UserDeviceKey
stream. This key along with the following key are used by other user’s to establish secure and ephemeral p2p sessions.Device lifecycle is outside of the purview of the Towns protocol and managed entirely by client implementations. However, given it is expected under the protocol that there exists a 1-1 relation between(user, client instance)
tuples anddevices
, the Towns Node performs periodic compaction criteria to stem the uncontrolled growth of user’s device key stream in storage.
session_id
is used to identify the keys associated with the ciphertext, which can be used to decrypt the same message multiple times. This is particularly useful in a group messaging application as it avoids the need to re-establish peer-to-peer encrypted sessions
for each message.
Peer to peer encryption sessions are only used to transmit session keys corresponding to message events and are described by the following protobuf in the protocol.
outbound
sender’s session was created for. In general, peer-to-peer encrypted messages are encrypted in a per device basis.
device
, and joins a Space.KeySolicitation
message with a device_key
corresponding to Alice’s device.isEntitled
to decryption keys for the channel stream that the solicitation event appeared in and creates a new p2p encrypted outbound
session using Alice’s device key and fallback key to transmit the keys requested from his local cache.ack
to the stream to notify other co-members of the channel that Alice’s request is being worked on.UserToDevice
key stream and created a new inbound
session with Bob’s device key and fallback key obtained from his UserDeviceKey
stream.session_id
of the keys she now has in her possession.Peer-to-peer encryption in Towns requires distinct sessionsoutbound
,inbound
for encryption and decryption, respectively. Moreover, each message can only be decrypted once per established session.
KeySolicitation
event on the stream, which any online member of the stream will see and conditionally service if the solicitator is an entitled member of the stream.
KeySolicitation
, and KeyFulfillment
messages. Since fulfilling a solicitation requires creating a peer-to-peer encrypted session with the solicitator, the device_key
and fallback_key
are added to the payload to save a lookup against the UserDeviceKey
stream. Fulfillments are synced by members of the same stream to avoid the worst case behavior of every member fulfilling every request in a duplicative manner.