This section contains an advanced discussion of Ditto’s underlying certificate, identity, and encryption implementation. Most readers can skip this section. However, if you are deploying an enterprise on-premises deployment of Ditto, you may be required to reference the following material.
Capability | Type |
---|---|
Encryption | TLS 1.3 |
Authentication | EC key-pairs with signed certificates |
Trust infrastructure | X.509 with a developer-controlled certificate authority |
Access Rules | Query patterns on Document _id’s describing read and or write access |
Identities
An identity is a bundle of the device and app-specific information:Production | Development | ||
---|---|---|---|
Site ID | Allocated by central authority | Defaults to a random number; can be customized | |
App ID | Set by central authority | For example, “5322afcd-5a70-43a3-bc2d-85d98ccf5ac0” | |
Access Rules | Set by central authority | All devices may read/write all documents | |
Private Key | Either generated on device or distributed by central authority | Hard-coded and shared by all devices | |
Identity Certificate | Unique and signed by a central authority; contains this device’s public key | Hard-coded and shared by all devices | |
CA Certificate | Shared by all users of the same app | Hard-coded and shared by all devices |
Certificates
Ditto identities and public keys are distributed in the standard X.509 certificate format. They do not directly contain potentially sensitive data such as access rules, but these can be defined by the app’s authentication webhook with the OnlineWithAuthentication identity, or by the developer through theManual
identity.
When you are ready to use production identities, feel free to contact us through the Ditto Portal and we will help you set up the right CA tooling for your use case - or provide specifications so you can build your own.
Discovering peers
Devices need to have the same AppID to discover other peers on the network, as well as matching certificates to connect over TLS 1.3. Peer-to-peer connections use mTLS (client certificates) with TLS 1.3. Connections to Ditto Server use a TLS-secured WebSocket connection, with authentication by JWT. Once the certificates match, then the embedded authorization information inside each certificate is used to authorize any incoming requests by that peer. This ensures that those access control rules are enforced.Syncing with Ditto Server
The description below covers internal details of the Ditto Server implementation. Ditto’s authentication module handles this implementation for you under the hood as part of the
OnlineWithAuthentication
and OnlinePlayground
identities.Overview
Online Authentication can be used when a Ditto application is hosted on Ditto Server. Ditto Server hosts an HTTPS identity service, which handles login requests. In Online Authentication mode, a Small Peer must log in with credentials before it can communicate with any peers. The login flow populates the Small Peer with valid authentication material that identifies the user and defines their level of access. Once the Small Peer receives this data after a successful login, the transports which depend on it will start automatically.1
Complete a Peer Key Challenge
The peer’s public key will be included in the certificates returned by the identity service. The identity service needs proof that the authenticating Small Peer actually holds the corresponding private key.
- Small Peer downloads a challenge token from
/_ditto/auth/cert
- this is a time-limited JWT which the client treats as opaque data. - Small Peer uses their Peer Key to sign it.
2
Log in with Credentials
When a client attempts to authenticate, it will make an HTTPS request to the identity service containing the following payload:
- Signed challenge
- App ID
- Provider name
- Credentials to be forwarded to the app’s webhook handler
Rationale
Why does X.509 return both a key and a certificate instead of locally generating a key and sending a CSR? It would be possible to use a standard CSR flow. It was chosen to issue keys directly for a few reasons.- There is no security benefit as our certificate request is in a secured tunnel, and the identity service is presumed to be completely trustworthy.
- Validating and signing CSRs is more complex than simply creating one with the correct format and fields.
- This is a convenient workflow if using Hashicorp Vault or similar to manage your PKI and issue certificates on demand.