11 KiB
Table of Contents
- Terminology
- Basic Assumption
- Protocol Overview
- Whisper adapter
- Perfect Forward Secrecy (PFS)
- Device syncing
- One-to-one messages
- Public messages
- Group messages
- Offline messages
- Whisper V6 extensions (or Status Whisper Node)
Terminology
- Client: a Whisper node implementing the protocol
- Whisper node: an Ethereum node with Whisper V6 enabled (in the case of geth, it's
--shh
option) - Status Whisper node: an Ethereum node with Whisper V6 enabled and additional Whisper extensions described in Whisper V6 extensions (or Status Whisper Node)
- Whisper network: a group of Whisper nodes connected together through the internet connection and forming a graph
- MailServer: an Ethereum node with Whisper V6 enabled and a mail server registered capable of storing and providing offline messages
- Message: decrypted Whisper message
- Envelope: encrypted message with some metadata like topic and TTL sent between Whisper nodes; a symmetric or asymmetric key is needed to decrypt it and read the payload
- Offline message: an expired envelope stored by a Whisper node permanently
Basic Assumption
This protocol assumes the following:
- There MUST be an Ethereum node that is capable of discovering peers and implements Whisper V6 specification.
- Participants of a given Whisper network in order to communicate with each other MUST accept messages with lowered PoW value. More in (Whisper node configuration)(#whisper-node-configuration).
- Time MUST be synced between all nodes participating in the given network (this is intrinsic requirement of the Whisper specification as well). A clock drift between two peers larger than 20 seconds MAY result in discarding incoming messages.
Perfect Forward Secrecy (PFS)
Additionally to encrypting messages on the Whisper level, the protocol supports PFS specification.
A message payload is first encrypted following the PFS specification and then it is encrypted once again following the Whisper specification and this protocol.
As not all messages are encrypted with PFS, a following strategy MAY be used:
- First, message is decrypted on the Whisper level
- Try to decrypt the message payload using PFS algorithm 2.1. If successful, pass the decrypted value to (3) 2.2. If failed, pass the unchanged payload to (3)
- Decode the payload as described in Payload section
TODO: link to a separate document (currently in the PR).
Device syncing
TODO: link to a separate document.
One-to-one messages
One-to-one messages are also known as private messages. These are the messages sent between two participants of the conversation.
Sending
Sending a message is fairly easy and relies on the Whisper RPC API, however, some preparation is needed:
- Obtain a public key of the recipient of the message
- Add your private key to Whisper using
shh_addPrivateKey
and save the result assigKeyID
- Call [
shh_post
(https://github.com/ethereum/go-ethereum/wiki/Whisper-v6-RPC-API#shh_post) with the following settings:pubKey
MUST be a hex-encoded public key of the message recipientsig
MUST be set tosigKeyID
ttl
MUST be at least10
(it is in seconds)topic
MUST be set accordingly to Topic section and hex-encodedpayload
MUST be a hex-encoded stringpowTime
MAY be arbitrary but should be enough to perform proof-of-workpowTarget
MUST be equal or lower than0.002
.
Note: these instructions are for the Whisper V6 RPC API. If you use Whisper service directly or Go shhclient
, the parameters might have different types.
Learn more following Whisper V6 RPC API.
Sending using PFS
When one decides to use PFS, the flow is the same but the payload MUST be additionally encrypted following the PFS specification before being hex-encoded and passed to shh_post
.
Receiving
Receiving private messages depends on Whisper filters idea. Upon receiving, messages are first matched by a topic and then trying to be decrypted using user's private key.
- Add your private key to Whisper using
shh_addPrivateKey
and save the result assigKeyID
- Call
shh_subscribe
with criteria:minPow
MUST be at least0.002
topics
MUST be list of hex-encoded topics you expect messages to receive from (follow Topic section)allowP2P
MUST be set totrue
if offline messages are supported, otherwise can befalse
.
Alternative method is to use shh_newMessageFilter
which takes the same criteria object and then periodically calling shh_getFilterMessages
method.
Learn more following Whisper V6 RPC API.
Public messages
Public messages are encrypted with a symmetric key which is publicly known so anyone can participate in the conversation.
The fact that anyone can participate makes the public chats vulnerable to spam attacks. Also, there are no moderators of these chats.
Sending
- Calculate a symmetric key using
shh_generateSymKeyFromPassword
passing a public chat name as a string and save the result tosymKeyID
- Call
shh_post
with the following settings:symKeyID
MUST be set tosymKeyID
sig
MUST be set tosigKeyID
ttl
MUST be at least10
(it is in seconds)topic
MUST be set accordingly to Topic section and hex-encoded,payload
MUST be a hex-encoded string,powTime
MAY be arbitrary but should be enough to perform proof-of-workpowTarget
MUST be equal or lower than0.002
.
Learn more following Whisper V6 RPC API.
Receiving
Receiving public messages depends on Whisper filters idea. Upon receiving, messages are first matched by a topic and then trying to be decrypted using a symmetric key.
- Calculate a symmetric key using
shh_generateSymKeyFromPassword
passing public chat name as a string and save the result tosymKeyID
- Call
shh_subscribe
with criteria:minPow
MUST be at least0.002
topics
MUST be list of hex-encoded topics you expect messages to receive from (follow Topic section)allowP2P
MUST be set totrue
if offline messages are supported, otherwise can befalse
.
Alternative method is to use shh_newMessageFilter
which takes the same criteria object and then periodically calling shh_getFilterMessages
method.
Learn more following Whisper V6 RPC API.
Group messages
TODO: describe how to send a group message starting from adding a key in Whisper etc.
Offline messages
In the case of mobile clients which are often offline, there is a strong need to have an ability to download offline messages. By offline messages, we mean messages sent into the Whisper network and expired before being collected by the recipient. A message stays in the Whisper network for a duration specified as TTL
(time-to-live) property.
A Whisper client needs to register a mail server instance which will be used by geth's Whisper service.
MailServer
is an interface with two methods:
Archive(env *Envelope)
DeliverMail(whisperPeer *Peer, request *Envelope)
If a mail server is registered for a given Whisper client, it will save all incoming messages on a local disk (this is the simplest implementation, it can store the messages wherever it wants, also using technologies like swarm and IPFS) in the background.
Notice that each node is meant to be independent and SHOULD keep a copy of all historic messages. High Availability (HA) can be achieved by having multiple nodes in different locations. Additionally, each node is free to store messages in a way which provides storage HA as well.
Saved messages are delivered to a requester (another Whisper peer) asynchronously as a response to p2pMessageCode
message code. This is not exposed as a JSON-RPC method in shh
namespace but it's exposed in status-go as shhext_requestMessages
and blocking shh_requestMessagesSync
. Read more about Whisper V6 extensions.
In order to receive historic messages from a filter, p2p messages MUST be allowed when creating the filter. Receiving p2p messages is implemented in geth's Whisper V6 implementation.
Anonymity concerns
In order to use a mail server, a given node needs to connect to it directly, i.e. add the mail server as its peer and mark it as trusted. This means that the mail server is able to send direct p2p messages to the node instead of broadcasting them. Effectively, it knows which topics the node is interested in, when it is online as well as many metadata like IP address.