This NKP proposes a pub/sub permission control mechanism that can be implemented purely on the client side.
Design Goal
We want to achieve the following goal:
- each group has an owner
- owner decides who can join the group (everyone, whitelist, or blacklist)
- members can be removed by owner from the group
- only group members can send message to the group
Protocol
Join Group
When client wants to join group name
owned by user whose public key is pubkey
, client subscribes to topic name.pubkey
.
Set/Update Permission
When owner wants to set or update who can join the group, he subscribes with a certain family of identifiers, e.g. __0__.__permission__
, __1__.__permission__
, __2__.__permission__
âŚ, and put permission control information in the subscribe metadata. He can use { "accept": ["*"] }
to allow everyone to join, or { "accept": [{"addr": "addr1"}, {"pubkey": "pk1"}, ...] }
to accept a list of address or pubkey (whitelist), or { "reject": [{"addr": "addr1"}, {"pubkey": "pk1"}, ...] }
to reject a list of address or pubkey (blacklist). Because of metadata size limit, he might use multiple identifiers to store the permission control list.
Get Permission
When anyone wants to get permission control information of a group name
owned by pubkey
, he first gets all subscriptions of topic name.pubkey
, filter out all subscriptions __0__.__permission__.pubkey
, __1__.__permission__.pubkey
, __2__.__permission__.pubkey
âŚ, and merge metadata of these subscriptions. Then he can compute the permission control information of the group.
Publish Message
When a client wants to publish a message to the group name
owned by pubkey
, he gets both subscribers of the topic name.pubkey
and permitted users of the group. Then he sends message to addresses that are both subscribed to the topic and are permitted to the group.
Receive Message
When a client receives a message from a group, he checks if the sender is in the permitted users of the group. If not, client will discard the message.
Attack Resistant
Malicious clients can try to subscribe to the topic or publish message to group members, but honest clients, as long as follow the protocol, will not send any message to or handle message from malicious clients.
Extension
The above basic protocol can be further extended by storing more information in ownerâs subscribe metadata. For example, one can have different permission control for sender and receiver, or add other users as admin, etc.