Skip to content

How it Works

Jay R Bolton edited this page Oct 3, 2017 · 10 revisions

dat-pki combines all the peer-to-peer networking features from dat with an extra layer of cryptography for identity management and user-to-user interaction. It is a Node module and can have add-on modules, a CLI, and different UIs in the future.

This is a high-level description of how everything works (or will work) under this system.

About dat

Dat is a Nodejs-based peer-to-peer file sharing protocol similar to Bittorrent or IPFS, but with improved features for data that changes over time with versioning. In this doc, a "dat" refers to a shared directory. A dat can contain any files, and in this library often one dat will contain metadata about other dats. Each dat has an key or link that is unique, private, and gives download access to anyone who has the address.

User setup

A new user is created by entering a user-name (which can be any string) and a passphrase. Using the passhprase, a public and private key pair is generated. Encryption in dat-pki (as well as dat) uses libsodium with elliptic-curve cryptography.

For each new user, a new dat is created that holds all the user's public metadata, which is called their public dat. This public dat holds the user's public key for other users to download. Each user also gets assigned a unique ID that is separate from their public dat address. User accounts can span multiple devices, so they can keep the same user ID on every device.

Sharing your link

You can share the link to your public dat by sending it to your friends, posting it on your website, etc. Other users can "follow" you by saving your link into their own account, which allows them to view and download all your public information, including links to other dats that you share.

Creating a dat and encrypting its contents

A user can create a new dat to store their documents, photos, spreadsheets, etc. If the device the user is on is untrusted (such as a third-party server), they can use their user's private key to encrypt all the files.

Sharing a dat publicly

After a user has created a dat, they can choose to make it public. The address of the dat is placed in the user's public dat, so that anyone else can freely see the dat address and download the files if they follow the user.

Following someone's public activity

In order for user A to follow the public activity of user B, user A can simply enter user B's public dat address. This public data can include a web page for their user profile and links to other dats they have shared. To download these files, user A will download user B's public dat into a follows directory. Whenever user B creates any new dats and publicizes them, then user A will see the updates. Any other public activity that user B wishes to share with their followers will automatically become visible, because each of their followers can continuously download updates from user B's public dat.

Adding a private contact relationship

Two users can share private data back and forth in a one-to-one communication channel by first establishing a shared private dat using their public/private keys.

When user A initiates a handshake with user B, user A creates a new dat. This new dat is called a relationship dat and will hold all the communication data that user A wants to send to user B. The address of this dat is kept totally private.

User A encrypts the address of the relationship dat using user B's public key, which user A can download from user B's public dat. User A then places the encrypted address of the relationship dat into their own public dat inside a handshakes folder. The filename of this encrypted address is set to be user B's ID.

When user B checks the status of the handshake with user A, user B reads user A's public dat and sees a handshake file that has user B's ID as the filename. User B then decrypts the handshake file using their own private key, and is able to read the address of the relationship dat that user A has created. User B saves that address privately and regularly downloads any changes.

Each 1:1 private communication channel has two different relationship dats: one for uploading data to the other user, and one for downloading data from the other user. Both relationship dats need to get created using the above handshake process.

Now that this "relationship dat" has been created, the two users can privately share arbitrary data with each other (including links pointing to other dats).

Verifying the contact's identity

In order to verify that a user's account is actually the correct person, and not some impostor, we can initially use the PGP-style web of trust system. Each user can sign the public keys of each of their contacts whose identity they trust. When you add a new contact, you can view the signatures of other contacts you have in common who have vouched for this account and use this as the basis for verifying their identity. In the PGP world, it is common to have in-person "signing parties" to initially establish these trust networks.

User Groups

One way to easily share data with multiple people at once is to first assign a tag to a number of users. You can then share some data with that tag, which is equivalent to sharing the same data with all the users in the tag.

In the future, we can think about more robust systems for multi-write groups with permission levels.

Group identity

For a more fine-grained approach to groups, a "group identity" can get created with its own keypair:

  • Generate a new key pair for the group and keep both keys private. One key is a write key and one is a read key (the write key is the "public key" and the read key is the "private key"---however, both are kept private)
  • Grant read access to a user by taking the group's read key and encrypting it using the user's own public key, then sending the encrypted version to them so they can store it
  • Grant write access to a user by taking the group's write key and also encrypting using a user's public key. Revoke access by creating a new group key pair and re-sending all the user-encrypted keys.

More details are yet to be explored.

Sharing encrypted files

If you share a dat on an untrusted device with all the files inside encrypted, then those files will get re-encrypted using all the public keys for each user who needs access. This hasn't been implemented yet, and will have more details soon.

Device networks and replication

Both user accounts and groups can span multiple devices. When a user account has multiple devices, a different keypair is generated for the other device, and all the metadata for the user is replicated. The user can control which of their dats they want to download on each device. When a group has multiple devices, then the group dat is replicated across the devices, and the admin of the group can control which device downloads and syncs which dats in the group.

Most dat uploads for user accounts on laptops and phones/tablets will have unreliable availability. Adding cheap, always-on, encrypted cloud-based backup nodes (such as with Amazon AWS, Digital Ocean) to a user account could be totally automated. There could also be a light weight linux VM that could gets installed on cheap boxes for always-on home or office backup

You can also have multiple user accounts on a single device (they only need to have separate user directories on the device).

Research areas

  • Multi-writing (eg conflict resolution) and permission levels for group data
  • Stream-lining contact handshake process
  • Use of bitcoin blockchain to supplement key signing/web of trust (various papers)
  • integration of p2p web applications / web pages and hyperdb
  • creating friendlier formats for the dat links allowing people to share them more easily
  • handling password recovery