A gRPC-based delivery service for MLS messaging that will eventually handle all core MLS functionality using OpenMLS and persists state to PostgreSQL using SQLx.
This delivery service provides:
- Client registration and identity management
- KeyPackage publication and retrieval
- MLS group creation and management
- Secure storage of MLS messages (proposals, commits, welcome)
- Membership tracking for groups
- Rust 1.70+ and Cargo
- PostgreSQL 12+
Create the following tables in your PostgreSQL database:
CREATE TABLE groups (
id UUID PRIMARY KEY,
creator_id UUID NOT NULL,
epoch BIGINT NOT NULL DEFAULT 0,
state BYTEA,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
is_active BOOLEAN NOT NULL DEFAULT true
);CREATE TABLE clients (
id UUID PRIMARY KEY,
user_id UUID NOT NULL,
credential BYTEA NOT NULL,
scheme TEXT NOT NULL,
device_name TEXT NOT NULL,
last_seen TIMESTAMPTZ NOT NULL DEFAULT now(),
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);CREATE TABLE memberships (
id UUID PRIMARY KEY,
client_id UUID NOT NULL REFERENCES clients(id),
group_id UUID NOT NULL REFERENCES groups(id),
role TEXT NOT NULL,
added_at TIMESTAMPTZ NOT NULL DEFAULT now(),
removed_at TIMESTAMPTZ
);CREATE TABLE messages (
id UUID PRIMARY KEY,
group_id UUID NOT NULL REFERENCES groups(id),
sender_id UUID NOT NULL REFERENCES clients(id),
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
read BOOLEAN NOT NULL DEFAULT false,
message_type TEXT NOT NULL,
proposal BYTEA,
commit BYTEA,
welcome BYTEA,
proposal_type TEXT,
epoch BIGINT,
recipients UUID[]
);CREATE TABLE key_packages (
id UUID PRIMARY KEY,
client_id UUID NOT NULL REFERENCES clients(id),
data BYTEA NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
used BOOLEAN NOT NULL DEFAULT false
);Create a .env file with the following configuration:
# PostgreSQL configuration
DATABASE_URL=postgres://username:password@localhost/mlsdb
# Logging level (debug, info, warn, error)
RUST_LOG=info
# Address to bind the server to
ADDR=0.0.0.0:50051
# Build the project
cargo build --release
# Run the service
cargo run --releaseThe service exposes the following gRPC endpoints:
RegisterClient: Register a new client with credentialGetClient: Retrieve client informationListClients: List all clients for a user
PublishKeyPackage: Publish a key package for a clientGetKeyPackage: Retrieve a specific key packageListKeyPackages: List all key packages for a client
CreateGroup: Create a new MLS groupGetGroup: Retrieve group informationListGroups: List all groups a client is a member of
AddMember: Add a client to a groupRemoveMember: Remove a client from a groupListMemberships: List all memberships for a group
StoreProposal: Store an MLS proposal messageStoreCommit: Store an MLS commit messageStoreWelcome: Store an MLS welcome messageFetchMessages: Fetch messages for a client
This service uses SQLx to connect to PostgreSQL. SQLx is:
- An async, pure Rust SQL crate featuring compile-time checked queries
- Supporting PostgreSQL, MySQL, SQLite, and MSSQL
- Fully asynchronous using Tokio for database operations
The application follows a repository pattern with a clean separation between:
- Database interface definition (
DatabaseInterfacetrait) - Implementation for PostgreSQL (
PostgresDatabase) - Service layer implementing the gRPC methods
- All MLS cryptographic operations are handled by the OpenMLS library
- Messages are stored in encrypted form as provided by the clients
- Always use a secure, limited-permission database user in production
See the LICENSE file for details.
The project includes comprehensive integration tests to verify the functionality of the MLS Delivery Service. The tests use a mock database implementation to avoid external dependencies.
To run the tests, use the following command:
cargo testThe integration tests cover:
- Client registration and lifecycle
- Key package publishing and management
- Group creation and management
- Message delivery (proposals, commits, and welcome messages)
- Error handling
tests/common.rs- Common utilities and mock database implementationtests/integration_tests.rs- Basic service functionality teststests/client_lifecycle_tests.rs- Tests for client registration and managementtests/welcome_test.rs- Tests for welcome message handlingtests/error_handling_tests.rs- Tests for error conditions and edge cases
