Compare commits
17 Commits
aa29d3bc34
...
d469999c2a
| Author | SHA1 | Date | |
|---|---|---|---|
| d469999c2a | |||
| f0901f6597 | |||
| 543bd442a3 | |||
| 266bcfed59 | |||
| c256c38ffb | |||
| 416618f4cf | |||
| 872695e5f1 | |||
| e4c5868b31 | |||
| 66eca065e0 | |||
| a05da9b751 | |||
| 077f48f19c | |||
| 3708b8df41 | |||
| b98dcc27ae | |||
| 2e081ead8e | |||
| a710037dde | |||
| d8c1392587 | |||
| a9d1f535aa |
20
.env.example
20
.env.example
@@ -1,20 +1,20 @@
|
|||||||
# quicproquo Production Environment Variables
|
# quicprochat Production Environment Variables
|
||||||
# Copy this file to .env and fill in the values.
|
# Copy this file to .env and fill in the values.
|
||||||
|
|
||||||
# Server auth token (required, >= 16 characters)
|
# Server auth token (required, >= 16 characters)
|
||||||
QPQ_AUTH_TOKEN=
|
QPC_AUTH_TOKEN=
|
||||||
|
|
||||||
# SQLCipher database encryption key (required for store_backend=sql)
|
# SQLCipher database encryption key (required for store_backend=sql)
|
||||||
QPQ_DB_KEY=
|
QPC_DB_KEY=
|
||||||
|
|
||||||
# Ports (defaults shown)
|
# Ports (defaults shown)
|
||||||
QPQ_LISTEN_PORT=7000
|
QPC_LISTEN_PORT=7000
|
||||||
QPQ_WS_PORT=9000
|
QPC_WS_PORT=9000
|
||||||
|
|
||||||
# Optional features
|
# Optional features
|
||||||
QPQ_SEALED_SENDER=false
|
QPC_SEALED_SENDER=false
|
||||||
QPQ_REDACT_LOGS=true
|
QPC_REDACT_LOGS=true
|
||||||
QPQ_WS_LISTEN=
|
QPC_WS_LISTEN=
|
||||||
|
|
||||||
# Grafana admin password
|
# Grafana admin password (required — must be strong, no default)
|
||||||
GRAFANA_ADMIN_PASSWORD=changeme
|
GRAFANA_ADMIN_PASSWORD=
|
||||||
|
|||||||
20
.github/CODEOWNERS
vendored
20
.github/CODEOWNERS
vendored
@@ -1,4 +1,4 @@
|
|||||||
# Code owners for quicproquo. PRs require review from owners.
|
# Code owners for quicprochat. PRs require review from owners.
|
||||||
# See https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners
|
# See https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners
|
||||||
# Replace 'maintainers' with your GitHub user/team handle.
|
# Replace 'maintainers' with your GitHub user/team handle.
|
||||||
|
|
||||||
@@ -6,32 +6,32 @@
|
|||||||
* @maintainers
|
* @maintainers
|
||||||
|
|
||||||
# Security-critical: crypto primitives, MLS, hybrid KEM
|
# Security-critical: crypto primitives, MLS, hybrid KEM
|
||||||
/crates/quicproquo-core/ @maintainers
|
/crates/quicprochat-core/ @maintainers
|
||||||
|
|
||||||
# Wire format: protobuf definitions, Cap'n Proto schemas
|
# Wire format: protobuf definitions, Cap'n Proto schemas
|
||||||
/crates/quicproquo-proto/ @maintainers
|
/crates/quicprochat-proto/ @maintainers
|
||||||
/proto/ @maintainers
|
/proto/ @maintainers
|
||||||
|
|
||||||
# Auth and server-side domain logic
|
# Auth and server-side domain logic
|
||||||
/crates/quicproquo-server/ @maintainers
|
/crates/quicprochat-server/ @maintainers
|
||||||
|
|
||||||
# Client SDK: auth, conversation store, messaging pipeline
|
# Client SDK: auth, conversation store, messaging pipeline
|
||||||
/crates/quicproquo-sdk/ @maintainers
|
/crates/quicprochat-sdk/ @maintainers
|
||||||
|
|
||||||
# CLI/TUI client
|
# CLI/TUI client
|
||||||
/crates/quicproquo-client/ @maintainers
|
/crates/quicprochat-client/ @maintainers
|
||||||
|
|
||||||
# RPC framework: framing, middleware, QUIC transport
|
# RPC framework: framing, middleware, QUIC transport
|
||||||
/crates/quicproquo-rpc/ @maintainers
|
/crates/quicprochat-rpc/ @maintainers
|
||||||
|
|
||||||
# Key transparency
|
# Key transparency
|
||||||
/crates/quicproquo-kt/ @maintainers
|
/crates/quicprochat-kt/ @maintainers
|
||||||
|
|
||||||
# Plugin ABI (no_std C-ABI boundary)
|
# Plugin ABI (no_std C-ABI boundary)
|
||||||
/crates/quicproquo-plugin-api/ @maintainers
|
/crates/quicprochat-plugin-api/ @maintainers
|
||||||
|
|
||||||
# P2P transport
|
# P2P transport
|
||||||
/crates/quicproquo-p2p/ @maintainers
|
/crates/quicprochat-p2p/ @maintainers
|
||||||
|
|
||||||
# CI and infrastructure
|
# CI and infrastructure
|
||||||
/.github/ @maintainers
|
/.github/ @maintainers
|
||||||
|
|||||||
2
.github/workflows/bench.yml
vendored
2
.github/workflows/bench.yml
vendored
@@ -35,7 +35,7 @@ jobs:
|
|||||||
${{ runner.os }}-bench-
|
${{ runner.os }}-bench-
|
||||||
|
|
||||||
- name: Run benchmarks
|
- name: Run benchmarks
|
||||||
run: cargo bench --package quicproquo-core -- --output-format=bencher 2>&1 | tee bench-output.txt
|
run: cargo bench --package quicprochat-core -- --output-format=bencher 2>&1 | tee bench-output.txt
|
||||||
|
|
||||||
- name: Upload HTML reports
|
- name: Upload HTML reports
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
|
|||||||
53
.github/workflows/ci.yml
vendored
53
.github/workflows/ci.yml
vendored
@@ -102,7 +102,7 @@ jobs:
|
|||||||
- name: Run coverage
|
- name: Run coverage
|
||||||
run: |
|
run: |
|
||||||
cargo tarpaulin --workspace \
|
cargo tarpaulin --workspace \
|
||||||
--exclude quicproquo-p2p \
|
--exclude quicprochat-p2p \
|
||||||
--out xml \
|
--out xml \
|
||||||
--output-dir coverage/ \
|
--output-dir coverage/ \
|
||||||
-- --test-threads 1
|
-- --test-threads 1
|
||||||
@@ -113,6 +113,57 @@ jobs:
|
|||||||
name: coverage-report
|
name: coverage-report
|
||||||
path: coverage/cobertura.xml
|
path: coverage/cobertura.xml
|
||||||
|
|
||||||
|
msrv:
|
||||||
|
name: MSRV Check
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install MSRV Rust (1.75)
|
||||||
|
uses: dtolnay/rust-action@1.75
|
||||||
|
with:
|
||||||
|
components: clippy
|
||||||
|
|
||||||
|
- name: Install capnp
|
||||||
|
run: sudo apt-get update && sudo apt-get install -y capnproto
|
||||||
|
|
||||||
|
- name: Cache cargo
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.cargo/registry
|
||||||
|
~/.cargo/git
|
||||||
|
target
|
||||||
|
key: ${{ runner.os }}-msrv-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-msrv-
|
||||||
|
|
||||||
|
- name: Check MSRV
|
||||||
|
run: cargo check --workspace
|
||||||
|
|
||||||
|
macos:
|
||||||
|
name: macOS Build Check
|
||||||
|
runs-on: macos-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install Rust
|
||||||
|
uses: dtolnay/rust-action@stable
|
||||||
|
|
||||||
|
- name: Cache cargo
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.cargo/registry
|
||||||
|
~/.cargo/git
|
||||||
|
target
|
||||||
|
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-cargo-
|
||||||
|
|
||||||
|
- name: Check build
|
||||||
|
run: cargo check --workspace
|
||||||
|
|
||||||
docker:
|
docker:
|
||||||
name: Docker Build
|
name: Docker Build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|||||||
8
.github/workflows/openwrt.yml
vendored
8
.github/workflows/openwrt.yml
vendored
@@ -43,11 +43,11 @@ jobs:
|
|||||||
CARGO_PROFILE_RELEASE_CODEGEN_UNITS: '1'
|
CARGO_PROFILE_RELEASE_CODEGEN_UNITS: '1'
|
||||||
CARGO_PROFILE_RELEASE_STRIP: symbols
|
CARGO_PROFILE_RELEASE_STRIP: symbols
|
||||||
run: |
|
run: |
|
||||||
cargo zigbuild --release --target ${{ matrix.target }} --bin qpq-server
|
cargo zigbuild --release --target ${{ matrix.target }} --bin qpc-server
|
||||||
|
|
||||||
- name: Check binary size
|
- name: Check binary size
|
||||||
run: |
|
run: |
|
||||||
BINARY="target/${{ matrix.target }}/release/qpq-server"
|
BINARY="target/${{ matrix.target }}/release/qpc-server"
|
||||||
SIZE=$(stat -c%s "$BINARY")
|
SIZE=$(stat -c%s "$BINARY")
|
||||||
SIZE_MB=$(echo "scale=2; $SIZE / 1048576" | bc)
|
SIZE_MB=$(echo "scale=2; $SIZE / 1048576" | bc)
|
||||||
echo "Binary size: ${SIZE_MB} MB"
|
echo "Binary size: ${SIZE_MB} MB"
|
||||||
@@ -60,6 +60,6 @@ jobs:
|
|||||||
- name: Upload artifact
|
- name: Upload artifact
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: qpq-server-${{ matrix.target }}
|
name: qpc-server-${{ matrix.target }}
|
||||||
path: target/${{ matrix.target }}/release/qpq-server
|
path: target/${{ matrix.target }}/release/qpc-server
|
||||||
retention-days: 30
|
retention-days: 30
|
||||||
|
|||||||
10
.gitignore
vendored
10
.gitignore
vendored
@@ -16,4 +16,12 @@ data/
|
|||||||
*.convdb-shm
|
*.convdb-shm
|
||||||
*.convdb-wal
|
*.convdb-wal
|
||||||
*.pending.ks
|
*.pending.ks
|
||||||
qpq-server.toml
|
qpc-server.toml
|
||||||
|
|
||||||
|
# Internal planning docs (not for public distribution)
|
||||||
|
docs/internal/
|
||||||
|
|
||||||
|
# AI development workflow files
|
||||||
|
CLAUDE.md
|
||||||
|
master-prompt.md
|
||||||
|
scripts/ai_team.py
|
||||||
|
|||||||
23
CLAUDE.md
23
CLAUDE.md
@@ -1,23 +0,0 @@
|
|||||||
# quicproquo — Claude Code Instructions
|
|
||||||
|
|
||||||
## Agent Team Workflow Rules
|
|
||||||
|
|
||||||
### NEVER delete worktrees before preserving changes
|
|
||||||
When using agent teams with `isolation: "worktree"`:
|
|
||||||
1. **Before calling `TeamDelete`**, always check each worktree for uncommitted or committed changes
|
|
||||||
2. **Create a named branch** from each worktree's HEAD and push/preserve it before cleanup
|
|
||||||
3. **Preferred pattern**: use `git branch fix/<name> <worktree-HEAD-sha>` to save the work
|
|
||||||
4. If an agent reports changes, its worktree branch MUST be merged or saved before the team is deleted
|
|
||||||
|
|
||||||
### Agent team best practices
|
|
||||||
- Always have agents **commit their changes** with descriptive messages before shutting them down
|
|
||||||
- After all agents report, **list worktrees** (`git worktree list`) and **save branches** before cleanup
|
|
||||||
- When using worktree isolation, the sequence must be: agents finish → save branches → merge → TeamDelete
|
|
||||||
- Never call TeamDelete as a shortcut to kill zombie agents — use `rm -rf ~/.claude/teams/<name>` for the team metadata only, preserving worktree dirs
|
|
||||||
|
|
||||||
### Git workflow
|
|
||||||
- Conventional commits: `feat:`, `fix:`, `chore:`, `docs:`, `test:`, `refactor:`
|
|
||||||
- GPG-signed commits only
|
|
||||||
- No `Co-authored-by` trailers
|
|
||||||
- No `.unwrap()` on crypto or I/O in non-test paths
|
|
||||||
- Secrets: zeroize on drop, never in logs
|
|
||||||
40
CONTRIBUTING.md
Normal file
40
CONTRIBUTING.md
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
# Contributing to quicprochat
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
- **Rust toolchain** (stable) via [rustup](https://rustup.rs/)
|
||||||
|
- **protoc** is vendored via the `protobuf-src` crate -- no system installation needed
|
||||||
|
- Git with GPG signing configured
|
||||||
|
|
||||||
|
## Building and Testing
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cargo build --workspace
|
||||||
|
cargo test --workspace
|
||||||
|
```
|
||||||
|
|
||||||
|
A `justfile` is also available for common tasks (`just build`, `just test`, `just proto`, etc.).
|
||||||
|
|
||||||
|
## Code Standards
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- **Conventional commits**: `feat:`, `fix:`, `docs:`, `chore:`, `test:`, `refactor:`
|
||||||
|
- Commits must be **GPG-signed**
|
||||||
|
- Commit messages describe *why*, not just *what*
|
||||||
|
- No `Co-authored-by` trailers
|
||||||
|
|
||||||
|
### Rust
|
||||||
|
|
||||||
|
- No `.unwrap()` on crypto or I/O operations outside of tests
|
||||||
|
- Secrets must be zeroized on drop and never logged
|
||||||
|
- No stubs, `todo!()`, or `unimplemented!()` in production code
|
||||||
|
- Prefer clarity over cleverness; avoid unnecessary abstractions
|
||||||
|
|
||||||
|
## Security Vulnerabilities
|
||||||
|
|
||||||
|
Do not open public issues for security bugs. See [SECURITY.md](SECURITY.md) for responsible disclosure instructions.
|
||||||
|
|
||||||
|
## Licensing
|
||||||
|
|
||||||
|
The server crate (`quicprochat-server`) is licensed under **AGPL-3.0**. All other crates are dual-licensed under **Apache-2.0 / MIT**. By submitting a contribution, you agree to license your work under the applicable license(s).
|
||||||
868
Cargo.lock
generated
868
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
42
Cargo.toml
42
Cargo.toml
@@ -1,29 +1,38 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
members = [
|
members = [
|
||||||
"crates/quicproquo-core",
|
"crates/quicprochat-core",
|
||||||
"crates/quicproquo-proto",
|
"crates/quicprochat-proto",
|
||||||
"crates/quicproquo-plugin-api",
|
"crates/quicprochat-plugin-api",
|
||||||
"crates/quicproquo-kt",
|
"crates/quicprochat-kt",
|
||||||
"crates/quicproquo-rpc",
|
"crates/quicprochat-rpc",
|
||||||
"crates/quicproquo-sdk",
|
"crates/quicprochat-sdk",
|
||||||
"crates/quicproquo-server",
|
"crates/quicprochat-server",
|
||||||
"crates/quicproquo-client",
|
"crates/quicprochat-client",
|
||||||
# P2P crate uses iroh (~90 extra deps). Only compiled when the `mesh`
|
# P2P crate uses iroh (~90 extra deps). Only compiled when the `mesh`
|
||||||
# feature is enabled on quicproquo-client.
|
# feature is enabled on quicprochat-client.
|
||||||
"crates/quicproquo-p2p",
|
"crates/quicprochat-p2p",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[workspace.package]
|
||||||
|
edition = "2021"
|
||||||
|
rust-version = "1.75"
|
||||||
|
repository = "https://github.com/quicprochat/quicprochat"
|
||||||
|
description = "End-to-end encrypted group messaging over QUIC"
|
||||||
|
keywords = ["encryption", "messaging", "quic", "mls", "post-quantum"]
|
||||||
|
categories = ["cryptography", "network-programming"]
|
||||||
|
|
||||||
# Shared dependency versions — bump here to affect the whole workspace.
|
# Shared dependency versions — bump here to affect the whole workspace.
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
|
|
||||||
# ── Crypto ────────────────────────────────────────────────────────────────────
|
# ── Crypto ────────────────────────────────────────────────────────────────────
|
||||||
openmls = { version = "0.5", default-features = false, features = ["crypto-subtle"] }
|
openmls = { version = "0.8" }
|
||||||
openmls_rust_crypto = { version = "0.2" }
|
openmls_rust_crypto = { version = "0.5" }
|
||||||
openmls_traits = { version = "0.2" }
|
openmls_traits = { version = "0.5" }
|
||||||
# tls_codec must match the version used by openmls 0.5 (which uses 0.3) to avoid
|
openmls_memory_storage = { version = "0.5" }
|
||||||
|
# tls_codec must match the version used by openmls 0.8 (which uses 0.4) to avoid
|
||||||
# duplicate Serialize trait versions in the dependency graph.
|
# duplicate Serialize trait versions in the dependency graph.
|
||||||
tls_codec = { version = "0.3", features = ["derive"] }
|
tls_codec = { version = "0.4", features = ["derive"] }
|
||||||
# ml-kem 0.2 is the current stable release (FIPS 203, ML-KEM-768).
|
# ml-kem 0.2 is the current stable release (FIPS 203, ML-KEM-768).
|
||||||
ml-kem = { version = "0.2" }
|
ml-kem = { version = "0.2" }
|
||||||
x25519-dalek = { version = "2", features = ["static_secrets"] }
|
x25519-dalek = { version = "2", features = ["static_secrets"] }
|
||||||
@@ -79,7 +88,8 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
|||||||
anyhow = { version = "1" }
|
anyhow = { version = "1" }
|
||||||
thiserror = { version = "1" }
|
thiserror = { version = "1" }
|
||||||
|
|
||||||
# ── CLI ───────────────────────────────────────────────────────────────────────
|
# ── Config / CLI ──────────────────────────────────────────────────────────────
|
||||||
|
toml = { version = "0.8" }
|
||||||
clap = { version = "4", features = ["derive", "env"] }
|
clap = { version = "4", features = ["derive", "env"] }
|
||||||
rustyline = { version = "14" }
|
rustyline = { version = "14" }
|
||||||
|
|
||||||
|
|||||||
30
LICENSE
Normal file
30
LICENSE
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
quicproquo — Split Licensing
|
||||||
|
============================
|
||||||
|
|
||||||
|
This project uses a split license model similar to Signal:
|
||||||
|
|
||||||
|
Server (quicproquo-server)
|
||||||
|
--------------------------
|
||||||
|
Licensed under the GNU Affero General Public License v3.0 only.
|
||||||
|
See LICENSE-AGPL-3.0 for the full text.
|
||||||
|
|
||||||
|
SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
Libraries and SDKs (all other crates)
|
||||||
|
--------------------------------------
|
||||||
|
Licensed under either of
|
||||||
|
|
||||||
|
* Apache License, Version 2.0 (LICENSE-APACHE)
|
||||||
|
* MIT License (LICENSE-MIT)
|
||||||
|
|
||||||
|
at your option.
|
||||||
|
|
||||||
|
SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||||
|
|
||||||
|
Contribution
|
||||||
|
------------
|
||||||
|
Unless you explicitly state otherwise, any contribution intentionally
|
||||||
|
submitted for inclusion in this project by you, as defined in the
|
||||||
|
Apache-2.0 license, shall be dual licensed as above (for library crates)
|
||||||
|
or AGPL-3.0-only (for the server crate), without any additional terms or
|
||||||
|
conditions.
|
||||||
661
LICENSE-AGPL-3.0
Normal file
661
LICENSE-AGPL-3.0
Normal file
@@ -0,0 +1,661 @@
|
|||||||
|
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 19 November 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU Affero General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works, specifically designed to ensure
|
||||||
|
cooperation with the community in the case of network server software.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
our General Public Licenses are intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
Developers that use our General Public Licenses protect your rights
|
||||||
|
with two steps: (1) assert copyright on the software, and (2) offer
|
||||||
|
you this License which gives you legal permission to copy, distribute
|
||||||
|
and/or modify the software.
|
||||||
|
|
||||||
|
A secondary benefit of defending all users' freedom is that
|
||||||
|
improvements made in alternate versions of the program, if they
|
||||||
|
receive widespread use, become available for other developers to
|
||||||
|
incorporate. Many developers of free software are heartened and
|
||||||
|
encouraged by the resulting cooperation. However, in the case of
|
||||||
|
software used on network servers, this result may fail to come about.
|
||||||
|
The GNU General Public License permits making a modified version and
|
||||||
|
letting the public access it on a server without ever releasing its
|
||||||
|
source code to the public.
|
||||||
|
|
||||||
|
The GNU Affero General Public License is designed specifically to
|
||||||
|
ensure that, in such cases, the modified source code becomes available
|
||||||
|
to the community. It requires the operator of a network server to
|
||||||
|
provide the source code of the modified version running there to the
|
||||||
|
users of that server. Therefore, public use of a modified version, on
|
||||||
|
a publicly accessible server, gives the public access to the source
|
||||||
|
code of the modified version.
|
||||||
|
|
||||||
|
An older license, called the Affero General Public License and
|
||||||
|
published by Affero, was designed to accomplish similar goals. This is
|
||||||
|
a different license, not a version of the Affero GPL, but Affero has
|
||||||
|
released a new version of the Affero GPL which permits relicensing under
|
||||||
|
this license.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, if you modify the
|
||||||
|
Program, your modified version must prominently offer all users
|
||||||
|
interacting with it remotely through a computer network (if your version
|
||||||
|
supports such interaction) an opportunity to receive the Corresponding
|
||||||
|
Source of your version by providing access to the Corresponding Source
|
||||||
|
from a network server at no charge, through some standard or customary
|
||||||
|
means of facilitating copying of software. This Corresponding Source
|
||||||
|
shall include the Corresponding Source for any work covered by version 3
|
||||||
|
of the GNU General Public License that is incorporated pursuant to the
|
||||||
|
following paragraph.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the work with which it is combined will remain governed by version
|
||||||
|
3 of the GNU General Public License.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU Affero General Public License from time to time. Such new versions
|
||||||
|
will be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU Affero General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU Affero General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU Affero General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If your software can interact with users remotely through a computer
|
||||||
|
network, you should also make sure that it provides a way for users to
|
||||||
|
get its source. For example, if your program is a web application, its
|
||||||
|
interface could display a "Source" link that leads users to an archive
|
||||||
|
of the code. There are many ways you could offer source, and different
|
||||||
|
solutions will be better for different programs; see section 13 for the
|
||||||
|
specific requirements.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
199
LICENSE-APACHE
Normal file
199
LICENSE-APACHE
Normal file
@@ -0,0 +1,199 @@
|
|||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to the Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by the Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding any notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. Please also get an
|
||||||
|
OpenPGP-compatible signature on any file you distribute.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
21
LICENSE-MIT
Normal file
21
LICENSE-MIT
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) quicproquo contributors
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
63
README.md
63
README.md
@@ -1,14 +1,15 @@
|
|||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="assets/logo.png" alt="quicproquo" width="160">
|
<img src="assets/logo.png" alt="quicprochat" width="160">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h1 align="center">quicproquo</h1>
|
<h1 align="center">quicprochat</h1>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<strong>End-to-end encrypted group messaging over QUIC, powered by MLS and post-quantum cryptography.</strong>
|
<strong>End-to-end encrypted group messaging over QUIC, powered by MLS and post-quantum cryptography.</strong>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
|
<a href="docs/src/design-rationale/messenger-comparison.md">Why quicprochat?</a> ·
|
||||||
<a href="ROADMAP.md">Roadmap</a> ·
|
<a href="ROADMAP.md">Roadmap</a> ·
|
||||||
<a href="docs/sdk/index.md">SDK Docs</a> ·
|
<a href="docs/sdk/index.md">SDK Docs</a> ·
|
||||||
<a href="docs/operations/monitoring.md">Operations</a> ·
|
<a href="docs/operations/monitoring.md">Operations</a> ·
|
||||||
@@ -17,7 +18,7 @@
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
quicproquo is a production-grade messenger where the server **never sees plaintext**. All traffic flows over QUIC/TLS 1.3, group keys are negotiated with the [MLS protocol](https://www.rfc-editor.org/rfc/rfc9420) (RFC 9420), and a hybrid X25519 + ML-KEM-768 KEM provides post-quantum confidentiality. Written in Rust. 45,000 lines of code. 301 tests.
|
quicprochat is a production-grade messenger where the server **never sees plaintext**. All traffic flows over QUIC/TLS 1.3, group keys are negotiated with the [MLS protocol](https://www.rfc-editor.org/rfc/rfc9420) (RFC 9420), and a hybrid X25519 + ML-KEM-768 KEM provides post-quantum confidentiality. Written in Rust. 45,000 lines of code. 301 tests.
|
||||||
|
|
||||||
```
|
```
|
||||||
┌─────────────────────────────────────────────────┐
|
┌─────────────────────────────────────────────────┐
|
||||||
@@ -53,17 +54,17 @@ cargo build --workspace
|
|||||||
cargo test --workspace
|
cargo test --workspace
|
||||||
|
|
||||||
# Start the server (auto-generates self-signed TLS cert)
|
# Start the server (auto-generates self-signed TLS cert)
|
||||||
cargo run --bin qpq-server -- --allow-insecure-auth
|
cargo run --bin qpc-server -- --allow-insecure-auth
|
||||||
|
|
||||||
# Interactive REPL (registers + logs in automatically)
|
# Interactive REPL (registers + logs in automatically)
|
||||||
cargo run --bin qpq -- repl --username alice --password secret
|
cargo run --bin qpc -- repl --username alice --password secret
|
||||||
```
|
```
|
||||||
|
|
||||||
**Two-terminal demo:**
|
**Two-terminal demo:**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Terminal 1 # Terminal 2
|
# Terminal 1 # Terminal 2
|
||||||
qpq repl -u alice -p secretA qpq repl -u bob -p secretB
|
qpc repl -u alice -p secretA qpc repl -u bob -p secretB
|
||||||
|
|
||||||
# Alice: # Bob sees:
|
# Alice: # Bob sees:
|
||||||
/dm bob [alice] Hello, Bob!
|
/dm bob [alice] Hello, Bob!
|
||||||
@@ -73,19 +74,19 @@ Hello, Bob!
|
|||||||
## Architecture
|
## Architecture
|
||||||
|
|
||||||
```
|
```
|
||||||
quicproquo/
|
quicprochat/
|
||||||
├── crates/
|
├── crates/
|
||||||
│ ├── quicproquo-core # MLS, hybrid KEM, PQ Noise, OPAQUE, recovery, padding
|
│ ├── quicprochat-core # MLS, hybrid KEM, PQ Noise, OPAQUE, recovery, padding
|
||||||
│ ├── quicproquo-proto # Protobuf (prost) + Cap'n Proto generated types
|
│ ├── quicprochat-proto # Protobuf (prost) + Cap'n Proto generated types
|
||||||
│ ├── quicproquo-rpc # QUIC RPC framework (framing, dispatch, middleware)
|
│ ├── quicprochat-rpc # QUIC RPC framework (framing, dispatch, middleware)
|
||||||
│ ├── quicproquo-sdk # Client SDK (QpqClient, conversation store, outbox)
|
│ ├── quicprochat-sdk # Client SDK (QpqClient, conversation store, outbox)
|
||||||
│ ├── quicproquo-server # QUIC server, 33 RPC methods, domain services, plugins
|
│ ├── quicprochat-server # QUIC server, 33 RPC methods, domain services, plugins
|
||||||
│ ├── quicproquo-client # CLI + REPL + TUI (Ratatui)
|
│ ├── quicprochat-client # CLI + REPL + TUI (Ratatui)
|
||||||
│ ├── quicproquo-kt # Key transparency (Merkle-log, revocation)
|
│ ├── quicprochat-kt # Key transparency (Merkle-log, revocation)
|
||||||
│ ├── quicproquo-p2p # iroh P2P, mesh identity, store-and-forward
|
│ ├── quicprochat-p2p # iroh P2P, mesh identity, store-and-forward
|
||||||
│ ├── quicproquo-ffi # C FFI (libquicproquo_ffi.so)
|
│ ├── quicprochat-ffi # C FFI (libquicprochat_ffi.so)
|
||||||
│ └── quicproquo-plugin-api # Dynamic plugin hooks (C ABI)
|
│ └── quicprochat-plugin-api # Dynamic plugin hooks (C ABI)
|
||||||
├── proto/qpq/v1/ # 15 .proto schema files
|
├── proto/qpc/v1/ # 15 .proto schema files
|
||||||
├── sdks/ # Go, Python, TypeScript, Swift, Kotlin, Java, Ruby
|
├── sdks/ # Go, Python, TypeScript, Swift, Kotlin, Java, Ruby
|
||||||
├── docs/ # mdBook docs, SDK guides, operational runbooks
|
├── docs/ # mdBook docs, SDK guides, operational runbooks
|
||||||
└── packaging/ # OpenWrt, Docker, cross-compilation
|
└── packaging/ # OpenWrt, Docker, cross-compilation
|
||||||
@@ -132,7 +133,7 @@ quicproquo/
|
|||||||
|
|
||||||
| Language | Location | Transport | Notes |
|
| Language | Location | Transport | Notes |
|
||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
| **Rust** | `crates/quicproquo-sdk` | QUIC (quinn) | Reference implementation |
|
| **Rust** | `crates/quicprochat-sdk` | QUIC (quinn) | Reference implementation |
|
||||||
| **Go** | `sdks/go/` | QUIC (quic-go) | Cap'n Proto RPC, full API |
|
| **Go** | `sdks/go/` | QUIC (quic-go) | Cap'n Proto RPC, full API |
|
||||||
| **Python** | `sdks/python/` | QUIC (aioquic) + FFI | Async client, PyPI-ready |
|
| **Python** | `sdks/python/` | QUIC (aioquic) + FFI | Async client, PyPI-ready |
|
||||||
| **TypeScript** | `sdks/typescript/` | WebSocket + WASM crypto | 175 KB WASM bundle, browser demo |
|
| **TypeScript** | `sdks/typescript/` | WebSocket + WASM crypto | 175 KB WASM bundle, browser demo |
|
||||||
@@ -165,8 +166,8 @@ quicproquo/
|
|||||||
### Docker
|
### Docker
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker build -t quicproquo -f docker/Dockerfile .
|
docker build -t quicprochat -f docker/Dockerfile .
|
||||||
docker run -p 7000:7000 -v qpq-data:/data quicproquo
|
docker run -p 7000:7000 -v qpc-data:/data quicprochat
|
||||||
```
|
```
|
||||||
|
|
||||||
### Production (Docker Compose)
|
### Production (Docker Compose)
|
||||||
@@ -190,13 +191,13 @@ See [docs/openwrt.md](docs/openwrt.md) for `opkg` packaging and `procd` init scr
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Environment variables (see .env.example for full list)
|
# Environment variables (see .env.example for full list)
|
||||||
QPQ_LISTEN=0.0.0.0:7000
|
QPC_LISTEN=0.0.0.0:7000
|
||||||
QPQ_AUTH_TOKEN=your-strong-token
|
QPC_AUTH_TOKEN=your-strong-token
|
||||||
QPQ_DB_KEY=your-db-encryption-key
|
QPC_DB_KEY=your-db-encryption-key
|
||||||
QPQ_STORE_BACKEND=sql
|
QPC_STORE_BACKEND=sql
|
||||||
QPQ_METRICS_LISTEN=0.0.0.0:9090
|
QPC_METRICS_LISTEN=0.0.0.0:9090
|
||||||
QPQ_DRAIN_TIMEOUT=30
|
QPC_DRAIN_TIMEOUT=30
|
||||||
QPQ_RPC_TIMEOUT=30
|
QPC_RPC_TIMEOUT=30
|
||||||
```
|
```
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
@@ -210,11 +211,9 @@ mdbook serve docs # http://localhost:3000
|
|||||||
- [Scaling Guide](docs/operations/scaling-guide.md) — resource sizing, horizontal scaling, capacity planning
|
- [Scaling Guide](docs/operations/scaling-guide.md) — resource sizing, horizontal scaling, capacity planning
|
||||||
- [Monitoring](docs/operations/monitoring.md) — Prometheus metrics, Grafana dashboards, alert rules
|
- [Monitoring](docs/operations/monitoring.md) — Prometheus metrics, Grafana dashboards, alert rules
|
||||||
|
|
||||||
## Security
|
## Security Status
|
||||||
|
|
||||||
This project has **not undergone a formal third-party audit**. See the [threat model](docs/src/cryptography/threat-model.md) for details.
|
> **This software has not undergone an independent security audit.** While it implements cryptographic best practices (MLS RFC 9420, OPAQUE, zeroization, constant-time comparisons), no third-party firm has reviewed the implementation. Do not rely on it for high-risk communications until an audit is completed. See [SECURITY.md](SECURITY.md) for our vulnerability disclosure policy.
|
||||||
|
|
||||||
If you discover a security vulnerability, please report it privately.
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
88
ROADMAP.html
88
ROADMAP.html
@@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<!-- Book generated using mdBook -->
|
<!-- Book generated using mdBook -->
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Full Roadmap (Phases 1–8) - quicproquo</title>
|
<title>Full Roadmap (Phases 1-8) - quicproquo</title>
|
||||||
|
|
||||||
|
|
||||||
<!-- Custom HTML head -->
|
<!-- Custom HTML head -->
|
||||||
@@ -35,10 +35,10 @@
|
|||||||
const path_to_root = "";
|
const path_to_root = "";
|
||||||
const default_light_theme = "navy";
|
const default_light_theme = "navy";
|
||||||
const default_dark_theme = "navy";
|
const default_dark_theme = "navy";
|
||||||
window.path_to_searchindex_js = "searchindex-92ce38c7.js";
|
window.path_to_searchindex_js = "searchindex-1e4ee6e2.js";
|
||||||
</script>
|
</script>
|
||||||
<!-- Start loading toc.js asap -->
|
<!-- Start loading toc.js asap -->
|
||||||
<script src="toc-4c7c920d.js"></script>
|
<script src="toc-69b0eb95.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="mdbook-help-container">
|
<div id="mdbook-help-container">
|
||||||
@@ -185,7 +185,7 @@ can be parallelised. Check the box when done.</p>
|
|||||||
<p>Eliminate all crash paths, enforce secure defaults, fix deployment blockers.</p>
|
<p>Eliminate all crash paths, enforce secure defaults, fix deployment blockers.</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>1.1 Remove <code>.unwrap()</code> / <code>.expect()</code> from production paths</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>1.1 Remove <code>.unwrap()</code> / <code>.expect()</code> from production paths</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Replace <code>AUTH_CONTEXT.read().expect()</code> in client RPC with proper <code>Result</code></li>
|
<li>Replace <code>AUTH_CONTEXT.read().expect()</code> in client RPC with proper <code>Result</code></li>
|
||||||
<li>Replace <code>"0.0.0.0:0".parse().unwrap()</code> in client with fallible parse</li>
|
<li>Replace <code>"0.0.0.0:0".parse().unwrap()</code> in client with fallible parse</li>
|
||||||
@@ -194,7 +194,7 @@ can be parallelised. Check the box when done.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>1.2 Enforce secure defaults in production mode</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>1.2 Enforce secure defaults in production mode</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Reject startup if <code>QPQ_PRODUCTION=true</code> and <code>auth_token</code> is empty or <code>"devtoken"</code></li>
|
<li>Reject startup if <code>QPQ_PRODUCTION=true</code> and <code>auth_token</code> is empty or <code>"devtoken"</code></li>
|
||||||
<li>Require non-empty <code>db_key</code> when using SQL backend in production</li>
|
<li>Require non-empty <code>db_key</code> when using SQL backend in production</li>
|
||||||
@@ -203,14 +203,14 @@ can be parallelised. Check the box when done.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>1.3 Fix <code>.gitignore</code></strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>1.3 Fix <code>.gitignore</code></strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Add <code>data/</code>, <code>*.der</code>, <code>*.pem</code>, <code>*.db</code>, <code>*.bin</code> (state files), <code>*.ks</code> (keystores)</li>
|
<li>Add <code>data/</code>, <code>*.der</code>, <code>*.pem</code>, <code>*.db</code>, <code>*.bin</code> (state files), <code>*.ks</code> (keystores)</li>
|
||||||
<li>Verify no secrets are already tracked: <code>git ls-files data/ *.der *.db</code></li>
|
<li>Verify no secrets are already tracked: <code>git ls-files data/ *.der *.db</code></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>1.4 Fix Dockerfile</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>1.4 Fix Dockerfile</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Sync workspace members (handle excluded <code>p2p</code> crate)</li>
|
<li>Sync workspace members (handle excluded <code>p2p</code> crate)</li>
|
||||||
<li>Create dedicated user/group instead of <code>nobody</code></li>
|
<li>Create dedicated user/group instead of <code>nobody</code></li>
|
||||||
@@ -219,7 +219,7 @@ can be parallelised. Check the box when done.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>1.5 TLS certificate lifecycle</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>1.5 TLS certificate lifecycle</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Document CA-signed cert setup (Let’s Encrypt / custom CA)</li>
|
<li>Document CA-signed cert setup (Let’s Encrypt / custom CA)</li>
|
||||||
<li>Add <code>--tls-required</code> flag that refuses to start without valid cert</li>
|
<li>Add <code>--tls-required</code> flag that refuses to start without valid cert</li>
|
||||||
@@ -233,7 +233,7 @@ can be parallelised. Check the box when done.</p>
|
|||||||
<p>Build confidence before adding features.</p>
|
<p>Build confidence before adding features.</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>2.1 Expand E2E test coverage</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>2.1 Expand E2E test coverage</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Auth failure scenarios (wrong password, expired token, invalid token)</li>
|
<li>Auth failure scenarios (wrong password, expired token, invalid token)</li>
|
||||||
<li>Message ordering verification (send N messages, verify seq numbers)</li>
|
<li>Message ordering verification (send N messages, verify seq numbers)</li>
|
||||||
@@ -246,7 +246,7 @@ can be parallelised. Check the box when done.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>2.2 Add unit tests for untested paths</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>2.2 Add unit tests for untested paths</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Client retry logic (exponential backoff, jitter, retriable classification)</li>
|
<li>Client retry logic (exponential backoff, jitter, retriable classification)</li>
|
||||||
<li>REPL input parsing edge cases (empty input, special characters, <code>/</code> commands)</li>
|
<li>REPL input parsing edge cases (empty input, special characters, <code>/</code> commands)</li>
|
||||||
@@ -256,7 +256,7 @@ can be parallelised. Check the box when done.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>2.3 CI hardening</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>2.3 CI hardening</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Add <code>.github/CODEOWNERS</code> (crypto, auth, wire-format require 2 reviewers)</li>
|
<li>Add <code>.github/CODEOWNERS</code> (crypto, auth, wire-format require 2 reviewers)</li>
|
||||||
<li>Ensure <code>cargo deny check</code> runs on every PR (already in CI — verify)</li>
|
<li>Ensure <code>cargo deny check</code> runs on every PR (already in CI — verify)</li>
|
||||||
@@ -266,7 +266,7 @@ can be parallelised. Check the box when done.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>2.4 Clean up build warnings</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>2.4 Clean up build warnings</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Fix Cap’n Proto generated <code>unused_parens</code> warnings</li>
|
<li>Fix Cap’n Proto generated <code>unused_parens</code> warnings</li>
|
||||||
<li>Remove dead code / unused imports</li>
|
<li>Remove dead code / unused imports</li>
|
||||||
@@ -328,7 +328,7 @@ WASM/FFI for the crypto layer.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>3.2 Python SDK (<code>quicproquo-py</code>)</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>3.2 Python SDK (<code>quicproquo-py</code>)</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>QUIC transport: <code>aioquic</code> with custom Cap’n Proto stream handler</li>
|
<li>QUIC transport: <code>aioquic</code> with custom Cap’n Proto stream handler</li>
|
||||||
<li>Cap’n Proto serialization: <code>pycapnp</code> for message types</li>
|
<li>Cap’n Proto serialization: <code>pycapnp</code> for message types</li>
|
||||||
@@ -357,7 +357,7 @@ WASM/FFI for the crypto layer.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>3.5 WebTransport server endpoint</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>3.5 WebTransport server endpoint</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Add HTTP/3 + WebTransport listener to server (same QUIC stack via quinn)</li>
|
<li>Add HTTP/3 + WebTransport listener to server (same QUIC stack via quinn)</li>
|
||||||
<li>Cap’n Proto RPC framed over WebTransport bidirectional streams</li>
|
<li>Cap’n Proto RPC framed over WebTransport bidirectional streams</li>
|
||||||
@@ -378,7 +378,7 @@ WASM/FFI for the crypto layer.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>3.7 SDK documentation and schema publishing</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>3.7 SDK documentation and schema publishing</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Publish <code>.capnp</code> schemas as the canonical API contract</li>
|
<li>Publish <code>.capnp</code> schemas as the canonical API contract</li>
|
||||||
<li>Document the QUIC + Cap’n Proto connection pattern for each language</li>
|
<li>Document the QUIC + Cap’n Proto connection pattern for each language</li>
|
||||||
@@ -401,7 +401,7 @@ WASM/FFI for the crypto layer.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>4.2 Key Transparency / revocation</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>4.2 Key Transparency / revocation</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Replace <code>BasicCredential</code> with X.509-based MLS credentials</li>
|
<li>Replace <code>BasicCredential</code> with X.509-based MLS credentials</li>
|
||||||
<li>Or: verifiable key directory (Merkle tree, auditable log)</li>
|
<li>Or: verifiable key directory (Merkle tree, auditable log)</li>
|
||||||
@@ -418,7 +418,7 @@ WASM/FFI for the crypto layer.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>4.4 M7 — Post-quantum MLS integration</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>4.4 M7 — Post-quantum MLS integration</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Integrate hybrid KEM (X25519 + ML-KEM-768) into the OpenMLS crypto provider</li>
|
<li>Integrate hybrid KEM (X25519 + ML-KEM-768) into the OpenMLS crypto provider</li>
|
||||||
<li>Group key material gets post-quantum confidentiality</li>
|
<li>Group key material gets post-quantum confidentiality</li>
|
||||||
@@ -439,7 +439,7 @@ WASM/FFI for the crypto layer.</p>
|
|||||||
<p>Make it a product people want to use.</p>
|
<p>Make it a product people want to use.</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>5.1 Multi-device support</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>5.1 Multi-device support</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Account → multiple devices, each with own Ed25519 key + MLS KeyPackages</li>
|
<li>Account → multiple devices, each with own Ed25519 key + MLS KeyPackages</li>
|
||||||
<li>Device graph management (add device, remove device, list devices)</li>
|
<li>Device graph management (add device, remove device, list devices)</li>
|
||||||
@@ -448,7 +448,7 @@ WASM/FFI for the crypto layer.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>5.2 Account recovery</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>5.2 Account recovery</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Recovery codes or backup key (encrypted, stored by user)</li>
|
<li>Recovery codes or backup key (encrypted, stored by user)</li>
|
||||||
<li>Option: server-assisted recovery with security questions (lower security)</li>
|
<li>Option: server-assisted recovery with security questions (lower security)</li>
|
||||||
@@ -456,7 +456,7 @@ WASM/FFI for the crypto layer.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>5.3 Full MLS lifecycle</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>5.3 Full MLS lifecycle</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Member removal (Remove proposal → Commit → fan-out)</li>
|
<li>Member removal (Remove proposal → Commit → fan-out)</li>
|
||||||
<li>Credential update (Update proposal for key rotation)</li>
|
<li>Credential update (Update proposal for key rotation)</li>
|
||||||
@@ -483,7 +483,7 @@ WASM/FFI for the crypto layer.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>5.6 Abuse prevention and moderation</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>5.6 Abuse prevention and moderation</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Block user (client-side, suppress display)</li>
|
<li>Block user (client-side, suppress display)</li>
|
||||||
<li>Report message (encrypted report to admin key)</li>
|
<li>Report message (encrypted report to admin key)</li>
|
||||||
@@ -491,7 +491,7 @@ WASM/FFI for the crypto layer.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>5.7 Offline message queue (client-side)</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>5.7 Offline message queue (client-side)</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Queue messages when disconnected, send on reconnect</li>
|
<li>Queue messages when disconnected, send on reconnect</li>
|
||||||
<li>Idempotent message IDs to prevent duplicates</li>
|
<li>Idempotent message IDs to prevent duplicates</li>
|
||||||
@@ -504,7 +504,7 @@ WASM/FFI for the crypto layer.</p>
|
|||||||
<p>Prepare for real traffic.</p>
|
<p>Prepare for real traffic.</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>6.1 Distributed rate limiting</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>6.1 Distributed rate limiting</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Current: in-memory per-process, lost on restart</li>
|
<li>Current: in-memory per-process, lost on restart</li>
|
||||||
<li>Move to Redis or shared state for multi-node deployments</li>
|
<li>Move to Redis or shared state for multi-node deployments</li>
|
||||||
@@ -512,7 +512,7 @@ WASM/FFI for the crypto layer.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>6.2 Multi-node / horizontal scaling</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>6.2 Multi-node / horizontal scaling</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Stateless server design (already mostly there — state is in storage backend)</li>
|
<li>Stateless server design (already mostly there — state is in storage backend)</li>
|
||||||
<li>Shared PostgreSQL or CockroachDB backend (replace SQLite)</li>
|
<li>Shared PostgreSQL or CockroachDB backend (replace SQLite)</li>
|
||||||
@@ -521,7 +521,7 @@ WASM/FFI for the crypto layer.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>6.3 Operational runbook</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>6.3 Operational runbook</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Backup / restore procedures (SQLCipher, file backend)</li>
|
<li>Backup / restore procedures (SQLCipher, file backend)</li>
|
||||||
<li>Key rotation (auth token, TLS cert, DB encryption key)</li>
|
<li>Key rotation (auth token, TLS cert, DB encryption key)</li>
|
||||||
@@ -531,7 +531,7 @@ WASM/FFI for the crypto layer.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>6.4 Connection draining and graceful shutdown</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>6.4 Connection draining and graceful shutdown</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Stop accepting new connections on SIGTERM</li>
|
<li>Stop accepting new connections on SIGTERM</li>
|
||||||
<li>Wait for in-flight RPCs (configurable timeout, default 30s)</li>
|
<li>Wait for in-flight RPCs (configurable timeout, default 30s)</li>
|
||||||
@@ -540,7 +540,7 @@ WASM/FFI for the crypto layer.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>6.5 Request-level timeouts</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>6.5 Request-level timeouts</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Per-RPC timeout (prevent slow clients from holding resources)</li>
|
<li>Per-RPC timeout (prevent slow clients from holding resources)</li>
|
||||||
<li>Database query timeout</li>
|
<li>Database query timeout</li>
|
||||||
@@ -548,7 +548,7 @@ WASM/FFI for the crypto layer.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>6.6 Observability enhancements</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>6.6 Observability enhancements</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Request correlation IDs (trace across RPC → storage)</li>
|
<li>Request correlation IDs (trace across RPC → storage)</li>
|
||||||
<li>Storage operation latency metrics</li>
|
<li>Storage operation latency metrics</li>
|
||||||
@@ -563,7 +563,7 @@ WASM/FFI for the crypto layer.</p>
|
|||||||
<p>Long-term vision for wide adoption.</p>
|
<p>Long-term vision for wide adoption.</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>7.1 Mobile clients (iOS + Android)</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>7.1 Mobile clients (iOS + Android)</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Use C FFI (Phase 3.3) for crypto + transport (single library)</li>
|
<li>Use C FFI (Phase 3.3) for crypto + transport (single library)</li>
|
||||||
<li>Push notifications via APNs / FCM (server sends notification on enqueue)</li>
|
<li>Push notifications via APNs / FCM (server sends notification on enqueue)</li>
|
||||||
@@ -572,7 +572,7 @@ WASM/FFI for the crypto layer.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>7.2 Web client (browser)</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>7.2 Web client (browser)</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Use WASM (Phase 3.4) for crypto</li>
|
<li>Use WASM (Phase 3.4) for crypto</li>
|
||||||
<li>Use WebTransport (Phase 3.5) for native QUIC transport</li>
|
<li>Use WebTransport (Phase 3.5) for native QUIC transport</li>
|
||||||
@@ -583,7 +583,7 @@ WASM/FFI for the crypto layer.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>7.3 Federation</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>7.3 Federation</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Server-to-server protocol via Cap’n Proto RPC over QUIC (see <code>federation.capnp</code>)</li>
|
<li>Server-to-server protocol via Cap’n Proto RPC over QUIC (see <code>federation.capnp</code>)</li>
|
||||||
<li><code>relayEnqueue</code>, <code>proxyFetchKeyPackage</code>, <code>federationHealth</code> methods</li>
|
<li><code>relayEnqueue</code>, <code>proxyFetchKeyPackage</code>, <code>federationHealth</code> methods</li>
|
||||||
@@ -601,7 +601,7 @@ WASM/FFI for the crypto layer.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>7.5 Additional language SDKs</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>7.5 Additional language SDKs</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Java/Kotlin: JNI bindings to C FFI (Phase 3.3) + native QUIC (netty-quic)</li>
|
<li>Java/Kotlin: JNI bindings to C FFI (Phase 3.3) + native QUIC (netty-quic)</li>
|
||||||
<li>Swift: Swift wrapper over C FFI + Network.framework QUIC</li>
|
<li>Swift: Swift wrapper over C FFI + Network.framework QUIC</li>
|
||||||
@@ -610,7 +610,7 @@ WASM/FFI for the crypto layer.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>7.6 P2P / NAT traversal</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>7.6 P2P / NAT traversal</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Direct peer-to-peer via iroh (foundation exists in <code>quicproquo-p2p</code>)</li>
|
<li>Direct peer-to-peer via iroh (foundation exists in <code>quicproquo-p2p</code>)</li>
|
||||||
<li>Server as fallback relay only</li>
|
<li>Server as fallback relay only</li>
|
||||||
@@ -619,7 +619,7 @@ WASM/FFI for the crypto layer.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>7.7 Traffic analysis resistance</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>7.7 Traffic analysis resistance</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Padding messages to uniform size</li>
|
<li>Padding messages to uniform size</li>
|
||||||
<li>Decoy traffic to mask timing patterns</li>
|
<li>Decoy traffic to mask timing patterns</li>
|
||||||
@@ -706,7 +706,7 @@ functions without any central infrastructure or internet uplink.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>F7 — OpenWrt cross-compilation guide</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>F7 — OpenWrt cross-compilation guide</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Musl static builds: <code>x86_64-unknown-linux-musl</code>, <code>armv7-unknown-linux-musleabihf</code>, <code>mips-unknown-linux-musl</code></li>
|
<li>Musl static builds: <code>x86_64-unknown-linux-musl</code>, <code>armv7-unknown-linux-musleabihf</code>, <code>mips-unknown-linux-musl</code></li>
|
||||||
<li>Strip binary: <code>--release</code> + <code>strip</code> → target size < 5 MB for flash storage</li>
|
<li>Strip binary: <code>--release</code> + <code>strip</code> → target size < 5 MB for flash storage</li>
|
||||||
@@ -716,7 +716,7 @@ functions without any central infrastructure or internet uplink.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>F8 — Traffic analysis resistance for mesh</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>F8 — Traffic analysis resistance for mesh</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Uniform message padding to nearest 256-byte boundary (hides message size)</li>
|
<li>Uniform message padding to nearest 256-byte boundary (hides message size)</li>
|
||||||
<li>Configurable decoy traffic rate (fake messages to mask send timing)</li>
|
<li>Configurable decoy traffic rate (fake messages to mask send timing)</li>
|
||||||
@@ -731,7 +731,7 @@ functions without any central infrastructure or internet uplink.</p>
|
|||||||
and lower the barrier to entry for non-crypto developers.</p>
|
and lower the barrier to entry for non-crypto developers.</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>9.1 Criterion Benchmark Suite (<code>qpq-bench</code>)</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>9.1 Criterion Benchmark Suite (<code>qpq-bench</code>)</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Criterion benchmarks for all crypto primitives: hybrid KEM encap/decap,
|
<li>Criterion benchmarks for all crypto primitives: hybrid KEM encap/decap,
|
||||||
MLS group-add at 10/100/1000 members, epoch rotation, Noise_XX handshake</li>
|
MLS group-add at 10/100/1000 members, epoch rotation, Noise_XX handshake</li>
|
||||||
@@ -748,7 +748,7 @@ MLS group-add at 10/100/1000 members, epoch rotation, Noise_XX handshake</li>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>9.3 Full-Screen TUI (Ratatui + Crossterm)</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>9.3 Full-Screen TUI (Ratatui + Crossterm)</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li><code>qpq tui</code> launches a full-screen terminal UI: message pane, input bar,
|
<li><code>qpq tui</code> launches a full-screen terminal UI: message pane, input bar,
|
||||||
channel sidebar with unread counts, MLS epoch indicator</li>
|
channel sidebar with unread counts, MLS epoch indicator</li>
|
||||||
@@ -757,7 +757,7 @@ channel sidebar with unread counts, MLS epoch indicator</li>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>9.4 Delivery Proof Canary Tokens</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>9.4 Delivery Proof Canary Tokens</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Server signs <code>Ed25519(SHA-256(message_id || recipient || timestamp))</code> on enqueue</li>
|
<li>Server signs <code>Ed25519(SHA-256(message_id || recipient || timestamp))</code> on enqueue</li>
|
||||||
<li>Sender stores proof locally — cryptographic evidence the server queued the message</li>
|
<li>Sender stores proof locally — cryptographic evidence the server queued the message</li>
|
||||||
@@ -765,7 +765,7 @@ channel sidebar with unread counts, MLS epoch indicator</li>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>9.5 Verifiable Transcript Archive</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>9.5 Verifiable Transcript Archive</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li><code>GroupMember::export_transcript(path, password)</code> writes encrypted, tamper-evident
|
<li><code>GroupMember::export_transcript(path, password)</code> writes encrypted, tamper-evident
|
||||||
message archive (CBOR records, Argon2id + ChaCha20-Poly1305, Merkle chain)</li>
|
message archive (CBOR records, Argon2id + ChaCha20-Poly1305, Merkle chain)</li>
|
||||||
@@ -774,7 +774,7 @@ message archive (CBOR records, Argon2id + ChaCha20-Poly1305, Merkle chain)</li>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>9.6 Key Transparency (Merkle-Log Identity Binding)</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>9.6 Key Transparency (Merkle-Log Identity Binding)</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Append-only Merkle log of (username, identity_key) bindings in the AS</li>
|
<li>Append-only Merkle log of (username, identity_key) bindings in the AS</li>
|
||||||
<li>Clients receive inclusion proofs alongside key fetches</li>
|
<li>Clients receive inclusion proofs alongside key fetches</li>
|
||||||
@@ -792,7 +792,7 @@ message archive (CBOR records, Argon2id + ChaCha20-Poly1305, Merkle chain)</li>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><input disabled="" type="checkbox"> <strong>9.8 PQ Noise Transport Layer</strong></p>
|
<p><input disabled="" type="checkbox" checked=""> <strong>9.8 PQ Noise Transport Layer</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Hybrid <code>Noise_XX + ML-KEM-768</code> handshake for post-quantum transport security</li>
|
<li>Hybrid <code>Noise_XX + ML-KEM-768</code> handshake for post-quantum transport security</li>
|
||||||
<li>Closes the harvest-now-decrypt-later gap on handshake metadata (ADR-006)</li>
|
<li>Closes the harvest-now-decrypt-later gap on handshake metadata (ADR-006)</li>
|
||||||
@@ -840,7 +840,7 @@ message archive (CBOR records, Argon2id + ChaCha20-Poly1305, Merkle chain)</li>
|
|||||||
<span class=fa-svg><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><!--! Font Awesome Free 6.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --><path d="M41.4 233.4c-12.5 12.5-12.5 32.8 0 45.3l160 160c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L109.3 256 246.6 118.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-160 160z"/></svg></span>
|
<span class=fa-svg><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><!--! Font Awesome Free 6.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --><path d="M41.4 233.4c-12.5 12.5-12.5 32.8 0 45.3l160 160c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L109.3 256 246.6 118.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-160 160z"/></svg></span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a rel="next prefetch" href="contributing/coding-standards.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
<a rel="next prefetch" href="operations/monitoring.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
||||||
<span class=fa-svg><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><!--! Font Awesome Free 6.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --><path d="M278.6 233.4c12.5 12.5 12.5 32.8 0 45.3l-160 160c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L210.7 256 73.4 118.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0l160 160z"/></svg></span>
|
<span class=fa-svg><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><!--! Font Awesome Free 6.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --><path d="M278.6 233.4c12.5 12.5 12.5 32.8 0 45.3l-160 160c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L210.7 256 73.4 118.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0l160 160z"/></svg></span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
@@ -854,7 +854,7 @@ message archive (CBOR records, Argon2id + ChaCha20-Poly1305, Merkle chain)</li>
|
|||||||
<span class=fa-svg><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><!--! Font Awesome Free 6.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --><path d="M41.4 233.4c-12.5 12.5-12.5 32.8 0 45.3l160 160c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L109.3 256 246.6 118.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-160 160z"/></svg></span>
|
<span class=fa-svg><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><!--! Font Awesome Free 6.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --><path d="M41.4 233.4c-12.5 12.5-12.5 32.8 0 45.3l160 160c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L109.3 256 246.6 118.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-160 160z"/></svg></span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a rel="next prefetch" href="contributing/coding-standards.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
<a rel="next prefetch" href="operations/monitoring.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
||||||
<span class=fa-svg><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><!--! Font Awesome Free 6.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --><path d="M278.6 233.4c12.5 12.5 12.5 32.8 0 45.3l-160 160c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L210.7 256 73.4 118.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0l160 160z"/></svg></span>
|
<span class=fa-svg><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><!--! Font Awesome Free 6.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --><path d="M278.6 233.4c12.5 12.5 12.5 32.8 0 45.3l-160 160c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L210.7 256 73.4 118.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0l160 160z"/></svg></span>
|
||||||
</a>
|
</a>
|
||||||
</nav>
|
</nav>
|
||||||
|
|||||||
64
ROADMAP.md
64
ROADMAP.md
@@ -1,4 +1,4 @@
|
|||||||
# Roadmap — quicproquo
|
# Roadmap — quicprochat
|
||||||
|
|
||||||
> From proof-of-concept to production-grade E2E encrypted messaging.
|
> From proof-of-concept to production-grade E2E encrypted messaging.
|
||||||
>
|
>
|
||||||
@@ -18,7 +18,7 @@ Eliminate all crash paths, enforce secure defaults, fix deployment blockers.
|
|||||||
- Audit: `grep -rn 'unwrap()\|expect(' crates/` outside `#[cfg(test)]`
|
- Audit: `grep -rn 'unwrap()\|expect(' crates/` outside `#[cfg(test)]`
|
||||||
|
|
||||||
- [x] **1.2 Enforce secure defaults in production mode**
|
- [x] **1.2 Enforce secure defaults in production mode**
|
||||||
- Reject startup if `QPQ_PRODUCTION=true` and `auth_token` is empty or `"devtoken"`
|
- Reject startup if `QPC_PRODUCTION=true` and `auth_token` is empty or `"devtoken"`
|
||||||
- Require non-empty `db_key` when using SQL backend in production
|
- Require non-empty `db_key` when using SQL backend in production
|
||||||
- Refuse to auto-generate TLS certs in production mode (require existing cert+key)
|
- Refuse to auto-generate TLS certs in production mode (require existing cert+key)
|
||||||
- Already partially implemented — verify and harden the validation in `config.rs`
|
- Already partially implemented — verify and harden the validation in `config.rs`
|
||||||
@@ -30,8 +30,8 @@ Eliminate all crash paths, enforce secure defaults, fix deployment blockers.
|
|||||||
- [x] **1.4 Fix Dockerfile**
|
- [x] **1.4 Fix Dockerfile**
|
||||||
- Sync workspace members (handle excluded `p2p` crate)
|
- Sync workspace members (handle excluded `p2p` crate)
|
||||||
- Create dedicated user/group instead of `nobody`
|
- Create dedicated user/group instead of `nobody`
|
||||||
- Set writable `QPQ_DATA_DIR` with correct permissions
|
- Set writable `QPC_DATA_DIR` with correct permissions
|
||||||
- Test: `docker build . && docker run --rm -it qpq-server --help`
|
- Test: `docker build . && docker run --rm -it qpc-server --help`
|
||||||
|
|
||||||
- [x] **1.5 TLS certificate lifecycle**
|
- [x] **1.5 TLS certificate lifecycle**
|
||||||
- Document CA-signed cert setup (Let's Encrypt / custom CA)
|
- Document CA-signed cert setup (Let's Encrypt / custom CA)
|
||||||
@@ -121,27 +121,27 @@ WASM/FFI for the crypto layer.
|
|||||||
|
|
||||||
### Implementation
|
### Implementation
|
||||||
|
|
||||||
- [x] **3.1 Go SDK (`quicproquo-go`)**
|
- [x] **3.1 Go SDK (`quicprochat-go`)**
|
||||||
- Generated Go types from `node.capnp` (6487-line codegen, all 24 RPC methods)
|
- Generated Go types from `node.capnp` (6487-line codegen, all 24 RPC methods)
|
||||||
- QUIC transport via `quic-go` with TLS 1.3 + ALPN `"capnp"`
|
- QUIC transport via `quic-go` with TLS 1.3 + ALPN `"capnp"`
|
||||||
- High-level `qpq` package: Connect, Health, ResolveUser, CreateChannel, Send/SendWithTTL, Receive/ReceiveWait, DeleteAccount, OPAQUE auth
|
- High-level `qpc` package: Connect, Health, ResolveUser, CreateChannel, Send/SendWithTTL, Receive/ReceiveWait, DeleteAccount, OPAQUE auth
|
||||||
- Example CLI in `sdks/go/cmd/example/`
|
- Example CLI in `sdks/go/cmd/example/`
|
||||||
|
|
||||||
- [x] **3.2 Python SDK (`quicproquo-py`)**
|
- [x] **3.2 Python SDK (`quicprochat-py`)**
|
||||||
- QUIC transport: `aioquic` with custom Cap'n Proto stream handler
|
- QUIC transport: `aioquic` with custom Cap'n Proto stream handler
|
||||||
- Cap'n Proto serialization: `pycapnp` for message types
|
- Cap'n Proto serialization: `pycapnp` for message types
|
||||||
- Manual RPC framing: length-prefixed request/response over QUIC stream
|
- Manual RPC framing: length-prefixed request/response over QUIC stream
|
||||||
- Async/await API matching the Rust client patterns
|
- Async/await API matching the Rust client patterns
|
||||||
- Crypto: PyO3 bindings to `quicproquo-core` for MLS operations
|
- Crypto: PyO3 bindings to `quicprochat-core` for MLS operations
|
||||||
- Publish: PyPI `quicproquo`
|
- Publish: PyPI `quicprochat`
|
||||||
- Example: async bot client
|
- Example: async bot client
|
||||||
|
|
||||||
- [x] **3.3 C FFI layer (`quicproquo-ffi`)**
|
- [x] **3.3 C FFI layer (`quicprochat-ffi`)**
|
||||||
- `crates/quicproquo-ffi` with 7 extern "C" functions: connect, login, send, receive, disconnect, last_error, free_string
|
- `crates/quicprochat-ffi` with 7 extern "C" functions: connect, login, send, receive, disconnect, last_error, free_string
|
||||||
- Builds as `libquicproquo_ffi.so` / `.dylib` / `.dll`
|
- Builds as `libquicprochat_ffi.so` / `.dylib` / `.dll`
|
||||||
- Python ctypes wrapper in `examples/python/qpq_client.py`
|
- Python ctypes wrapper in `examples/python/qpc_client.py`
|
||||||
|
|
||||||
- [x] **3.4 WASM compilation of `quicproquo-core`**
|
- [x] **3.4 WASM compilation of `quicprochat-core`**
|
||||||
- `wasm-pack build` target producing 175 KB WASM bundle (LTO + opt-level=s)
|
- `wasm-pack build` target producing 175 KB WASM bundle (LTO + opt-level=s)
|
||||||
- 13 `wasm_bindgen` functions: Ed25519 identity, hybrid KEM, safety numbers, sealed sender, padding
|
- 13 `wasm_bindgen` functions: Ed25519 identity, hybrid KEM, safety numbers, sealed sender, padding
|
||||||
- Browser-ready with `crypto.getRandomValues()` RNG
|
- Browser-ready with `crypto.getRandomValues()` RNG
|
||||||
@@ -156,7 +156,7 @@ WASM/FFI for the crypto layer.
|
|||||||
- Configurable port: `--webtransport-listen 0.0.0.0:7443`
|
- Configurable port: `--webtransport-listen 0.0.0.0:7443`
|
||||||
- Feature-flagged: `--features webtransport`
|
- Feature-flagged: `--features webtransport`
|
||||||
|
|
||||||
- [x] **3.6 TypeScript/JavaScript SDK (`@quicproquo/client`)**
|
- [x] **3.6 TypeScript/JavaScript SDK (`@quicprochat/client`)**
|
||||||
- `QpqClient` class: connect, offline, health, resolveUser, createChannel, send/sendWithTTL, receive, deleteAccount
|
- `QpqClient` class: connect, offline, health, resolveUser, createChannel, send/sendWithTTL, receive, deleteAccount
|
||||||
- WASM crypto wrapper: generateIdentity, sign/verify, hybridEncrypt/Decrypt, computeSafetyNumber, sealedSend, pad
|
- WASM crypto wrapper: generateIdentity, sign/verify, hybridEncrypt/Decrypt, computeSafetyNumber, sealedSend, pad
|
||||||
- WebSocket transport with request/response correlation and reconnection
|
- WebSocket transport with request/response correlation and reconnection
|
||||||
@@ -317,17 +317,17 @@ Long-term vision for wide adoption.
|
|||||||
|
|
||||||
- [x] **7.4 Sealed Sender**
|
- [x] **7.4 Sealed Sender**
|
||||||
- Sender identity inside MLS ciphertext only (server can't see who sent)
|
- Sender identity inside MLS ciphertext only (server can't see who sent)
|
||||||
- `sealed_sender` module in quicproquo-core with seal/unseal API
|
- `sealed_sender` module in quicprochat-core with seal/unseal API
|
||||||
- WASM-accessible via `wasm_bindgen` for browser use
|
- WASM-accessible via `wasm_bindgen` for browser use
|
||||||
|
|
||||||
- [x] **7.5 Additional language SDKs**
|
- [x] **7.5 Additional language SDKs**
|
||||||
- Java/Kotlin: JNI bindings to C FFI (Phase 3.3) + native QUIC (netty-quic)
|
- Java/Kotlin: JNI bindings to C FFI (Phase 3.3) + native QUIC (netty-quic)
|
||||||
- Swift: Swift wrapper over C FFI + Network.framework QUIC
|
- Swift: Swift wrapper over C FFI + Network.framework QUIC
|
||||||
- Ruby: FFI bindings via `quicproquo-ffi`
|
- Ruby: FFI bindings via `quicprochat-ffi`
|
||||||
- Evaluate demand-driven — only build SDKs people request
|
- Evaluate demand-driven — only build SDKs people request
|
||||||
|
|
||||||
- [x] **7.6 P2P / NAT traversal**
|
- [x] **7.6 P2P / NAT traversal**
|
||||||
- Direct peer-to-peer via iroh (foundation exists in `quicproquo-p2p`)
|
- Direct peer-to-peer via iroh (foundation exists in `quicprochat-p2p`)
|
||||||
- Server as fallback relay only
|
- Server as fallback relay only
|
||||||
- Reduces latency and single-point-of-failure
|
- Reduces latency and single-point-of-failure
|
||||||
- Ref: `FUTURE-IMPROVEMENTS.md § 6.1`
|
- Ref: `FUTURE-IMPROVEMENTS.md § 6.1`
|
||||||
@@ -342,35 +342,35 @@ Long-term vision for wide adoption.
|
|||||||
|
|
||||||
## Phase 8 — Freifunk / Community Mesh Networking
|
## Phase 8 — Freifunk / Community Mesh Networking
|
||||||
|
|
||||||
Make qpq a first-class citizen on decentralised, community-operated wireless
|
Make qpc a first-class citizen on decentralised, community-operated wireless
|
||||||
networks (Freifunk, BATMAN-adv/Babel routing, OpenWrt). Multiple qpq nodes form
|
networks (Freifunk, BATMAN-adv/Babel routing, OpenWrt). Multiple qpc nodes form
|
||||||
a federated mesh; clients auto-discover nearby nodes via mDNS; the network
|
a federated mesh; clients auto-discover nearby nodes via mDNS; the network
|
||||||
functions without any central infrastructure or internet uplink.
|
functions without any central infrastructure or internet uplink.
|
||||||
|
|
||||||
### Architecture
|
### Architecture
|
||||||
|
|
||||||
```
|
```
|
||||||
Client A ─── mDNS discovery ──► nearby qpq node (LAN / mesh)
|
Client A ─── mDNS discovery ──► nearby qpc node (LAN / mesh)
|
||||||
│
|
│
|
||||||
Cap'n Proto federation
|
Cap'n Proto federation
|
||||||
│
|
│
|
||||||
remote qpq node (across mesh)
|
remote qpc node (across mesh)
|
||||||
```
|
```
|
||||||
|
|
||||||
- [x] **F0 — Re-include `quicproquo-p2p` in workspace; fix ALPN strings**
|
- [x] **F0 — Re-include `quicprochat-p2p` in workspace; fix ALPN strings**
|
||||||
- Moved `crates/quicproquo-p2p` from `exclude` back into `[workspace] members`
|
- Moved `crates/quicprochat-p2p` from `exclude` back into `[workspace] members`
|
||||||
- Fixed ALPN `b"quicnprotochat/p2p/1"` → `b"quicproquo/p2p/1"` (breaking wire change)
|
- Fixed ALPN `b"quicnprotochat/p2p/1"` → `b"quicprochat/p2p/1"` (breaking wire change)
|
||||||
- Fixed federation ALPN `b"qnpc-fed"` → `b"quicproquo/federation/1"`
|
- Fixed federation ALPN `b"qnpc-fed"` → `b"quicprochat/federation/1"`
|
||||||
- Feature-gated behind `--features mesh` on client (keeps iroh out of default builds)
|
- Feature-gated behind `--features mesh` on client (keeps iroh out of default builds)
|
||||||
|
|
||||||
- [x] **F1 — Federation routing in message delivery**
|
- [x] **F1 — Federation routing in message delivery**
|
||||||
- `handle_enqueue` and `handle_batch_enqueue` call `federation::routing::resolve_destination()`
|
- `handle_enqueue` and `handle_batch_enqueue` call `federation::routing::resolve_destination()`
|
||||||
- Recipients with a remote home server are relayed via `FederationClient::relay_enqueue()`
|
- Recipients with a remote home server are relayed via `FederationClient::relay_enqueue()`
|
||||||
- mTLS mutual authentication between nodes (both present client certs, validated against shared CA)
|
- mTLS mutual authentication between nodes (both present client certs, validated against shared CA)
|
||||||
- Config: `QPQ_FEDERATION_LISTEN`, `QPQ_LOCAL_DOMAIN`, `QPQ_FEDERATION_CERT/KEY/CA`
|
- Config: `QPC_FEDERATION_LISTEN`, `QPC_LOCAL_DOMAIN`, `QPC_FEDERATION_CERT/KEY/CA`
|
||||||
|
|
||||||
- [x] **F2 — mDNS local peer discovery**
|
- [x] **F2 — mDNS local peer discovery**
|
||||||
- Server announces `_quicproquo._udp.local.` on startup via `mdns-sd`
|
- Server announces `_quicprochat._udp.local.` on startup via `mdns-sd`
|
||||||
- Client: `MeshDiscovery::start()` browses for nearby nodes (feature-gated)
|
- Client: `MeshDiscovery::start()` browses for nearby nodes (feature-gated)
|
||||||
- REPL commands: `/mesh peers` (scan + list), `/mesh server <host:port>` (note address)
|
- REPL commands: `/mesh peers` (scan + list), `/mesh server <host:port>` (note address)
|
||||||
- Nodes announce: `ver=1`, `server=<host:port>`, `domain=<local_domain>` TXT records
|
- Nodes announce: `ver=1`, `server=<host:port>`, `domain=<local_domain>` TXT records
|
||||||
@@ -378,7 +378,7 @@ functions without any central infrastructure or internet uplink.
|
|||||||
- [x] **F3 — Self-sovereign mesh identity**
|
- [x] **F3 — Self-sovereign mesh identity**
|
||||||
- Ed25519 keypair-based identity independent of AS registration
|
- Ed25519 keypair-based identity independent of AS registration
|
||||||
- JSON-persisted seed + known peers directory
|
- JSON-persisted seed + known peers directory
|
||||||
- Sign/verify operations for mesh authenticity (`crates/quicproquo-p2p/src/identity.rs`)
|
- Sign/verify operations for mesh authenticity (`crates/quicprochat-p2p/src/identity.rs`)
|
||||||
|
|
||||||
- [x] **F4 — Store-and-forward with TTL**
|
- [x] **F4 — Store-and-forward with TTL**
|
||||||
- `MeshEnvelope` with TTL-based expiry, hop_count tracking, max_hops routing limit
|
- `MeshEnvelope` with TTL-based expiry, hop_count tracking, max_hops routing limit
|
||||||
@@ -419,7 +419,7 @@ functions without any central infrastructure or internet uplink.
|
|||||||
Features designed to attract contributors, create demo/showcase potential,
|
Features designed to attract contributors, create demo/showcase potential,
|
||||||
and lower the barrier to entry for non-crypto developers.
|
and lower the barrier to entry for non-crypto developers.
|
||||||
|
|
||||||
- [x] **9.1 Criterion Benchmark Suite (`qpq-bench`)**
|
- [x] **9.1 Criterion Benchmark Suite (`qpc-bench`)**
|
||||||
- Criterion benchmarks for all crypto primitives: hybrid KEM encap/decap,
|
- Criterion benchmarks for all crypto primitives: hybrid KEM encap/decap,
|
||||||
MLS group-add at 10/100/1000 members, epoch rotation, Noise_XX handshake
|
MLS group-add at 10/100/1000 members, epoch rotation, Noise_XX handshake
|
||||||
- CI publishes HTML benchmark reports as GitHub Actions artifacts
|
- CI publishes HTML benchmark reports as GitHub Actions artifacts
|
||||||
@@ -431,7 +431,7 @@ and lower the barrier to entry for non-crypto developers.
|
|||||||
- Available in WASM via `compute_safety_number` binding
|
- Available in WASM via `compute_safety_number` binding
|
||||||
|
|
||||||
- [x] **9.3 Full-Screen TUI (Ratatui + Crossterm)**
|
- [x] **9.3 Full-Screen TUI (Ratatui + Crossterm)**
|
||||||
- `qpq tui` launches a full-screen terminal UI: message pane, input bar,
|
- `qpc tui` launches a full-screen terminal UI: message pane, input bar,
|
||||||
channel sidebar with unread counts, MLS epoch indicator
|
channel sidebar with unread counts, MLS epoch indicator
|
||||||
- Feature-gated `--features tui` to keep ratatui/crossterm out of default builds
|
- Feature-gated `--features tui` to keep ratatui/crossterm out of default builds
|
||||||
- Existing REPL and CLI subcommands are unaffected
|
- Existing REPL and CLI subcommands are unaffected
|
||||||
@@ -444,7 +444,7 @@ and lower the barrier to entry for non-crypto developers.
|
|||||||
- [x] **9.5 Verifiable Transcript Archive**
|
- [x] **9.5 Verifiable Transcript Archive**
|
||||||
- `GroupMember::export_transcript(path, password)` writes encrypted, tamper-evident
|
- `GroupMember::export_transcript(path, password)` writes encrypted, tamper-evident
|
||||||
message archive (CBOR records, Argon2id + ChaCha20-Poly1305, Merkle chain)
|
message archive (CBOR records, Argon2id + ChaCha20-Poly1305, Merkle chain)
|
||||||
- `qpq export verify` CLI command independently verifies chain integrity
|
- `qpc export verify` CLI command independently verifies chain integrity
|
||||||
- Useful for legal discovery, audit, or personal backup
|
- Useful for legal discovery, audit, or personal backup
|
||||||
|
|
||||||
- [x] **9.6 Key Transparency (Merkle-Log Identity Binding)**
|
- [x] **9.6 Key Transparency (Merkle-Log Identity Binding)**
|
||||||
|
|||||||
29
SECURITY.md
Normal file
29
SECURITY.md
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# Security Policy
|
||||||
|
|
||||||
|
## Supported Versions
|
||||||
|
|
||||||
|
Only the current `main` branch is supported with security updates.
|
||||||
|
|
||||||
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
|
**Do not use public GitHub issues to report security vulnerabilities.**
|
||||||
|
|
||||||
|
Instead, email **security@quicprochat.org** with:
|
||||||
|
|
||||||
|
- A description of the vulnerability
|
||||||
|
- Steps to reproduce or a proof of concept
|
||||||
|
- The affected component(s) and potential impact
|
||||||
|
|
||||||
|
We will acknowledge your report within **48 hours** and work with you on a fix under a **90-day coordinated disclosure** timeline.
|
||||||
|
|
||||||
|
## What Qualifies
|
||||||
|
|
||||||
|
- Cryptographic implementation bugs (MLS, Noise, hybrid KEM, key derivation)
|
||||||
|
- Authentication or authorization bypass
|
||||||
|
- Key material leakage (memory, logs, network)
|
||||||
|
- Protocol-level flaws (replay, downgrade, impersonation)
|
||||||
|
- Any issue that compromises message confidentiality or integrity
|
||||||
|
|
||||||
|
## Credit
|
||||||
|
|
||||||
|
Reporters are credited in published security advisories unless they prefer to remain anonymous. Let us know your preference when you report.
|
||||||
229
SPRINTS.md
Normal file
229
SPRINTS.md
Normal file
@@ -0,0 +1,229 @@
|
|||||||
|
# quicprochat — Sprint Plan
|
||||||
|
|
||||||
|
> 7 sprints synthesized from code audit, architecture analysis, and ecosystem research.
|
||||||
|
> Each sprint is ~1 week. Sprints are ordered by priority and dependency.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Sprint 1 — Bug Fixes & Code Quality (Quick Wins)
|
||||||
|
|
||||||
|
Fix all known bugs, clippy warnings, and dead code before building on top.
|
||||||
|
|
||||||
|
- [x] **1.1 Fix boolean logic bug in TUI**
|
||||||
|
- `crates/quicprochat-client/src/client/v2_tui.rs:832` — remove `|| true`
|
||||||
|
- Cursor positioning always executes regardless of input state
|
||||||
|
|
||||||
|
- [x] **1.2 Fix unwrap violations in P2P router**
|
||||||
|
- `crates/quicprochat-p2p/src/routing.rs:416,419` — `.lock().unwrap()` on Mutex
|
||||||
|
- Replace with `.expect("lock poisoned")` or proper error handling
|
||||||
|
|
||||||
|
- [x] **1.3 Remove placeholder assertion in WebTransport**
|
||||||
|
- `crates/quicprochat-server/src/webtransport.rs:418` — `assert!(true);`
|
||||||
|
|
||||||
|
- [x] **1.4 Wire up unused metrics**
|
||||||
|
- `record_storage_latency()` — instrument storage layer calls
|
||||||
|
- `record_uptime_seconds()` — add periodic heartbeat task in server main loop
|
||||||
|
|
||||||
|
- [x] **1.5 Wire up or remove unused config fields**
|
||||||
|
- `EffectiveConfig::webtransport_listen` — connect to WebTransport listener
|
||||||
|
- `EffectiveConfig::rpc_timeout_secs` — apply as per-RPC deadline
|
||||||
|
- `EffectiveConfig::storage_timeout_secs` — apply as DB query timeout
|
||||||
|
|
||||||
|
- [x] **1.6 Fix remaining clippy warnings**
|
||||||
|
- Reduce function arity (2 functions with 8-9 args → use config/param structs)
|
||||||
|
- Remove useless `format!()` call
|
||||||
|
- Collapse nested conditionals
|
||||||
|
- Rename `from_str` method to avoid `FromStr` trait confusion
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Sprint 2 — OpenMLS 0.5 → 0.8 Migration
|
||||||
|
|
||||||
|
**CRITICAL**: OpenMLS 0.7.2 includes security patches. Staying on 0.5 is a risk.
|
||||||
|
|
||||||
|
- [x] **2.1 Migrate StorageProvider trait**
|
||||||
|
- Old `OpenMlsKeyStore` → new `StorageProvider` (most invasive change)
|
||||||
|
- Rework `DiskKeyStore` integration (must keep bincode serialization)
|
||||||
|
- Update all `group.rs` calls that interact with the key store
|
||||||
|
|
||||||
|
- [x] **2.2 Update MLS API calls**
|
||||||
|
- `self_update()` / `propose_self_update()` — add `LeafNodeParameters` arg
|
||||||
|
- `join_by_external_commit()` — add optional LeafNode params
|
||||||
|
- `Sender::NewMember` → split into `NewMemberProposal` / `NewMemberCommit`
|
||||||
|
|
||||||
|
- [x] **2.3 Handle GREASE support**
|
||||||
|
- New variants in `ProposalType`, `ExtensionType`, `CredentialType`
|
||||||
|
- Update match arms to handle unknown/GREASE values
|
||||||
|
|
||||||
|
- [x] **2.4 Update AAD handling**
|
||||||
|
- AAD no longer persisted — set before every API call generating `MlsMessageOut`
|
||||||
|
|
||||||
|
- [x] **2.5 Verify FIPS 203 alignment**
|
||||||
|
- Confirm ML-KEM-768 parameters match final FIPS 203 (not draft)
|
||||||
|
- Review hybrid KEM against RFC 9794 combination methods
|
||||||
|
|
||||||
|
- [x] **2.6 Full test suite pass**
|
||||||
|
- All 301 tests must pass with OpenMLS 0.8
|
||||||
|
- Run crypto benchmarks to check for performance regressions
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Sprint 3 — Client Resilience
|
||||||
|
|
||||||
|
Currently, network glitches cause the client to hang. This blocks v2 launch.
|
||||||
|
|
||||||
|
- [x] **3.1 Auto-reconnect with backoff**
|
||||||
|
- Integrate existing `retry.rs` into `RpcClient::call()` path
|
||||||
|
- Exponential backoff with jitter (already implemented, not wired)
|
||||||
|
- Configurable max retries and backoff ceiling
|
||||||
|
|
||||||
|
- [x] **3.2 Push subscription recovery**
|
||||||
|
- Detect broken push stream and re-subscribe automatically
|
||||||
|
- Buffer missed events during reconnection window
|
||||||
|
|
||||||
|
- [x] **3.3 Heartbeat / keepalive**
|
||||||
|
- Periodic QUIC ping in TUI and REPL modes
|
||||||
|
- Detect dead connections before user notices
|
||||||
|
|
||||||
|
- [x] **3.4 SDK disconnect lifecycle**
|
||||||
|
- Add `QpcClient::disconnect()` for clean shutdown
|
||||||
|
- Proper state machine: Connected → Reconnecting → Disconnected
|
||||||
|
|
||||||
|
- [x] **3.5 Connection status UI**
|
||||||
|
- TUI: show connection state in status bar (Connected / Reconnecting / Offline)
|
||||||
|
- REPL: print status change notifications
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Sprint 4 — Server Hardening
|
||||||
|
|
||||||
|
Fix graceful shutdown and wire up timeouts for production readiness.
|
||||||
|
|
||||||
|
- [x] **4.1 In-flight RPC tracking**
|
||||||
|
- Replace fixed 30s shutdown delay with actual in-flight RPC counter
|
||||||
|
- Drain when counter reaches zero (with configurable max wait)
|
||||||
|
|
||||||
|
- [x] **4.2 Apply request-level timeouts**
|
||||||
|
- Wire `rpc_timeout_secs` config into per-RPC deadline enforcement
|
||||||
|
- Wire `storage_timeout_secs` into DB query timeouts
|
||||||
|
- Cancel long-running operations cleanly
|
||||||
|
|
||||||
|
- [x] **4.3 Plugin shutdown hooks**
|
||||||
|
- Add `on_shutdown` hook to `HookVTable`
|
||||||
|
- Call plugin shutdown before server exits
|
||||||
|
|
||||||
|
- [x] **4.4 Federation drain during shutdown**
|
||||||
|
- Stop accepting federation relay requests on SIGTERM
|
||||||
|
- Wait for in-flight federation RPCs before exit
|
||||||
|
|
||||||
|
- [x] **4.5 Connection draining improvements**
|
||||||
|
- Send QUIC CONNECTION_CLOSE with application reason
|
||||||
|
- WebTransport: send close frame before dropping sessions
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Sprint 5 — Test Coverage & CI Hardening
|
||||||
|
|
||||||
|
Address the major test coverage gaps identified in the audit.
|
||||||
|
|
||||||
|
- [x] **5.1 RPC framing unit tests**
|
||||||
|
- `crates/quicprochat-rpc/src/framing.rs` — encode/decode edge cases
|
||||||
|
- Malformed frames, truncated input, max-size payloads
|
||||||
|
- Fuzzing harness for frame parser
|
||||||
|
|
||||||
|
- [x] **5.2 SDK state machine tests**
|
||||||
|
- `crates/quicprochat-sdk/src/conversation.rs` — conversation lifecycle
|
||||||
|
- `crates/quicprochat-sdk/src/groups.rs` — group join/leave/update
|
||||||
|
- `crates/quicprochat-sdk/src/messaging.rs` — send/receive/queue
|
||||||
|
|
||||||
|
- [x] **5.3 Server domain service tests**
|
||||||
|
- `crates/quicprochat-server/src/domain/` — all service modules
|
||||||
|
- Test business logic without DB (mock storage trait)
|
||||||
|
|
||||||
|
- [x] **5.4 Integration tests**
|
||||||
|
- Reconnection scenario (kill server, restart, verify client recovers)
|
||||||
|
- Graceful shutdown (send SIGTERM during active RPCs, verify drain)
|
||||||
|
- Multi-node federation relay (if federation wired in Sprint 6)
|
||||||
|
|
||||||
|
- [x] **5.5 CI hardening**
|
||||||
|
- Add MSRV check (Rust 1.75 or declared minimum)
|
||||||
|
- Add cross-platform CI (macOS, Windows — at least build check)
|
||||||
|
- Add cargo-fuzz for crypto and parsing code
|
||||||
|
- Add MIRI for unsafe code in plugin-api/FFI
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Sprint 6 — Federation & P2P Integration
|
||||||
|
|
||||||
|
Wire up the scaffolded federation and P2P code into working features.
|
||||||
|
|
||||||
|
- [x] **6.1 Federation message routing**
|
||||||
|
- Wire `federation::routing::resolve_destination()` into `handle_enqueue`
|
||||||
|
- Route messages to remote home servers via `FederationClient::relay_enqueue()`
|
||||||
|
- Resolve protocol mismatch (Cap'n Proto federation vs Protobuf main RPC)
|
||||||
|
|
||||||
|
- [x] **6.2 Federation identity resolution**
|
||||||
|
- Cross-server user lookup (`user@remote-server`)
|
||||||
|
- KeyPackage fetching across federated nodes
|
||||||
|
|
||||||
|
- [x] **6.3 P2P client integration**
|
||||||
|
- Wire iroh P2P into client as transport option
|
||||||
|
- Fallback logic: prefer P2P direct → fall back to server relay
|
||||||
|
- mDNS discovery in client (already scaffolded, needs activation)
|
||||||
|
|
||||||
|
- [x] **6.4 Multipath QUIC evaluation**
|
||||||
|
- Research draft-ietf-quic-multipath (likely RFC in 2026)
|
||||||
|
- Prototype: use multiple paths for mesh relay resilience
|
||||||
|
- Decision: adopt or defer based on quinn support
|
||||||
|
|
||||||
|
- [x] **6.5 Federation integration tests**
|
||||||
|
- Two-server test: register on A, send to user on B, verify delivery
|
||||||
|
- mTLS mutual auth verification
|
||||||
|
- Partition tolerance (one node goes down, messages queue)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Sprint 7 — Documentation, Polish & Future Prep
|
||||||
|
|
||||||
|
Final polish and forward-looking improvements.
|
||||||
|
|
||||||
|
- [x] **7.1 Crate-level documentation**
|
||||||
|
- Add module-level docs to `quicprochat-plugin-api`, `quicprochat-rpc`, `quicprochat-sdk`
|
||||||
|
- Doc comments for all public APIs in domain services
|
||||||
|
|
||||||
|
- [x] **7.2 Refactor high-arity functions** (none found — already clean)
|
||||||
|
- Consolidate 8-9 parameter functions into config/param structs
|
||||||
|
- Improve builder patterns where appropriate
|
||||||
|
|
||||||
|
- [ ] **7.3 Review RFC 9750 (MLS Architecture)** (deferred — requires manual review)
|
||||||
|
- Verify quicprochat's AS/DS split aligns with RFC 9750 recommendations
|
||||||
|
- Document any deviations and rationale
|
||||||
|
|
||||||
|
- [ ] **7.4 Desktop client evaluation** (deferred — requires Tauri prototype)
|
||||||
|
- Prototype Tauri v2 desktop shell wrapping the TUI or a web UI
|
||||||
|
- Evaluate effort to ship cross-platform desktop client
|
||||||
|
|
||||||
|
- [x] **7.5 Security pre-audit prep**
|
||||||
|
- Document all crypto boundaries and trust assumptions
|
||||||
|
- Create threat model document
|
||||||
|
- Prepare scope document for external auditors (Roadmap item 4.1)
|
||||||
|
- Budget: NCC Group / Trail of Bits / Cure53 ($50K–$150K, 4-6 weeks)
|
||||||
|
|
||||||
|
- [ ] **7.6 Repository rename** (requires GitHub admin action)
|
||||||
|
- Rename GitHub repository from `quicproquo` → `quicprochat`
|
||||||
|
- Update all GitHub URLs, CI badge links, go.mod import paths
|
||||||
|
- Set up redirect from old repo name
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Sprint Summary
|
||||||
|
|
||||||
|
| Sprint | Focus | Risk | Key Deliverable |
|
||||||
|
|--------|-------|------|----------------|
|
||||||
|
| **1** | Bug fixes & code quality | Low | Zero clippy warnings, metrics wired |
|
||||||
|
| **2** | OpenMLS 0.5 → 0.8 | High | Security patches applied, FIPS 203 verified |
|
||||||
|
| **3** | Client resilience | Medium | Auto-reconnect, heartbeat, status UI |
|
||||||
|
| **4** | Server hardening | Medium | Real graceful shutdown, timeouts enforced |
|
||||||
|
| **5** | Test coverage & CI | Low | Unit tests for SDK/RPC/domain, fuzzing |
|
||||||
|
| **6** | Federation & P2P | High | Working cross-server messaging, P2P fallback |
|
||||||
|
| **7** | Docs, polish & audit prep | Low | Audit-ready, desktop prototype |
|
||||||
@@ -1,18 +1,19 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "quicproquo-client"
|
name = "quicprochat-client"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition.workspace = true
|
||||||
description = "CLI client for quicproquo."
|
description = "CLI client for quicprochat."
|
||||||
license = "MIT"
|
license = "Apache-2.0 OR MIT"
|
||||||
|
repository.workspace = true
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "qpq"
|
name = "qpc"
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
quicproquo-core = { path = "../quicproquo-core" }
|
quicprochat-core = { path = "../quicprochat-core" }
|
||||||
quicproquo-proto = { path = "../quicproquo-proto" }
|
quicprochat-proto = { path = "../quicprochat-proto" }
|
||||||
quicproquo-kt = { path = "../quicproquo-kt" }
|
quicprochat-kt = { path = "../quicprochat-kt" }
|
||||||
openmls_rust_crypto = { workspace = true }
|
openmls_rust_crypto = { workspace = true }
|
||||||
|
|
||||||
# Serialisation + RPC
|
# Serialisation + RPC
|
||||||
@@ -49,8 +50,9 @@ rustls = { workspace = true }
|
|||||||
tracing = { workspace = true }
|
tracing = { workspace = true }
|
||||||
tracing-subscriber = { workspace = true }
|
tracing-subscriber = { workspace = true }
|
||||||
|
|
||||||
# CLI
|
# CLI + config
|
||||||
clap = { workspace = true }
|
clap = { workspace = true }
|
||||||
|
toml = { workspace = true }
|
||||||
|
|
||||||
# Local message/conversation storage
|
# Local message/conversation storage
|
||||||
rusqlite = { workspace = true }
|
rusqlite = { workspace = true }
|
||||||
@@ -65,7 +67,7 @@ rpassword = "5"
|
|||||||
mdns-sd = { version = "0.12", optional = true }
|
mdns-sd = { version = "0.12", optional = true }
|
||||||
|
|
||||||
# Optional P2P transport for direct node-to-node messaging.
|
# Optional P2P transport for direct node-to-node messaging.
|
||||||
quicproquo-p2p = { path = "../quicproquo-p2p", optional = true }
|
quicprochat-p2p = { path = "../quicprochat-p2p", optional = true }
|
||||||
|
|
||||||
# Optional TUI dependencies (Ratatui full-screen interface).
|
# Optional TUI dependencies (Ratatui full-screen interface).
|
||||||
ratatui = { version = "0.29", optional = true, default-features = false, features = ["crossterm"] }
|
ratatui = { version = "0.29", optional = true, default-features = false, features = ["crossterm"] }
|
||||||
@@ -74,9 +76,9 @@ crossterm = { version = "0.28", optional = true }
|
|||||||
# YAML playbook parsing (only compiled with --features playbook).
|
# YAML playbook parsing (only compiled with --features playbook).
|
||||||
serde_yaml = { version = "0.9", optional = true }
|
serde_yaml = { version = "0.9", optional = true }
|
||||||
|
|
||||||
# v2 SDK-based CLI (thin shell over quicproquo-sdk).
|
# v2 SDK-based CLI (thin shell over quicprochat-sdk).
|
||||||
quicproquo-sdk = { path = "../quicproquo-sdk", optional = true }
|
quicprochat-sdk = { path = "../quicprochat-sdk", optional = true }
|
||||||
quicproquo-rpc = { path = "../quicproquo-rpc", optional = true }
|
quicprochat-rpc = { path = "../quicprochat-rpc", optional = true }
|
||||||
rustyline = { workspace = true, optional = true }
|
rustyline = { workspace = true, optional = true }
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
@@ -84,15 +86,15 @@ workspace = true
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
# Enable mesh-mode features: mDNS local peer discovery + P2P transport.
|
# Enable mesh-mode features: mDNS local peer discovery + P2P transport.
|
||||||
# Build: cargo build -p quicproquo-client --features mesh
|
# Build: cargo build -p quicprochat-client --features mesh
|
||||||
mesh = ["dep:mdns-sd", "dep:quicproquo-p2p"]
|
mesh = ["dep:mdns-sd", "dep:quicprochat-p2p"]
|
||||||
# Enable full-screen Ratatui TUI: cargo build -p quicproquo-client --features tui
|
# Enable full-screen Ratatui TUI: cargo build -p quicprochat-client --features tui
|
||||||
tui = ["dep:ratatui", "dep:crossterm"]
|
tui = ["dep:ratatui", "dep:crossterm"]
|
||||||
# Enable playbook (scripted command execution): YAML parser + serde derives.
|
# Enable playbook (scripted command execution): YAML parser + serde derives.
|
||||||
# Build: cargo build -p quicproquo-client --features playbook
|
# Build: cargo build -p quicprochat-client --features playbook
|
||||||
playbook = ["dep:serde_yaml"]
|
playbook = ["dep:serde_yaml"]
|
||||||
# v2 CLI over SDK: cargo build -p quicproquo-client --features v2
|
# v2 CLI over SDK: cargo build -p quicprochat-client --features v2
|
||||||
v2 = ["dep:quicproquo-sdk", "dep:quicproquo-rpc", "dep:rustyline"]
|
v2 = ["dep:quicprochat-sdk", "dep:quicprochat-rpc", "dep:rustyline"]
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
dashmap = { workspace = true }
|
dashmap = { workspace = true }
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use quicproquo_proto::node_capnp::node_service;
|
use quicprochat_proto::node_capnp::node_service;
|
||||||
|
|
||||||
use super::repl::{Input, SlashCommand, parse_input};
|
use super::repl::{Input, SlashCommand, parse_input};
|
||||||
use super::session::SessionState;
|
use super::session::SessionState;
|
||||||
@@ -109,6 +109,8 @@ pub enum Command {
|
|||||||
History { count: usize },
|
History { count: usize },
|
||||||
|
|
||||||
// Mesh
|
// Mesh
|
||||||
|
MeshStart,
|
||||||
|
MeshStop,
|
||||||
MeshPeers,
|
MeshPeers,
|
||||||
MeshServer { addr: String },
|
MeshServer { addr: String },
|
||||||
MeshSend { peer_id: String, message: String },
|
MeshSend { peer_id: String, message: String },
|
||||||
@@ -171,6 +173,8 @@ impl Command {
|
|||||||
Command::GroupInfo => Some(SlashCommand::GroupInfo),
|
Command::GroupInfo => Some(SlashCommand::GroupInfo),
|
||||||
Command::Rename { name } => Some(SlashCommand::Rename { name }),
|
Command::Rename { name } => Some(SlashCommand::Rename { name }),
|
||||||
Command::History { count } => Some(SlashCommand::History { count }),
|
Command::History { count } => Some(SlashCommand::History { count }),
|
||||||
|
Command::MeshStart => Some(SlashCommand::MeshStart),
|
||||||
|
Command::MeshStop => Some(SlashCommand::MeshStop),
|
||||||
Command::MeshPeers => Some(SlashCommand::MeshPeers),
|
Command::MeshPeers => Some(SlashCommand::MeshPeers),
|
||||||
Command::MeshServer { addr } => Some(SlashCommand::MeshServer { addr }),
|
Command::MeshServer { addr } => Some(SlashCommand::MeshServer { addr }),
|
||||||
Command::MeshSend { peer_id, message } => {
|
Command::MeshSend { peer_id, message } => {
|
||||||
@@ -332,6 +336,8 @@ fn slash_to_command(sc: SlashCommand) -> Command {
|
|||||||
SlashCommand::GroupInfo => Command::GroupInfo,
|
SlashCommand::GroupInfo => Command::GroupInfo,
|
||||||
SlashCommand::Rename { name } => Command::Rename { name },
|
SlashCommand::Rename { name } => Command::Rename { name },
|
||||||
SlashCommand::History { count } => Command::History { count },
|
SlashCommand::History { count } => Command::History { count },
|
||||||
|
SlashCommand::MeshStart => Command::MeshStart,
|
||||||
|
SlashCommand::MeshStop => Command::MeshStop,
|
||||||
SlashCommand::MeshPeers => Command::MeshPeers,
|
SlashCommand::MeshPeers => Command::MeshPeers,
|
||||||
SlashCommand::MeshServer { addr } => Command::MeshServer { addr },
|
SlashCommand::MeshServer { addr } => Command::MeshServer { addr },
|
||||||
SlashCommand::MeshSend { peer_id, message } => Command::MeshSend { peer_id, message },
|
SlashCommand::MeshSend { peer_id, message } => Command::MeshSend { peer_id, message },
|
||||||
@@ -394,6 +400,8 @@ async fn execute_slash(
|
|||||||
SlashCommand::GroupInfo => cmd_group_info(session, client).await,
|
SlashCommand::GroupInfo => cmd_group_info(session, client).await,
|
||||||
SlashCommand::Rename { name } => cmd_rename(session, &name),
|
SlashCommand::Rename { name } => cmd_rename(session, &name),
|
||||||
SlashCommand::History { count } => cmd_history(session, count),
|
SlashCommand::History { count } => cmd_history(session, count),
|
||||||
|
SlashCommand::MeshStart => cmd_mesh_start(session).await,
|
||||||
|
SlashCommand::MeshStop => cmd_mesh_stop(session).await,
|
||||||
SlashCommand::MeshPeers => cmd_mesh_peers(),
|
SlashCommand::MeshPeers => cmd_mesh_peers(),
|
||||||
SlashCommand::MeshServer { addr } => {
|
SlashCommand::MeshServer { addr } => {
|
||||||
super::display::print_status(&format!(
|
super::display::print_status(&format!(
|
||||||
@@ -401,9 +409,9 @@ async fn execute_slash(
|
|||||||
));
|
));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
SlashCommand::MeshSend { peer_id, message } => cmd_mesh_send(&peer_id, &message),
|
SlashCommand::MeshSend { peer_id, message } => cmd_mesh_send(session, &peer_id, &message).await,
|
||||||
SlashCommand::MeshBroadcast { topic, message } => cmd_mesh_broadcast(&topic, &message),
|
SlashCommand::MeshBroadcast { topic, message } => cmd_mesh_broadcast(session, &topic, &message).await,
|
||||||
SlashCommand::MeshSubscribe { topic } => cmd_mesh_subscribe(&topic),
|
SlashCommand::MeshSubscribe { topic } => cmd_mesh_subscribe(session, &topic),
|
||||||
SlashCommand::MeshRoute => cmd_mesh_route(session),
|
SlashCommand::MeshRoute => cmd_mesh_route(session),
|
||||||
SlashCommand::MeshIdentity => cmd_mesh_identity(session),
|
SlashCommand::MeshIdentity => cmd_mesh_identity(session),
|
||||||
SlashCommand::MeshStore => cmd_mesh_store(session),
|
SlashCommand::MeshStore => cmd_mesh_store(session),
|
||||||
@@ -5,7 +5,7 @@ use opaque_ke::{
|
|||||||
ClientLogin, ClientLoginFinishParameters, ClientRegistration,
|
ClientLogin, ClientLoginFinishParameters, ClientRegistration,
|
||||||
ClientRegistrationFinishParameters, CredentialResponse, RegistrationResponse,
|
ClientRegistrationFinishParameters, CredentialResponse, RegistrationResponse,
|
||||||
};
|
};
|
||||||
use quicproquo_core::{
|
use quicprochat_core::{
|
||||||
generate_key_package, hybrid_decrypt, hybrid_encrypt, opaque_auth::OpaqueSuite,
|
generate_key_package, hybrid_decrypt, hybrid_encrypt, opaque_auth::OpaqueSuite,
|
||||||
GroupMember, HybridKeypair, IdentityKeypair, ReceivedMessage,
|
GroupMember, HybridKeypair, IdentityKeypair, ReceivedMessage,
|
||||||
};
|
};
|
||||||
@@ -317,7 +317,7 @@ fn derive_identity_for_login(
|
|||||||
/// The error message contains "E018" if the user already exists.
|
/// The error message contains "E018" if the user already exists.
|
||||||
/// Does NOT require init_auth() — OPAQUE RPCs are unauthenticated.
|
/// Does NOT require init_auth() — OPAQUE RPCs are unauthenticated.
|
||||||
pub(crate) async fn opaque_register(
|
pub(crate) async fn opaque_register(
|
||||||
client: &quicproquo_proto::node_capnp::node_service::Client,
|
client: &quicprochat_proto::node_capnp::node_service::Client,
|
||||||
username: &str,
|
username: &str,
|
||||||
password: &str,
|
password: &str,
|
||||||
identity_key: Option<&[u8]>,
|
identity_key: Option<&[u8]>,
|
||||||
@@ -378,7 +378,7 @@ pub(crate) async fn opaque_register(
|
|||||||
/// Perform OPAQUE login and return the raw session token bytes.
|
/// Perform OPAQUE login and return the raw session token bytes.
|
||||||
/// Does NOT require init_auth() — OPAQUE RPCs are unauthenticated.
|
/// Does NOT require init_auth() — OPAQUE RPCs are unauthenticated.
|
||||||
pub async fn opaque_login(
|
pub async fn opaque_login(
|
||||||
client: &quicproquo_proto::node_capnp::node_service::Client,
|
client: &quicprochat_proto::node_capnp::node_service::Client,
|
||||||
username: &str,
|
username: &str,
|
||||||
password: &str,
|
password: &str,
|
||||||
identity_key: &[u8],
|
identity_key: &[u8],
|
||||||
@@ -647,8 +647,8 @@ pub async fn cmd_fetch_key(
|
|||||||
|
|
||||||
/// Run a two-party MLS demo against the unified server.
|
/// Run a two-party MLS demo against the unified server.
|
||||||
pub async fn cmd_demo_group(server: &str, ca_cert: &Path, server_name: &str) -> anyhow::Result<()> {
|
pub async fn cmd_demo_group(server: &str, ca_cert: &Path, server_name: &str) -> anyhow::Result<()> {
|
||||||
let creator_state_path = PathBuf::from("qpq-demo-creator.bin");
|
let creator_state_path = PathBuf::from("qpc-demo-creator.bin");
|
||||||
let joiner_state_path = PathBuf::from("qpq-demo-joiner.bin");
|
let joiner_state_path = PathBuf::from("qpc-demo-joiner.bin");
|
||||||
|
|
||||||
let (mut creator, creator_hybrid_opt) =
|
let (mut creator, creator_hybrid_opt) =
|
||||||
load_or_init_state(&creator_state_path, None)?.into_parts(&creator_state_path)?;
|
load_or_init_state(&creator_state_path, None)?.into_parts(&creator_state_path)?;
|
||||||
@@ -1298,7 +1298,7 @@ pub async fn cmd_chat(
|
|||||||
///
|
///
|
||||||
/// `conv_db` is the path to the conversation SQLite database (`.convdb` file).
|
/// `conv_db` is the path to the conversation SQLite database (`.convdb` file).
|
||||||
/// `conv_id_hex` is the 32-hex-character conversation ID to export.
|
/// `conv_id_hex` is the 32-hex-character conversation ID to export.
|
||||||
/// `output` is the path for the `.qpqt` transcript file to write.
|
/// `output` is the path for the `.qpct` transcript file to write.
|
||||||
/// `transcript_password` is used to derive the encryption key (Argon2id).
|
/// `transcript_password` is used to derive the encryption key (Argon2id).
|
||||||
/// `db_password` is the optional SQLCipher password for the conversation database.
|
/// `db_password` is the optional SQLCipher password for the conversation database.
|
||||||
pub fn cmd_export(
|
pub fn cmd_export(
|
||||||
@@ -1308,7 +1308,7 @@ pub fn cmd_export(
|
|||||||
transcript_password: &str,
|
transcript_password: &str,
|
||||||
db_password: Option<&str>,
|
db_password: Option<&str>,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
use quicproquo_core::{TranscriptRecord, TranscriptWriter};
|
use quicprochat_core::{TranscriptRecord, TranscriptWriter};
|
||||||
use super::conversation::{ConversationId, ConversationStore};
|
use super::conversation::{ConversationId, ConversationStore};
|
||||||
|
|
||||||
// Decode conversation ID from hex.
|
// Decode conversation ID from hex.
|
||||||
@@ -1367,7 +1367,7 @@ pub fn cmd_export(
|
|||||||
conv.display_name,
|
conv.display_name,
|
||||||
output.display()
|
output.display()
|
||||||
);
|
);
|
||||||
println!("Decrypt with: qpq export verify --input <file> --password <password>");
|
println!("Decrypt with: qpc export verify --input <file> --password <password>");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -1376,7 +1376,7 @@ pub fn cmd_export(
|
|||||||
///
|
///
|
||||||
/// Prints a summary. Does not require the encryption password (structural check only).
|
/// Prints a summary. Does not require the encryption password (structural check only).
|
||||||
pub fn cmd_export_verify(input: &Path) -> anyhow::Result<()> {
|
pub fn cmd_export_verify(input: &Path) -> anyhow::Result<()> {
|
||||||
use quicproquo_core::{validate_transcript_structure, ChainVerdict};
|
use quicprochat_core::{validate_transcript_structure, ChainVerdict};
|
||||||
|
|
||||||
let data = std::fs::read(input)
|
let data = std::fs::read(input)
|
||||||
.with_context(|| format!("read transcript file '{}'", input.display()))?;
|
.with_context(|| format!("read transcript file '{}'", input.display()))?;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
//! mDNS-based peer discovery for Freifunk / community mesh deployments.
|
//! mDNS-based peer discovery for Freifunk / community mesh deployments.
|
||||||
//!
|
//!
|
||||||
//! Browse for `_quicproquo._udp.local.` services on the local network and
|
//! Browse for `_quicprochat._udp.local.` services on the local network and
|
||||||
//! surface them as [`DiscoveredPeer`] structs. Servers announce themselves
|
//! surface them as [`DiscoveredPeer`] structs. Servers announce themselves
|
||||||
//! automatically on startup; this module lets clients find them without manual
|
//! automatically on startup; this module lets clients find them without manual
|
||||||
//! configuration.
|
//! configuration.
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
//! # Usage
|
//! # Usage
|
||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! use quicproquo_client::client::mesh_discovery::MeshDiscovery;
|
//! use quicprochat_client::client::mesh_discovery::MeshDiscovery;
|
||||||
//!
|
//!
|
||||||
//! let disc = MeshDiscovery::start()?;
|
//! let disc = MeshDiscovery::start()?;
|
||||||
//! // Give mDNS time to collect announcements before reading.
|
//! // Give mDNS time to collect announcements before reading.
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
//! for peer in disc.peers() {
|
//! for peer in disc.peers() {
|
||||||
//! println!("found: {} at {}", peer.domain, peer.server_addr);
|
//! println!("found: {} at {}", peer.domain, peer.server_addr);
|
||||||
//! }
|
//! }
|
||||||
//! # Ok::<(), quicproquo_client::client::mesh_discovery::MeshDiscoveryError>(())
|
//! # Ok::<(), quicprochat_client::client::mesh_discovery::MeshDiscoveryError>(())
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
#[cfg(feature = "mesh")]
|
#[cfg(feature = "mesh")]
|
||||||
@@ -27,7 +27,7 @@ use std::sync::{Arc, Mutex};
|
|||||||
#[cfg(feature = "mesh")]
|
#[cfg(feature = "mesh")]
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
/// A qpq server discovered on the local network via mDNS.
|
/// A qpc server discovered on the local network via mDNS.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct DiscoveredPeer {
|
pub struct DiscoveredPeer {
|
||||||
/// Federation domain of the remote server (e.g. `"node1.freifunk.net"`).
|
/// Federation domain of the remote server (e.g. `"node1.freifunk.net"`).
|
||||||
@@ -57,7 +57,7 @@ pub enum MeshDiscoveryError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl MeshDiscovery {
|
impl MeshDiscovery {
|
||||||
/// Start browsing for `_quicproquo._udp.local.` services.
|
/// Start browsing for `_quicprochat._udp.local.` services.
|
||||||
///
|
///
|
||||||
/// Returns immediately; peers are collected in the background.
|
/// Returns immediately; peers are collected in the background.
|
||||||
/// Returns [`MeshDiscoveryError::FeatureDisabled`] when built without the
|
/// Returns [`MeshDiscoveryError::FeatureDisabled`] when built without the
|
||||||
@@ -79,7 +79,7 @@ impl MeshDiscovery {
|
|||||||
.map_err(|e| MeshDiscoveryError::DaemonError(e.to_string()))?;
|
.map_err(|e| MeshDiscoveryError::DaemonError(e.to_string()))?;
|
||||||
|
|
||||||
let receiver = daemon
|
let receiver = daemon
|
||||||
.browse("_quicproquo._udp.local.")
|
.browse("_quicprochat._udp.local.")
|
||||||
.map_err(|e| MeshDiscoveryError::BrowseError(e.to_string()))?;
|
.map_err(|e| MeshDiscoveryError::BrowseError(e.to_string()))?;
|
||||||
|
|
||||||
let peers: Arc<Mutex<HashMap<String, DiscoveredPeer>>> =
|
let peers: Arc<Mutex<HashMap<String, DiscoveredPeer>>> =
|
||||||
@@ -91,7 +91,7 @@ impl MeshDiscovery {
|
|||||||
for event in receiver {
|
for event in receiver {
|
||||||
match event {
|
match event {
|
||||||
ServiceEvent::ServiceResolved(info) => {
|
ServiceEvent::ServiceResolved(info) => {
|
||||||
// Extract the qpq server address from TXT records.
|
// Extract the qpc server address from TXT records.
|
||||||
let server_addr_str = info
|
let server_addr_str = info
|
||||||
.get_property_val_str("server")
|
.get_property_val_str("server")
|
||||||
.map(|s| s.to_string());
|
.map(|s| s.to_string());
|
||||||
@@ -24,7 +24,7 @@ use std::path::Path;
|
|||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
use anyhow::{Context, bail};
|
use anyhow::{Context, bail};
|
||||||
use quicproquo_proto::node_capnp::node_service;
|
use quicprochat_proto::node_capnp::node_service;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::command_engine::{AssertCondition, CmpOp, Command, CommandRegistry};
|
use super::command_engine::{AssertCondition, CmpOp, Command, CommandRegistry};
|
||||||
@@ -9,13 +9,13 @@ use std::sync::Arc;
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use quicproquo_core::{
|
use quicprochat_core::{
|
||||||
AppMessage, DiskKeyStore, GroupMember, IdentityKeypair, ReceivedMessage,
|
AppMessage, DiskKeyStore, GroupMember, IdentityKeypair, ReceivedMessage,
|
||||||
compute_safety_number, hybrid_encrypt, parse as parse_app_msg, serialize_chat,
|
compute_safety_number, hybrid_encrypt, parse as parse_app_msg, serialize_chat,
|
||||||
serialize_delete, serialize_dummy, serialize_edit, serialize_file_ref, serialize_reaction,
|
serialize_delete, serialize_dummy, serialize_edit, serialize_file_ref, serialize_reaction,
|
||||||
serialize_read_receipt, serialize_typing,
|
serialize_read_receipt, serialize_typing,
|
||||||
};
|
};
|
||||||
use quicproquo_proto::node_capnp::node_service;
|
use quicprochat_proto::node_capnp::node_service;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use tokio::time::interval;
|
use tokio::time::interval;
|
||||||
|
|
||||||
@@ -60,6 +60,8 @@ pub(crate) enum SlashCommand {
|
|||||||
Rename { name: String },
|
Rename { name: String },
|
||||||
History { count: usize },
|
History { count: usize },
|
||||||
/// Mesh subcommands: /mesh peers, /mesh server <addr>, etc.
|
/// Mesh subcommands: /mesh peers, /mesh server <addr>, etc.
|
||||||
|
MeshStart,
|
||||||
|
MeshStop,
|
||||||
MeshPeers,
|
MeshPeers,
|
||||||
MeshServer { addr: String },
|
MeshServer { addr: String },
|
||||||
MeshSend { peer_id: String, message: String },
|
MeshSend { peer_id: String, message: String },
|
||||||
@@ -173,6 +175,8 @@ pub(crate) fn parse_input(line: &str) -> Input {
|
|||||||
Input::Slash(SlashCommand::History { count })
|
Input::Slash(SlashCommand::History { count })
|
||||||
}
|
}
|
||||||
"/mesh" => match arg.as_deref() {
|
"/mesh" => match arg.as_deref() {
|
||||||
|
Some("start") => Input::Slash(SlashCommand::MeshStart),
|
||||||
|
Some("stop") => Input::Slash(SlashCommand::MeshStop),
|
||||||
Some("peers") => Input::Slash(SlashCommand::MeshPeers),
|
Some("peers") => Input::Slash(SlashCommand::MeshPeers),
|
||||||
Some(rest) if rest.starts_with("server ") => {
|
Some(rest) if rest.starts_with("server ") => {
|
||||||
let addr = rest.trim_start_matches("server ").trim().to_string();
|
let addr = rest.trim_start_matches("server ").trim().to_string();
|
||||||
@@ -221,7 +225,7 @@ pub(crate) fn parse_input(line: &str) -> Input {
|
|||||||
Some("store") => Input::Slash(SlashCommand::MeshStore),
|
Some("store") => Input::Slash(SlashCommand::MeshStore),
|
||||||
_ => {
|
_ => {
|
||||||
display::print_error(
|
display::print_error(
|
||||||
"usage: /mesh peers|server|send|broadcast|subscribe|route|identity|store"
|
"usage: /mesh start|stop|peers|server|send|broadcast|subscribe|route|identity|store"
|
||||||
);
|
);
|
||||||
Input::Empty
|
Input::Empty
|
||||||
}
|
}
|
||||||
@@ -355,10 +359,10 @@ fn derive_key_path(cert_path: &Path) -> PathBuf {
|
|||||||
cert_path.with_file_name(key_name)
|
cert_path.with_file_name(key_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Find the `qpq-server` binary: same directory as current exe, then PATH.
|
/// Find the `qpc-server` binary: same directory as current exe, then PATH.
|
||||||
fn find_server_binary() -> Option<PathBuf> {
|
fn find_server_binary() -> Option<PathBuf> {
|
||||||
if let Ok(exe) = std::env::current_exe() {
|
if let Ok(exe) = std::env::current_exe() {
|
||||||
let sibling = exe.with_file_name("qpq-server");
|
let sibling = exe.with_file_name("qpc-server");
|
||||||
if sibling.exists() {
|
if sibling.exists() {
|
||||||
return Some(sibling);
|
return Some(sibling);
|
||||||
}
|
}
|
||||||
@@ -366,7 +370,7 @@ fn find_server_binary() -> Option<PathBuf> {
|
|||||||
// Fall back to PATH lookup.
|
// Fall back to PATH lookup.
|
||||||
std::env::var_os("PATH").and_then(|paths| {
|
std::env::var_os("PATH").and_then(|paths| {
|
||||||
std::env::split_paths(&paths)
|
std::env::split_paths(&paths)
|
||||||
.map(|dir| dir.join("qpq-server"))
|
.map(|dir| dir.join("qpc-server"))
|
||||||
.find(|p| p.exists())
|
.find(|p| p.exists())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -400,13 +404,13 @@ async fn ensure_server(
|
|||||||
if ca_cert.exists() {
|
if ca_cert.exists() {
|
||||||
// Cert exists but connection failed and no binary found.
|
// Cert exists but connection failed and no binary found.
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
"server at {server} is not reachable and qpq-server binary not found; \
|
"server at {server} is not reachable and qpc-server binary not found; \
|
||||||
start a server manually or install qpq-server"
|
start a server manually or install qpc-server"
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
"no server running and qpq-server binary not found; \
|
"no server running and qpc-server binary not found; \
|
||||||
start a server manually or install qpq-server"
|
start a server manually or install qpc-server"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -445,7 +449,7 @@ async fn ensure_server(
|
|||||||
|
|
||||||
if start.elapsed() > max_wait {
|
if start.elapsed() > max_wait {
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
"auto-started qpq-server but it did not become ready within {max_wait:?}"
|
"auto-started qpc-server but it did not become ready within {max_wait:?}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -804,6 +808,8 @@ async fn handle_slash(
|
|||||||
SlashCommand::GroupInfo => cmd_group_info(session, client).await,
|
SlashCommand::GroupInfo => cmd_group_info(session, client).await,
|
||||||
SlashCommand::Rename { name } => cmd_rename(session, &name),
|
SlashCommand::Rename { name } => cmd_rename(session, &name),
|
||||||
SlashCommand::History { count } => cmd_history(session, count),
|
SlashCommand::History { count } => cmd_history(session, count),
|
||||||
|
SlashCommand::MeshStart => cmd_mesh_start(session).await,
|
||||||
|
SlashCommand::MeshStop => cmd_mesh_stop(session).await,
|
||||||
SlashCommand::MeshPeers => cmd_mesh_peers(),
|
SlashCommand::MeshPeers => cmd_mesh_peers(),
|
||||||
SlashCommand::MeshServer { addr } => {
|
SlashCommand::MeshServer { addr } => {
|
||||||
display::print_status(&format!(
|
display::print_status(&format!(
|
||||||
@@ -811,9 +817,9 @@ async fn handle_slash(
|
|||||||
));
|
));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
SlashCommand::MeshSend { peer_id, message } => cmd_mesh_send(&peer_id, &message),
|
SlashCommand::MeshSend { peer_id, message } => cmd_mesh_send(session, &peer_id, &message).await,
|
||||||
SlashCommand::MeshBroadcast { topic, message } => cmd_mesh_broadcast(&topic, &message),
|
SlashCommand::MeshBroadcast { topic, message } => cmd_mesh_broadcast(session, &topic, &message).await,
|
||||||
SlashCommand::MeshSubscribe { topic } => cmd_mesh_subscribe(&topic),
|
SlashCommand::MeshSubscribe { topic } => cmd_mesh_subscribe(session, &topic),
|
||||||
SlashCommand::MeshRoute => cmd_mesh_route(session),
|
SlashCommand::MeshRoute => cmd_mesh_route(session),
|
||||||
SlashCommand::MeshIdentity => cmd_mesh_identity(session),
|
SlashCommand::MeshIdentity => cmd_mesh_identity(session),
|
||||||
SlashCommand::MeshStore => cmd_mesh_store(session),
|
SlashCommand::MeshStore => cmd_mesh_store(session),
|
||||||
@@ -862,7 +868,9 @@ pub(crate) fn print_help() {
|
|||||||
display::print_status(" /rename <name> - Rename the current conversation");
|
display::print_status(" /rename <name> - Rename the current conversation");
|
||||||
display::print_status(" /history [N] - Show last N messages (default: 20)");
|
display::print_status(" /history [N] - Show last N messages (default: 20)");
|
||||||
display::print_status(" /whoami - Show your identity");
|
display::print_status(" /whoami - Show your identity");
|
||||||
display::print_status(" /mesh peers - Discover nearby qpq nodes via mDNS");
|
display::print_status(" /mesh start - Start the P2P node for direct messaging");
|
||||||
|
display::print_status(" /mesh stop - Stop the P2P node");
|
||||||
|
display::print_status(" /mesh peers - Discover nearby qpc nodes via mDNS");
|
||||||
display::print_status(" /mesh server <host:port> - Show how to reconnect to a mesh node");
|
display::print_status(" /mesh server <host:port> - Show how to reconnect to a mesh node");
|
||||||
display::print_status(" /mesh send <peer> <msg> - Send a P2P message to a mesh peer");
|
display::print_status(" /mesh send <peer> <msg> - Send a P2P message to a mesh peer");
|
||||||
display::print_status(" /mesh broadcast <topic> <m> - Broadcast an encrypted message on a topic");
|
display::print_status(" /mesh broadcast <topic> <m> - Broadcast an encrypted message on a topic");
|
||||||
@@ -1099,7 +1107,7 @@ pub(crate) async fn cmd_rotate_all_keys(
|
|||||||
cmd_update_key(session, client).await?;
|
cmd_update_key(session, client).await?;
|
||||||
|
|
||||||
// Step 2: Generate new hybrid KEM keypair and upload.
|
// Step 2: Generate new hybrid KEM keypair and upload.
|
||||||
let new_kp = quicproquo_core::HybridKeypair::generate();
|
let new_kp = quicprochat_core::HybridKeypair::generate();
|
||||||
let id_key = session.identity.public_key_bytes();
|
let id_key = session.identity.public_key_bytes();
|
||||||
upload_hybrid_key(client, &id_key, &new_kp.public_key()).await?;
|
upload_hybrid_key(client, &id_key, &new_kp.public_key()).await?;
|
||||||
session.hybrid_kp = Some(new_kp);
|
session.hybrid_kp = Some(new_kp);
|
||||||
@@ -1108,7 +1116,95 @@ pub(crate) async fn cmd_rotate_all_keys(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Discover nearby qpq servers via mDNS (requires `--features mesh` build).
|
/// Start the P2P node for mesh messaging.
|
||||||
|
pub(crate) async fn cmd_mesh_start(session: &mut SessionState) -> anyhow::Result<()> {
|
||||||
|
#[cfg(feature = "mesh")]
|
||||||
|
{
|
||||||
|
if session.p2p_node.is_some() {
|
||||||
|
display::print_status("P2P node is already running");
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
display::print_status("starting P2P node...");
|
||||||
|
|
||||||
|
// Try to load a persisted mesh identity or generate a new one.
|
||||||
|
let mesh_state_path = session.state_path.with_extension("mesh.json");
|
||||||
|
let mesh_id = if mesh_state_path.exists() {
|
||||||
|
match quicprochat_p2p::identity::MeshIdentity::load(&mesh_state_path) {
|
||||||
|
Ok(id) => {
|
||||||
|
display::print_status("loaded existing mesh identity");
|
||||||
|
Some(id)
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
display::print_status(&format!("could not load mesh identity: {e}, generating new"));
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
let node = if let Some(id) = mesh_id {
|
||||||
|
match quicprochat_p2p::P2pNode::start_with_mesh(None, id, 1000).await {
|
||||||
|
Ok(n) => n,
|
||||||
|
Err(e) => {
|
||||||
|
display::print_error(&format!("failed to start P2P node: {e}"));
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
match quicprochat_p2p::P2pNode::start(None).await {
|
||||||
|
Ok(n) => n,
|
||||||
|
Err(e) => {
|
||||||
|
display::print_error(&format!("failed to start P2P node: {e}"));
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let node_id = node.node_id();
|
||||||
|
session.p2p_node = Some(Arc::new(node));
|
||||||
|
display::print_status(&format!("P2P node started: {}", node_id.fmt_short()));
|
||||||
|
}
|
||||||
|
#[cfg(not(feature = "mesh"))]
|
||||||
|
{
|
||||||
|
let _ = session;
|
||||||
|
display::print_error("requires --features mesh");
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Stop the P2P node.
|
||||||
|
pub(crate) async fn cmd_mesh_stop(session: &mut SessionState) -> anyhow::Result<()> {
|
||||||
|
#[cfg(feature = "mesh")]
|
||||||
|
{
|
||||||
|
match session.p2p_node.take() {
|
||||||
|
Some(node) => {
|
||||||
|
// Try to unwrap the Arc; if there are other references, just drop our handle.
|
||||||
|
match Arc::try_unwrap(node) {
|
||||||
|
Ok(owned) => {
|
||||||
|
owned.close().await;
|
||||||
|
display::print_status("P2P node stopped");
|
||||||
|
}
|
||||||
|
Err(_arc) => {
|
||||||
|
display::print_status("P2P node reference released (other tasks may still hold it)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
display::print_status("P2P node is not running");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[cfg(not(feature = "mesh"))]
|
||||||
|
{
|
||||||
|
let _ = session;
|
||||||
|
display::print_error("requires --features mesh");
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Discover nearby qpc servers via mDNS (requires `--features mesh` build).
|
||||||
pub(crate) fn cmd_mesh_peers() -> anyhow::Result<()> {
|
pub(crate) fn cmd_mesh_peers() -> anyhow::Result<()> {
|
||||||
use super::mesh_discovery::MeshDiscovery;
|
use super::mesh_discovery::MeshDiscovery;
|
||||||
|
|
||||||
@@ -1118,65 +1214,117 @@ pub(crate) fn cmd_mesh_peers() -> anyhow::Result<()> {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
Ok(disc) => {
|
Ok(disc) => {
|
||||||
display::print_status("scanning for nearby qpq nodes (2s)...");
|
display::print_status("scanning for nearby qpc nodes (2s)...");
|
||||||
// Block briefly to collect mDNS announcements from the local network.
|
// Block briefly to collect mDNS announcements from the local network.
|
||||||
std::thread::sleep(std::time::Duration::from_secs(2));
|
std::thread::sleep(std::time::Duration::from_secs(2));
|
||||||
let peers = disc.peers();
|
let peers = disc.peers();
|
||||||
if peers.is_empty() {
|
if peers.is_empty() {
|
||||||
display::print_status("no qpq nodes found on the local network");
|
display::print_status("no qpc nodes found on the local network");
|
||||||
} else {
|
} else {
|
||||||
display::print_status(&format!("found {} node(s):", peers.len()));
|
display::print_status(&format!("found {} node(s):", peers.len()));
|
||||||
for p in &peers {
|
for p in &peers {
|
||||||
display::print_status(&format!(" {} at {}", p.domain, p.server_addr));
|
display::print_status(&format!(" {} at {}", p.domain, p.server_addr));
|
||||||
}
|
}
|
||||||
display::print_status("use: /mesh server <host:port> to note the address,");
|
display::print_status("use: /mesh server <host:port> to note the address,");
|
||||||
display::print_status("then reconnect with: qpq --server <host:port>");
|
display::print_status("then reconnect with: qpc --server <host:port>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send a direct P2P mesh message (stub — P2pNode not yet wired into session).
|
/// Send a direct P2P mesh message via the session's P2P node.
|
||||||
pub(crate) fn cmd_mesh_send(peer_id: &str, message: &str) -> anyhow::Result<()> {
|
pub(crate) async fn cmd_mesh_send(session: &SessionState, peer_id: &str, message: &str) -> anyhow::Result<()> {
|
||||||
#[cfg(feature = "mesh")]
|
#[cfg(feature = "mesh")]
|
||||||
{
|
{
|
||||||
display::print_status(&format!("mesh send: would send to {peer_id}: {message}"));
|
match &session.p2p_node {
|
||||||
display::print_status("(P2P node integration pending — message not actually sent)");
|
Some(node) => {
|
||||||
|
// Parse the peer_id as an iroh PublicKey hex string and create an EndpointAddr.
|
||||||
|
let pk_bytes = hex::decode(peer_id)
|
||||||
|
.map_err(|e| anyhow::anyhow!("invalid peer_id hex: {e}"))?;
|
||||||
|
let pk_array: [u8; 32] = pk_bytes
|
||||||
|
.as_slice()
|
||||||
|
.try_into()
|
||||||
|
.map_err(|_| anyhow::anyhow!("peer_id must be 32 bytes (64 hex chars)"))?;
|
||||||
|
let pk = iroh::PublicKey::from_bytes(&pk_array);
|
||||||
|
let addr = iroh::EndpointAddr::from(pk);
|
||||||
|
|
||||||
|
match node.send(addr, message.as_bytes()).await {
|
||||||
|
Ok(()) => {
|
||||||
|
display::print_status(&format!("sent to {}: {message}", &peer_id[..8.min(peer_id.len())]));
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
display::print_error(&format!("P2P send failed: {e}"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
display::print_error("P2P node not started. Use /mesh start to initialize.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "mesh"))]
|
#[cfg(not(feature = "mesh"))]
|
||||||
{
|
{
|
||||||
let _ = (peer_id, message);
|
let _ = (session, peer_id, message);
|
||||||
display::print_error("requires --features mesh");
|
display::print_error("requires --features mesh");
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Broadcast an encrypted message on a topic (stub — P2pNode not yet wired into session).
|
/// Broadcast an encrypted message on a topic via the session's P2P node.
|
||||||
pub(crate) fn cmd_mesh_broadcast(topic: &str, message: &str) -> anyhow::Result<()> {
|
pub(crate) async fn cmd_mesh_broadcast(session: &SessionState, topic: &str, message: &str) -> anyhow::Result<()> {
|
||||||
#[cfg(feature = "mesh")]
|
#[cfg(feature = "mesh")]
|
||||||
{
|
{
|
||||||
display::print_status(&format!("mesh broadcast to {topic}: {message}"));
|
match &session.p2p_node {
|
||||||
display::print_status("(P2P node integration pending — message not actually sent)");
|
Some(node) => {
|
||||||
|
match node.broadcast(topic, message.as_bytes()).await {
|
||||||
|
Ok(()) => {
|
||||||
|
display::print_status(&format!("broadcast to {topic}: {message}"));
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
display::print_error(&format!("broadcast failed: {e}"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
display::print_error("P2P node not started. Use /mesh start to initialize.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "mesh"))]
|
#[cfg(not(feature = "mesh"))]
|
||||||
{
|
{
|
||||||
let _ = (topic, message);
|
let _ = (session, topic, message);
|
||||||
display::print_error("requires --features mesh");
|
display::print_error("requires --features mesh");
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Subscribe to a broadcast topic (stub — P2pNode not yet wired into session).
|
/// Subscribe to a broadcast topic on the session's P2P node.
|
||||||
pub(crate) fn cmd_mesh_subscribe(topic: &str) -> anyhow::Result<()> {
|
pub(crate) fn cmd_mesh_subscribe(session: &SessionState, topic: &str) -> anyhow::Result<()> {
|
||||||
#[cfg(feature = "mesh")]
|
#[cfg(feature = "mesh")]
|
||||||
{
|
{
|
||||||
display::print_status(&format!("subscribed to topic: {topic}"));
|
match &session.p2p_node {
|
||||||
display::print_status("(P2P node integration pending — subscription is not persisted)");
|
Some(node) => {
|
||||||
|
// Generate a random key for the subscription.
|
||||||
|
let key: [u8; 32] = rand::random();
|
||||||
|
match node.subscribe(topic, key) {
|
||||||
|
Ok(()) => {
|
||||||
|
display::print_status(&format!("subscribed to topic: {topic}"));
|
||||||
|
display::print_status(&format!("share this key to let others join: {}", hex::encode(key)));
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
display::print_error(&format!("subscribe failed: {e}"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
display::print_error("P2P node not started. Use /mesh start to initialize.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "mesh"))]
|
#[cfg(not(feature = "mesh"))]
|
||||||
{
|
{
|
||||||
let _ = topic;
|
let _ = (session, topic);
|
||||||
display::print_error("requires --features mesh");
|
display::print_error("requires --features mesh");
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -1188,7 +1336,7 @@ pub(crate) fn cmd_mesh_route(session: &SessionState) -> anyhow::Result<()> {
|
|||||||
{
|
{
|
||||||
let mesh_state_path = session.state_path.with_extension("mesh.json");
|
let mesh_state_path = session.state_path.with_extension("mesh.json");
|
||||||
if mesh_state_path.exists() {
|
if mesh_state_path.exists() {
|
||||||
let id = quicproquo_p2p::identity::MeshIdentity::load(&mesh_state_path)?;
|
let id = quicprochat_p2p::identity::MeshIdentity::load(&mesh_state_path)?;
|
||||||
let peers = id.known_peers();
|
let peers = id.known_peers();
|
||||||
if peers.is_empty() {
|
if peers.is_empty() {
|
||||||
display::print_status("no known mesh peers");
|
display::print_status("no known mesh peers");
|
||||||
@@ -1222,7 +1370,7 @@ pub(crate) fn cmd_mesh_identity(session: &SessionState) -> anyhow::Result<()> {
|
|||||||
{
|
{
|
||||||
let mesh_state_path = session.state_path.with_extension("mesh.json");
|
let mesh_state_path = session.state_path.with_extension("mesh.json");
|
||||||
if mesh_state_path.exists() {
|
if mesh_state_path.exists() {
|
||||||
let id = quicproquo_p2p::identity::MeshIdentity::load(&mesh_state_path)?;
|
let id = quicprochat_p2p::identity::MeshIdentity::load(&mesh_state_path)?;
|
||||||
display::print_status(&format!("mesh public key: {}", hex::encode(id.public_key())));
|
display::print_status(&format!("mesh public key: {}", hex::encode(id.public_key())));
|
||||||
display::print_status(&format!("known peers: {}", id.known_peers().len()));
|
display::print_status(&format!("known peers: {}", id.known_peers().len()));
|
||||||
} else {
|
} else {
|
||||||
@@ -1449,10 +1597,8 @@ pub(crate) async fn cmd_dm(
|
|||||||
},
|
},
|
||||||
display_name: format!("@{username}"),
|
display_name: format!("@{username}"),
|
||||||
mls_group_blob: member
|
mls_group_blob: member
|
||||||
.group_ref()
|
.serialize_mls_state()
|
||||||
.map(bincode::serialize)
|
.context("serialize MLS state")?,
|
||||||
.transpose()
|
|
||||||
.context("serialize group")?,
|
|
||||||
keystore_blob: None,
|
keystore_blob: None,
|
||||||
member_keys,
|
member_keys,
|
||||||
unread_count: 0,
|
unread_count: 0,
|
||||||
@@ -1493,10 +1639,8 @@ pub(crate) fn cmd_create_group(session: &mut SessionState, name: &str) -> anyhow
|
|||||||
kind: ConversationKind::Group { name: name.to_string() },
|
kind: ConversationKind::Group { name: name.to_string() },
|
||||||
display_name: format!("#{name}"),
|
display_name: format!("#{name}"),
|
||||||
mls_group_blob: member
|
mls_group_blob: member
|
||||||
.group_ref()
|
.serialize_mls_state()
|
||||||
.map(bincode::serialize)
|
.context("serialize MLS state")?,
|
||||||
.transpose()
|
|
||||||
.context("serialize group")?,
|
|
||||||
keystore_blob: None,
|
keystore_blob: None,
|
||||||
member_keys,
|
member_keys,
|
||||||
unread_count: 0,
|
unread_count: 0,
|
||||||
@@ -1780,9 +1924,7 @@ pub(crate) async fn cmd_join(
|
|||||||
kind: ConversationKind::Group { name: display.clone() },
|
kind: ConversationKind::Group { name: display.clone() },
|
||||||
display_name: format!("#{display}"),
|
display_name: format!("#{display}"),
|
||||||
mls_group_blob: new_member
|
mls_group_blob: new_member
|
||||||
.group_ref()
|
.serialize_mls_state()
|
||||||
.map(bincode::serialize)
|
|
||||||
.transpose()
|
|
||||||
.context("serialize joined group")?,
|
.context("serialize joined group")?,
|
||||||
keystore_blob: None,
|
keystore_blob: None,
|
||||||
member_keys,
|
member_keys,
|
||||||
@@ -2005,8 +2147,8 @@ pub(crate) async fn cmd_typing(
|
|||||||
);
|
);
|
||||||
|
|
||||||
let app_payload = serialize_typing(1);
|
let app_payload = serialize_typing(1);
|
||||||
let sealed = quicproquo_core::sealed_sender::seal(&identity, &app_payload);
|
let sealed = quicprochat_core::sealed_sender::seal(&identity, &app_payload);
|
||||||
let padded = quicproquo_core::padding::pad(&sealed);
|
let padded = quicprochat_core::padding::pad(&sealed);
|
||||||
|
|
||||||
let ct = member
|
let ct = member
|
||||||
.send_message(&padded)
|
.send_message(&padded)
|
||||||
@@ -2082,8 +2224,8 @@ pub(crate) async fn cmd_react(
|
|||||||
let app_payload = serialize_reaction(ref_msg_id, emoji.as_bytes())
|
let app_payload = serialize_reaction(ref_msg_id, emoji.as_bytes())
|
||||||
.context("serialize reaction")?;
|
.context("serialize reaction")?;
|
||||||
|
|
||||||
let sealed = quicproquo_core::sealed_sender::seal(&identity, &app_payload);
|
let sealed = quicprochat_core::sealed_sender::seal(&identity, &app_payload);
|
||||||
let padded = quicproquo_core::padding::pad(&sealed);
|
let padded = quicprochat_core::padding::pad(&sealed);
|
||||||
|
|
||||||
let ct = member
|
let ct = member
|
||||||
.send_message(&padded)
|
.send_message(&padded)
|
||||||
@@ -2167,8 +2309,8 @@ pub(crate) async fn cmd_edit(
|
|||||||
|
|
||||||
let app_payload = serialize_edit(&msg_id, new_text.as_bytes())
|
let app_payload = serialize_edit(&msg_id, new_text.as_bytes())
|
||||||
.context("serialize edit message")?;
|
.context("serialize edit message")?;
|
||||||
let sealed = quicproquo_core::sealed_sender::seal(&identity, &app_payload);
|
let sealed = quicprochat_core::sealed_sender::seal(&identity, &app_payload);
|
||||||
let padded = quicproquo_core::padding::pad(&sealed);
|
let padded = quicprochat_core::padding::pad(&sealed);
|
||||||
|
|
||||||
let ct = member
|
let ct = member
|
||||||
.send_message(&padded)
|
.send_message(&padded)
|
||||||
@@ -2238,8 +2380,8 @@ pub(crate) async fn cmd_delete(
|
|||||||
);
|
);
|
||||||
|
|
||||||
let app_payload = serialize_delete(&msg_id);
|
let app_payload = serialize_delete(&msg_id);
|
||||||
let sealed = quicproquo_core::sealed_sender::seal(&identity, &app_payload);
|
let sealed = quicprochat_core::sealed_sender::seal(&identity, &app_payload);
|
||||||
let padded = quicproquo_core::padding::pad(&sealed);
|
let padded = quicprochat_core::padding::pad(&sealed);
|
||||||
|
|
||||||
let ct = member
|
let ct = member
|
||||||
.send_message(&padded)
|
.send_message(&padded)
|
||||||
@@ -2394,8 +2536,8 @@ pub(crate) async fn cmd_send_file(
|
|||||||
"cannot send files in a local-only conversation"
|
"cannot send files in a local-only conversation"
|
||||||
);
|
);
|
||||||
|
|
||||||
let sealed = quicproquo_core::sealed_sender::seal(&identity, &app_payload);
|
let sealed = quicprochat_core::sealed_sender::seal(&identity, &app_payload);
|
||||||
let padded = quicproquo_core::padding::pad(&sealed);
|
let padded = quicprochat_core::padding::pad(&sealed);
|
||||||
|
|
||||||
let ct = member
|
let ct = member
|
||||||
.send_message(&padded)
|
.send_message(&padded)
|
||||||
@@ -2672,8 +2814,8 @@ pub(crate) async fn do_send(
|
|||||||
.context("serialize app message")?;
|
.context("serialize app message")?;
|
||||||
|
|
||||||
// Metadata protection: seal sender identity inside payload + pad to bucket size.
|
// Metadata protection: seal sender identity inside payload + pad to bucket size.
|
||||||
let sealed = quicproquo_core::sealed_sender::seal(&identity, &app_payload);
|
let sealed = quicprochat_core::sealed_sender::seal(&identity, &app_payload);
|
||||||
let padded = quicproquo_core::padding::pad(&sealed);
|
let padded = quicprochat_core::padding::pad(&sealed);
|
||||||
|
|
||||||
let ct = member
|
let ct = member
|
||||||
.send_message(&padded)
|
.send_message(&padded)
|
||||||
@@ -2762,8 +2904,8 @@ async fn send_dummy_message(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let dummy_payload = serialize_dummy();
|
let dummy_payload = serialize_dummy();
|
||||||
let sealed = quicproquo_core::sealed_sender::seal(&identity, &dummy_payload);
|
let sealed = quicprochat_core::sealed_sender::seal(&identity, &dummy_payload);
|
||||||
let padded = quicproquo_core::padding::pad(&sealed);
|
let padded = quicprochat_core::padding::pad(&sealed);
|
||||||
|
|
||||||
let ct = match member.send_message(&padded) {
|
let ct = match member.send_message(&padded) {
|
||||||
Ok(ct) => ct,
|
Ok(ct) => ct,
|
||||||
@@ -2845,12 +2987,12 @@ async fn poll_messages(
|
|||||||
// Falls back gracefully for messages from older clients.
|
// Falls back gracefully for messages from older clients.
|
||||||
let (sender_key, app_bytes) = {
|
let (sender_key, app_bytes) = {
|
||||||
// Step 1: try unpad
|
// Step 1: try unpad
|
||||||
let after_unpad = quicproquo_core::padding::unpad(&plaintext)
|
let after_unpad = quicprochat_core::padding::unpad(&plaintext)
|
||||||
.unwrap_or_else(|_| plaintext.clone());
|
.unwrap_or_else(|_| plaintext.clone());
|
||||||
|
|
||||||
// Step 2: try unseal
|
// Step 2: try unseal
|
||||||
if quicproquo_core::sealed_sender::is_sealed(&after_unpad) {
|
if quicprochat_core::sealed_sender::is_sealed(&after_unpad) {
|
||||||
match quicproquo_core::sealed_sender::unseal(&after_unpad) {
|
match quicprochat_core::sealed_sender::unseal(&after_unpad) {
|
||||||
Ok((sk, inner)) => (sk.to_vec(), inner),
|
Ok((sk, inner)) => (sk.to_vec(), inner),
|
||||||
Err(_) => (my_key.clone(), after_unpad),
|
Err(_) => (my_key.clone(), after_unpad),
|
||||||
}
|
}
|
||||||
@@ -3048,8 +3190,8 @@ async fn poll_messages(
|
|||||||
if let Some(mid) = msg_id {
|
if let Some(mid) = msg_id {
|
||||||
let receipt_bytes = serialize_read_receipt(mid);
|
let receipt_bytes = serialize_read_receipt(mid);
|
||||||
let identity = Arc::clone(&session.identity);
|
let identity = Arc::clone(&session.identity);
|
||||||
let sealed = quicproquo_core::sealed_sender::seal(&identity, &receipt_bytes);
|
let sealed = quicprochat_core::sealed_sender::seal(&identity, &receipt_bytes);
|
||||||
let padded = quicproquo_core::padding::pad(&sealed);
|
let padded = quicprochat_core::padding::pad(&sealed);
|
||||||
if let Some(m) = session.members.get_mut(conv_id) {
|
if let Some(m) = session.members.get_mut(conv_id) {
|
||||||
if let Ok(ct) = m.send_message(&padded) {
|
if let Ok(ct) = m.send_message(&padded) {
|
||||||
let _ = enqueue(client, &sender_key, &ct).await;
|
let _ = enqueue(client, &sender_key, &ct).await;
|
||||||
@@ -3186,8 +3328,9 @@ async fn try_auto_join(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mls_blob = member
|
let mls_blob = member
|
||||||
.group_ref()
|
.serialize_mls_state()
|
||||||
.and_then(|g| bincode::serialize(g).ok());
|
.ok()
|
||||||
|
.flatten();
|
||||||
|
|
||||||
let conv = Conversation {
|
let conv = Conversation {
|
||||||
id: conv_id.clone(),
|
id: conv_id.clone(),
|
||||||
@@ -10,8 +10,8 @@ use rustls::{ClientConfig as RustlsClientConfig, RootCertStore};
|
|||||||
use tokio_util::compat::{TokioAsyncReadCompatExt, TokioAsyncWriteCompatExt};
|
use tokio_util::compat::{TokioAsyncReadCompatExt, TokioAsyncWriteCompatExt};
|
||||||
use capnp_rpc::{rpc_twoparty_capnp::Side, twoparty, RpcSystem};
|
use capnp_rpc::{rpc_twoparty_capnp::Side, twoparty, RpcSystem};
|
||||||
|
|
||||||
use quicproquo_core::HybridPublicKey;
|
use quicprochat_core::HybridPublicKey;
|
||||||
use quicproquo_proto::node_capnp::{auth, node_service};
|
use quicprochat_proto::node_capnp::{auth, node_service};
|
||||||
|
|
||||||
use crate::{AUTH_CONTEXT, INSECURE_SKIP_VERIFY};
|
use crate::{AUTH_CONTEXT, INSECURE_SKIP_VERIFY};
|
||||||
|
|
||||||
@@ -440,11 +440,11 @@ pub async fn fetch_hybrid_key(
|
|||||||
|
|
||||||
/// Decrypt a hybrid envelope. Requires a hybrid key; no fallback to plaintext MLS.
|
/// Decrypt a hybrid envelope. Requires a hybrid key; no fallback to plaintext MLS.
|
||||||
pub fn try_hybrid_decrypt(
|
pub fn try_hybrid_decrypt(
|
||||||
hybrid_kp: Option<&quicproquo_core::HybridKeypair>,
|
hybrid_kp: Option<&quicprochat_core::HybridKeypair>,
|
||||||
payload: &[u8],
|
payload: &[u8],
|
||||||
) -> anyhow::Result<Vec<u8>> {
|
) -> anyhow::Result<Vec<u8>> {
|
||||||
let kp = hybrid_kp.ok_or_else(|| anyhow::anyhow!("hybrid key required for decryption"))?;
|
let kp = hybrid_kp.ok_or_else(|| anyhow::anyhow!("hybrid key required for decryption"))?;
|
||||||
quicproquo_core::hybrid_decrypt(kp, payload, b"", b"").map_err(|e| anyhow::anyhow!("{e}"))
|
quicprochat_core::hybrid_decrypt(kp, payload, b"", b"").map_err(|e| anyhow::anyhow!("{e}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Peek at queued payloads without removing them.
|
/// Peek at queued payloads without removing them.
|
||||||
@@ -701,9 +701,9 @@ pub async fn resolve_user(
|
|||||||
.to_vec();
|
.to_vec();
|
||||||
|
|
||||||
if !proof_bytes.is_empty() {
|
if !proof_bytes.is_empty() {
|
||||||
let proof = quicproquo_kt::InclusionProof::from_bytes(&proof_bytes)
|
let proof = quicprochat_kt::InclusionProof::from_bytes(&proof_bytes)
|
||||||
.context("resolve_user: inclusion proof deserialise failed")?;
|
.context("resolve_user: inclusion proof deserialise failed")?;
|
||||||
quicproquo_kt::verify_inclusion(&proof, username, &key)
|
quicprochat_kt::verify_inclusion(&proof, username, &key)
|
||||||
.context("resolve_user: KT inclusion proof verification FAILED — possible key mislabelling")?;
|
.context("resolve_user: KT inclusion proof verification FAILED — possible key mislabelling")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11,12 +11,12 @@ use std::time::Instant;
|
|||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use zeroize::Zeroizing;
|
use zeroize::Zeroizing;
|
||||||
|
|
||||||
use quicproquo_core::{DiskKeyStore, GroupMember, HybridKeypair, IdentityKeypair};
|
use quicprochat_core::{DiskKeyStore, GroupMember, HybridKeypair, IdentityKeypair};
|
||||||
|
|
||||||
use super::conversation::{
|
use super::conversation::{
|
||||||
now_ms, Conversation, ConversationId, ConversationKind, ConversationStore,
|
now_ms, Conversation, ConversationId, ConversationKind, ConversationStore,
|
||||||
};
|
};
|
||||||
use super::state::{load_or_init_state, keystore_path};
|
use super::state::load_or_init_state;
|
||||||
|
|
||||||
/// Runtime state for an interactive REPL session.
|
/// Runtime state for an interactive REPL session.
|
||||||
pub struct SessionState {
|
pub struct SessionState {
|
||||||
@@ -53,6 +53,9 @@ pub struct SessionState {
|
|||||||
pub padding_enabled: bool,
|
pub padding_enabled: bool,
|
||||||
/// Last epoch at which we sent a message (for /verify-fs).
|
/// Last epoch at which we sent a message (for /verify-fs).
|
||||||
pub last_send_epoch: Option<u64>,
|
pub last_send_epoch: Option<u64>,
|
||||||
|
/// P2P node for direct mesh messaging (requires `--features mesh`).
|
||||||
|
#[cfg(feature = "mesh")]
|
||||||
|
pub p2p_node: Option<Arc<quicprochat_p2p::P2pNode>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SessionState {
|
impl SessionState {
|
||||||
@@ -93,6 +96,8 @@ impl SessionState {
|
|||||||
auto_clear_secs: None,
|
auto_clear_secs: None,
|
||||||
padding_enabled: false,
|
padding_enabled: false,
|
||||||
last_send_epoch: None,
|
last_send_epoch: None,
|
||||||
|
#[cfg(feature = "mesh")]
|
||||||
|
p2p_node: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Migrate legacy single-group into conversations if present and not yet migrated.
|
// Migrate legacy single-group into conversations if present and not yet migrated.
|
||||||
@@ -109,7 +114,7 @@ impl SessionState {
|
|||||||
/// Migrate the legacy single-group from StoredState into the conversation DB.
|
/// Migrate the legacy single-group from StoredState into the conversation DB.
|
||||||
fn migrate_legacy_group(
|
fn migrate_legacy_group(
|
||||||
&mut self,
|
&mut self,
|
||||||
state_path: &Path,
|
_state_path: &Path,
|
||||||
group_blob: &Option<Vec<u8>>,
|
group_blob: &Option<Vec<u8>>,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let blob = match group_blob {
|
let blob = match group_blob {
|
||||||
@@ -117,16 +122,22 @@ impl SessionState {
|
|||||||
None => return Ok(()),
|
None => return Ok(()),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Reconstruct GroupMember using the legacy keystore and group blob.
|
// Legacy group blobs used openmls 0.5 serde format. After the 0.8
|
||||||
let ks_path = keystore_path(state_path);
|
// upgrade the blob format changed to storage-provider state. Attempt
|
||||||
let ks = DiskKeyStore::persistent(&ks_path)?;
|
// to load from the new format; if that fails, skip the legacy group.
|
||||||
let group = bincode::deserialize(blob).context("decode legacy group")?;
|
let group_id_guess = &blob[..blob.len().min(16)];
|
||||||
let member = GroupMember::new_with_state(
|
let member = match GroupMember::new_from_storage_bytes(
|
||||||
Arc::clone(&self.identity),
|
Arc::clone(&self.identity),
|
||||||
ks,
|
blob,
|
||||||
Some(group),
|
group_id_guess,
|
||||||
false, // legacy groups are classical
|
false, // legacy groups are classical
|
||||||
);
|
) {
|
||||||
|
Ok(m) => m,
|
||||||
|
Err(e) => {
|
||||||
|
tracing::warn!(error = %e, "skipping incompatible legacy group blob (openmls version mismatch)");
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let group_id_bytes = member.group_id().unwrap_or_default();
|
let group_id_bytes = member.group_id().unwrap_or_default();
|
||||||
|
|
||||||
@@ -182,26 +193,31 @@ impl SessionState {
|
|||||||
|
|
||||||
/// Create a GroupMember from a stored conversation.
|
/// Create a GroupMember from a stored conversation.
|
||||||
fn create_member_from_conv(&self, conv: &Conversation) -> anyhow::Result<GroupMember> {
|
fn create_member_from_conv(&self, conv: &Conversation) -> anyhow::Result<GroupMember> {
|
||||||
let ks_path = self.keystore_path_for(&conv.id);
|
if let Some(blob) = conv.mls_group_blob.as_ref() {
|
||||||
let ks = DiskKeyStore::persistent(&ks_path)
|
let group_id = conv.id.0.as_slice();
|
||||||
.unwrap_or_else(|e| {
|
let member = GroupMember::new_from_storage_bytes(
|
||||||
tracing::warn!(path = %ks_path.display(), error = %e, "DiskKeyStore open failed, falling back to ephemeral");
|
Arc::clone(&self.identity),
|
||||||
DiskKeyStore::ephemeral()
|
blob,
|
||||||
});
|
group_id,
|
||||||
|
conv.is_hybrid,
|
||||||
let group = conv
|
)
|
||||||
.mls_group_blob
|
.context("restore MLS state from conversation db")?;
|
||||||
.as_ref()
|
Ok(member)
|
||||||
.map(|b| bincode::deserialize(b))
|
} else {
|
||||||
.transpose()
|
// No MLS state — create an empty member.
|
||||||
.context("decode MLS group from conversation db")?;
|
let ks_path = self.keystore_path_for(&conv.id);
|
||||||
|
let ks = DiskKeyStore::persistent(&ks_path)
|
||||||
Ok(GroupMember::new_with_state(
|
.unwrap_or_else(|e| {
|
||||||
Arc::clone(&self.identity),
|
tracing::warn!(path = %ks_path.display(), error = %e, "DiskKeyStore open failed, falling back to ephemeral");
|
||||||
ks,
|
DiskKeyStore::ephemeral()
|
||||||
group,
|
});
|
||||||
conv.is_hybrid,
|
Ok(GroupMember::new_with_state(
|
||||||
))
|
Arc::clone(&self.identity),
|
||||||
|
ks,
|
||||||
|
None,
|
||||||
|
conv.is_hybrid,
|
||||||
|
))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Path for a per-conversation keystore file.
|
/// Path for a per-conversation keystore file.
|
||||||
@@ -214,10 +230,8 @@ impl SessionState {
|
|||||||
pub fn save_member(&self, conv_id: &ConversationId) -> anyhow::Result<()> {
|
pub fn save_member(&self, conv_id: &ConversationId) -> anyhow::Result<()> {
|
||||||
let member = self.members.get(conv_id).context("no such conversation")?;
|
let member = self.members.get(conv_id).context("no such conversation")?;
|
||||||
let blob = member
|
let blob = member
|
||||||
.group_ref()
|
.serialize_mls_state()
|
||||||
.map(bincode::serialize)
|
.context("serialize MLS state")?;
|
||||||
.transpose()
|
|
||||||
.context("serialize MLS group")?;
|
|
||||||
|
|
||||||
let member_keys = member.member_identities();
|
let member_keys = member.member_identities();
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ use chacha20poly1305::{
|
|||||||
use rand::RngCore;
|
use rand::RngCore;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use quicproquo_core::{DiskKeyStore, GroupMember, HybridKeypair, HybridKeypairBytes, IdentityKeypair};
|
use quicprochat_core::{DiskKeyStore, GroupMember, HybridKeypair, HybridKeypairBytes, IdentityKeypair};
|
||||||
|
|
||||||
/// Magic bytes for encrypted client state files.
|
/// Magic bytes for encrypted client state files.
|
||||||
const STATE_MAGIC: &[u8; 4] = b"QPCE";
|
const STATE_MAGIC: &[u8; 4] = b"QPCE";
|
||||||
@@ -27,18 +27,31 @@ pub struct StoredState {
|
|||||||
/// Cached member public keys for group participants.
|
/// Cached member public keys for group participants.
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub member_keys: Vec<Vec<u8>>,
|
pub member_keys: Vec<Vec<u8>>,
|
||||||
|
/// MLS group ID bytes, needed to reload the group from StorageProvider state.
|
||||||
|
#[serde(default)]
|
||||||
|
pub group_id: Option<Vec<u8>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StoredState {
|
impl StoredState {
|
||||||
pub fn into_parts(self, state_path: &Path) -> anyhow::Result<(GroupMember, Option<HybridKeypair>)> {
|
pub fn into_parts(self, state_path: &Path) -> anyhow::Result<(GroupMember, Option<HybridKeypair>)> {
|
||||||
let identity = Arc::new(IdentityKeypair::from_seed(self.identity_seed));
|
let identity = Arc::new(IdentityKeypair::from_seed(self.identity_seed));
|
||||||
let group = self
|
|
||||||
.group
|
|
||||||
.map(|bytes| bincode::deserialize(&bytes).context("decode group"))
|
|
||||||
.transpose()?;
|
|
||||||
let key_store = DiskKeyStore::persistent(keystore_path(state_path))?;
|
|
||||||
let hybrid = self.hybrid_key.is_some();
|
let hybrid = self.hybrid_key.is_some();
|
||||||
let member = GroupMember::new_with_state(identity, key_store, group, hybrid);
|
|
||||||
|
let member = match (self.group.as_ref(), self.group_id.as_ref()) {
|
||||||
|
(Some(storage_bytes), Some(gid)) => {
|
||||||
|
GroupMember::new_from_storage_bytes(
|
||||||
|
identity,
|
||||||
|
storage_bytes,
|
||||||
|
gid,
|
||||||
|
hybrid,
|
||||||
|
)
|
||||||
|
.context("restore MLS state from stored state")?
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
let key_store = DiskKeyStore::persistent(keystore_path(state_path))?;
|
||||||
|
GroupMember::new_with_state(identity, key_store, None, hybrid)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let hybrid_kp = self
|
let hybrid_kp = self
|
||||||
.hybrid_key
|
.hybrid_key
|
||||||
@@ -50,15 +63,15 @@ impl StoredState {
|
|||||||
|
|
||||||
pub fn from_parts(member: &GroupMember, hybrid_kp: Option<&HybridKeypair>) -> anyhow::Result<Self> {
|
pub fn from_parts(member: &GroupMember, hybrid_kp: Option<&HybridKeypair>) -> anyhow::Result<Self> {
|
||||||
let group = member
|
let group = member
|
||||||
.group_ref()
|
.serialize_mls_state()
|
||||||
.map(|g| bincode::serialize(g).context("serialize group"))
|
.context("serialize MLS state")?;
|
||||||
.transpose()?;
|
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
identity_seed: *member.identity_seed(),
|
identity_seed: *member.identity_seed(),
|
||||||
group,
|
group,
|
||||||
hybrid_key: hybrid_kp.map(|kp| kp.to_bytes()),
|
hybrid_key: hybrid_kp.map(|kp| kp.to_bytes()),
|
||||||
member_keys: Vec::new(),
|
member_keys: Vec::new(),
|
||||||
|
group_id: member.group_id(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -245,6 +258,7 @@ mod tests {
|
|||||||
hybrid_key: None,
|
hybrid_key: None,
|
||||||
group: None,
|
group: None,
|
||||||
member_keys: Vec::new(),
|
member_keys: Vec::new(),
|
||||||
|
group_id: None,
|
||||||
};
|
};
|
||||||
let password = "test-password";
|
let password = "test-password";
|
||||||
let plaintext = bincode::serialize(&state).unwrap();
|
let plaintext = bincode::serialize(&state).unwrap();
|
||||||
@@ -268,6 +282,7 @@ mod tests {
|
|||||||
}),
|
}),
|
||||||
group: None,
|
group: None,
|
||||||
member_keys: Vec::new(),
|
member_keys: Vec::new(),
|
||||||
|
group_id: None,
|
||||||
};
|
};
|
||||||
let password = "another-password";
|
let password = "another-password";
|
||||||
let plaintext = bincode::serialize(&state).unwrap();
|
let plaintext = bincode::serialize(&state).unwrap();
|
||||||
@@ -285,6 +300,7 @@ mod tests {
|
|||||||
hybrid_key: None,
|
hybrid_key: None,
|
||||||
group: None,
|
group: None,
|
||||||
member_keys: Vec::new(),
|
member_keys: Vec::new(),
|
||||||
|
group_id: None,
|
||||||
};
|
};
|
||||||
let plaintext = bincode::serialize(&state).unwrap();
|
let plaintext = bincode::serialize(&state).unwrap();
|
||||||
let encrypted = encrypt_state("correct", &plaintext).unwrap();
|
let encrypted = encrypt_state("correct", &plaintext).unwrap();
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
//! Full-screen Ratatui TUI for quicproquo.
|
//! Full-screen Ratatui TUI for quicprochat.
|
||||||
//!
|
//!
|
||||||
//! Layout:
|
//! Layout:
|
||||||
//! ┌──────────────┬──────────────────────────────────────────┐
|
//! ┌──────────────┬──────────────────────────────────────────┐
|
||||||
@@ -48,11 +48,11 @@ use super::session::SessionState;
|
|||||||
use super::state::load_or_init_state;
|
use super::state::load_or_init_state;
|
||||||
use super::token_cache::{load_cached_session, save_cached_session};
|
use super::token_cache::{load_cached_session, save_cached_session};
|
||||||
|
|
||||||
use quicproquo_core::{
|
use quicprochat_core::{
|
||||||
AppMessage, DiskKeyStore, GroupMember, IdentityKeypair, ReceivedMessage,
|
AppMessage, DiskKeyStore, GroupMember, IdentityKeypair, ReceivedMessage,
|
||||||
hybrid_encrypt, parse as parse_app_msg, serialize_chat,
|
hybrid_encrypt, parse as parse_app_msg, serialize_chat,
|
||||||
};
|
};
|
||||||
use quicproquo_proto::node_capnp::node_service;
|
use quicprochat_proto::node_capnp::node_service;
|
||||||
|
|
||||||
// ── App events ───────────────────────────────────────────────────────────────
|
// ── App events ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
@@ -393,11 +393,11 @@ async fn poll_task(
|
|||||||
match member.receive_message(&mls_payload) {
|
match member.receive_message(&mls_payload) {
|
||||||
Ok(ReceivedMessage::Application(plaintext)) => {
|
Ok(ReceivedMessage::Application(plaintext)) => {
|
||||||
let (sender_key, app_bytes) = {
|
let (sender_key, app_bytes) = {
|
||||||
let after_unpad = quicproquo_core::padding::unpad(&plaintext)
|
let after_unpad = quicprochat_core::padding::unpad(&plaintext)
|
||||||
.unwrap_or_else(|_| plaintext.clone());
|
.unwrap_or_else(|_| plaintext.clone());
|
||||||
|
|
||||||
if quicproquo_core::sealed_sender::is_sealed(&after_unpad) {
|
if quicprochat_core::sealed_sender::is_sealed(&after_unpad) {
|
||||||
match quicproquo_core::sealed_sender::unseal(&after_unpad) {
|
match quicprochat_core::sealed_sender::unseal(&after_unpad) {
|
||||||
Ok((sk, inner)) => (sk.to_vec(), inner),
|
Ok((sk, inner)) => (sk.to_vec(), inner),
|
||||||
Err(_) => (my_key.clone(), after_unpad),
|
Err(_) => (my_key.clone(), after_unpad),
|
||||||
}
|
}
|
||||||
@@ -493,8 +493,8 @@ async fn send_message(
|
|||||||
.context("serialize app message")?;
|
.context("serialize app message")?;
|
||||||
|
|
||||||
// Metadata protection: seal + pad.
|
// Metadata protection: seal + pad.
|
||||||
let sealed = quicproquo_core::sealed_sender::seal(&identity, &app_payload);
|
let sealed = quicprochat_core::sealed_sender::seal(&identity, &app_payload);
|
||||||
let padded = quicproquo_core::padding::pad(&sealed);
|
let padded = quicprochat_core::padding::pad(&sealed);
|
||||||
|
|
||||||
let ct = member.send_message(&padded).context("MLS encrypt")?;
|
let ct = member.send_message(&padded).context("MLS encrypt")?;
|
||||||
|
|
||||||
@@ -543,7 +543,7 @@ async fn send_message(
|
|||||||
|
|
||||||
// ── TUI entry point ───────────────────────────────────────────────────────────
|
// ── TUI entry point ───────────────────────────────────────────────────────────
|
||||||
|
|
||||||
/// Entry point for `qpq tui`. Sets up the terminal, runs the event loop, and
|
/// Entry point for `qpc tui`. Sets up the terminal, runs the event loop, and
|
||||||
/// restores the terminal on exit.
|
/// restores the terminal on exit.
|
||||||
pub async fn run_tui(
|
pub async fn run_tui(
|
||||||
state_path: &Path,
|
state_path: &Path,
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
//! v2 REPL — thin shell over `quicproquo_sdk::QpqClient`.
|
//! v2 REPL — thin shell over `quicprochat_sdk::QpqClient`.
|
||||||
//!
|
//!
|
||||||
//! Provides an interactive command-line interface with categorized `/help`,
|
//! Provides an interactive command-line interface with categorized `/help`,
|
||||||
//! tab-completion, and a background event listener. Delegates all crypto,
|
//! tab-completion, and a background event listener. Delegates all crypto,
|
||||||
//! MLS, and RPC work to the SDK.
|
//! MLS, and RPC work to the SDK.
|
||||||
//!
|
//!
|
||||||
//! Build: `cargo build -p quicproquo-client --features v2`
|
//! Build: `cargo build -p quicprochat-client --features v2`
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::{Child, Command as ProcessCommand};
|
use std::process::{Child, Command as ProcessCommand};
|
||||||
@@ -12,10 +12,10 @@ use std::sync::Arc;
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use quicproquo_core::{GroupMember, IdentityKeypair};
|
use quicprochat_core::{GroupMember, IdentityKeypair};
|
||||||
use quicproquo_sdk::client::QpqClient;
|
use quicprochat_sdk::client::QpqClient;
|
||||||
use quicproquo_sdk::conversation::{ConversationId, ConversationKind, StoredMessage};
|
use quicprochat_sdk::conversation::{ConversationId, ConversationKind, StoredMessage};
|
||||||
use quicproquo_sdk::events::ClientEvent;
|
use quicprochat_sdk::events::ClientEvent;
|
||||||
use rustyline::completion::{Completer, Pair};
|
use rustyline::completion::{Completer, Pair};
|
||||||
use rustyline::error::ReadlineError;
|
use rustyline::error::ReadlineError;
|
||||||
use rustyline::highlight::Highlighter;
|
use rustyline::highlight::Highlighter;
|
||||||
@@ -216,14 +216,14 @@ impl Drop for ServerGuard {
|
|||||||
|
|
||||||
fn find_server_binary() -> Option<PathBuf> {
|
fn find_server_binary() -> Option<PathBuf> {
|
||||||
if let Ok(exe) = std::env::current_exe() {
|
if let Ok(exe) = std::env::current_exe() {
|
||||||
let sibling = exe.with_file_name("qpq-server");
|
let sibling = exe.with_file_name("qpc-server");
|
||||||
if sibling.exists() {
|
if sibling.exists() {
|
||||||
return Some(sibling);
|
return Some(sibling);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::env::var_os("PATH").and_then(|paths| {
|
std::env::var_os("PATH").and_then(|paths| {
|
||||||
std::env::split_paths(&paths)
|
std::env::split_paths(&paths)
|
||||||
.map(|dir| dir.join("qpq-server"))
|
.map(|dir| dir.join("qpc-server"))
|
||||||
.find(|p| p.exists())
|
.find(|p| p.exists())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -235,7 +235,7 @@ async fn auto_start_server(addr: &str) -> ServerGuard {
|
|||||||
let binary = match find_server_binary() {
|
let binary = match find_server_binary() {
|
||||||
Some(b) => b,
|
Some(b) => b,
|
||||||
None => {
|
None => {
|
||||||
display::print_status("server not reachable and qpq-server binary not found");
|
display::print_status("server not reachable and qpc-server binary not found");
|
||||||
return ServerGuard(None);
|
return ServerGuard(None);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -294,6 +294,15 @@ fn show_event(event: &ClientEvent) {
|
|||||||
};
|
};
|
||||||
display::print_incoming(&sender, body);
|
display::print_incoming(&sender, body);
|
||||||
}
|
}
|
||||||
|
ClientEvent::Connected => {
|
||||||
|
display::print_status("connected to server");
|
||||||
|
}
|
||||||
|
ClientEvent::Disconnected { reason } => {
|
||||||
|
display::print_error(&format!("disconnected: {reason}"));
|
||||||
|
}
|
||||||
|
ClientEvent::Reconnecting { attempt } => {
|
||||||
|
display::print_status(&format!("reconnecting... (attempt {attempt})"));
|
||||||
|
}
|
||||||
ClientEvent::ConversationCreated { display_name, .. } => {
|
ClientEvent::ConversationCreated { display_name, .. } => {
|
||||||
display::print_status(&format!("new conversation: {display_name}"));
|
display::print_status(&format!("new conversation: {display_name}"));
|
||||||
}
|
}
|
||||||
@@ -311,7 +320,7 @@ fn show_event(event: &ClientEvent) {
|
|||||||
// ── Help ────────────────────────────────────────────────────────────────────
|
// ── Help ────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
fn print_help() {
|
fn print_help() {
|
||||||
println!("\n{BOLD}quicproquo v2 REPL{RESET}\n");
|
println!("\n{BOLD}quicprochat v2 REPL{RESET}\n");
|
||||||
for cat in Category::all() {
|
for cat in Category::all() {
|
||||||
println!("{BOLD}{}{RESET}", cat.label());
|
println!("{BOLD}{}{RESET}", cat.label());
|
||||||
for cmd in COMMANDS.iter().filter(|c| c.category == *cat) {
|
for cmd in COMMANDS.iter().filter(|c| c.category == *cat) {
|
||||||
@@ -397,7 +406,7 @@ async fn dispatch(
|
|||||||
|
|
||||||
fn do_status(client: &QpqClient, st: &ReplState) {
|
fn do_status(client: &QpqClient, st: &ReplState) {
|
||||||
println!("{BOLD}Status{RESET}");
|
println!("{BOLD}Status{RESET}");
|
||||||
println!(" connected: {}", if client.is_connected() { "yes" } else { "no" });
|
println!(" connection: {}", client.connection_state());
|
||||||
println!(" authenticated: {}", if client.is_authenticated() { "yes" } else { "no" });
|
println!(" authenticated: {}", if client.is_authenticated() { "yes" } else { "no" });
|
||||||
println!(" username: {}", client.username().unwrap_or("(none)"));
|
println!(" username: {}", client.username().unwrap_or("(none)"));
|
||||||
println!(" conversation: {}", st.current_display_name.as_deref().unwrap_or("(none)"));
|
println!(" conversation: {}", st.current_display_name.as_deref().unwrap_or("(none)"));
|
||||||
@@ -462,14 +471,14 @@ async fn do_login(client: &mut QpqClient, st: &mut ReplState, args: &str) -> any
|
|||||||
// Try to load identity keypair from state file.
|
// Try to load identity keypair from state file.
|
||||||
let state_path = &client.config_state_path();
|
let state_path = &client.config_state_path();
|
||||||
if state_path.exists() {
|
if state_path.exists() {
|
||||||
match quicproquo_sdk::state::load_state(state_path, Some(pass)) {
|
match quicprochat_sdk::state::load_state(state_path, Some(pass)) {
|
||||||
Ok(stored) => {
|
Ok(stored) => {
|
||||||
let kp = IdentityKeypair::from_seed(stored.identity_seed);
|
let kp = IdentityKeypair::from_seed(stored.identity_seed);
|
||||||
st.identity = Some(Arc::new(kp));
|
st.identity = Some(Arc::new(kp));
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
// Try without password (unencrypted state).
|
// Try without password (unencrypted state).
|
||||||
if let Ok(stored) = quicproquo_sdk::state::load_state(state_path, None) {
|
if let Ok(stored) = quicprochat_sdk::state::load_state(state_path, None) {
|
||||||
let kp = IdentityKeypair::from_seed(stored.identity_seed);
|
let kp = IdentityKeypair::from_seed(stored.identity_seed);
|
||||||
st.identity = Some(Arc::new(kp));
|
st.identity = Some(Arc::new(kp));
|
||||||
}
|
}
|
||||||
@@ -493,7 +502,7 @@ async fn do_resolve(client: &QpqClient, args: &str) -> anyhow::Result<()> {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let rpc = client.rpc().map_err(|e| anyhow::anyhow!("{e}"))?;
|
let rpc = client.rpc().map_err(|e| anyhow::anyhow!("{e}"))?;
|
||||||
match quicproquo_sdk::users::resolve_user(rpc, name).await? {
|
match quicprochat_sdk::users::resolve_user(rpc, name).await? {
|
||||||
Some(key) => println!(" {name} -> {}", hex::encode(&key)),
|
Some(key) => println!(" {name} -> {}", hex::encode(&key)),
|
||||||
None => display::print_error(&format!("user '{name}' not found")),
|
None => display::print_error(&format!("user '{name}' not found")),
|
||||||
}
|
}
|
||||||
@@ -510,7 +519,7 @@ async fn do_safety(client: &QpqClient, st: &ReplState, args: &str) -> anyhow::Re
|
|||||||
let my_key = identity.public_key_bytes();
|
let my_key = identity.public_key_bytes();
|
||||||
|
|
||||||
let rpc = client.rpc().map_err(|e| anyhow::anyhow!("{e}"))?;
|
let rpc = client.rpc().map_err(|e| anyhow::anyhow!("{e}"))?;
|
||||||
let peer_key = quicproquo_sdk::users::resolve_user(rpc, name)
|
let peer_key = quicprochat_sdk::users::resolve_user(rpc, name)
|
||||||
.await?
|
.await?
|
||||||
.ok_or_else(|| anyhow::anyhow!("user '{name}' not found"))?;
|
.ok_or_else(|| anyhow::anyhow!("user '{name}' not found"))?;
|
||||||
if peer_key.len() != 32 {
|
if peer_key.len() != 32 {
|
||||||
@@ -519,7 +528,7 @@ async fn do_safety(client: &QpqClient, st: &ReplState, args: &str) -> anyhow::Re
|
|||||||
let mut peer_arr = [0u8; 32];
|
let mut peer_arr = [0u8; 32];
|
||||||
peer_arr.copy_from_slice(&peer_key);
|
peer_arr.copy_from_slice(&peer_key);
|
||||||
|
|
||||||
let sn = quicproquo_core::compute_safety_number(&my_key, &peer_arr);
|
let sn = quicprochat_core::compute_safety_number(&my_key, &peer_arr);
|
||||||
println!("\n{BOLD}Safety number with {name}:{RESET}");
|
println!("\n{BOLD}Safety number with {name}:{RESET}");
|
||||||
println!(" {sn}\n");
|
println!(" {sn}\n");
|
||||||
println!("{DIM}Compare with {name} over a trusted channel.{RESET}");
|
println!("{DIM}Compare with {name} over a trusted channel.{RESET}");
|
||||||
@@ -536,7 +545,7 @@ async fn do_refresh_key(client: &QpqClient, st: &ReplState) -> anyhow::Result<()
|
|||||||
.map_err(|e| anyhow::anyhow!("generate key package: {e}"))?;
|
.map_err(|e| anyhow::anyhow!("generate key package: {e}"))?;
|
||||||
|
|
||||||
let pub_key = identity.public_key_bytes();
|
let pub_key = identity.public_key_bytes();
|
||||||
let fp = quicproquo_sdk::keys::upload_key_package(rpc, &pub_key, &kp_bytes).await?;
|
let fp = quicprochat_sdk::keys::upload_key_package(rpc, &pub_key, &kp_bytes).await?;
|
||||||
display::print_status(&format!(
|
display::print_status(&format!(
|
||||||
"KeyPackage uploaded (fp: {})",
|
"KeyPackage uploaded (fp: {})",
|
||||||
hex::encode(&fp[..8.min(fp.len())])
|
hex::encode(&fp[..8.min(fp.len())])
|
||||||
@@ -554,7 +563,7 @@ async fn do_dm(client: &mut QpqClient, st: &mut ReplState, args: &str) -> anyhow
|
|||||||
let rpc = client.rpc().map_err(|e| anyhow::anyhow!("{e}"))?;
|
let rpc = client.rpc().map_err(|e| anyhow::anyhow!("{e}"))?;
|
||||||
let conv_store = client.conversations().map_err(|e| anyhow::anyhow!("{e}"))?;
|
let conv_store = client.conversations().map_err(|e| anyhow::anyhow!("{e}"))?;
|
||||||
|
|
||||||
let peer_key = quicproquo_sdk::users::resolve_user(rpc, username)
|
let peer_key = quicprochat_sdk::users::resolve_user(rpc, username)
|
||||||
.await?
|
.await?
|
||||||
.ok_or_else(|| anyhow::anyhow!("user '{username}' not found"))?;
|
.ok_or_else(|| anyhow::anyhow!("user '{username}' not found"))?;
|
||||||
|
|
||||||
@@ -565,13 +574,13 @@ async fn do_dm(client: &mut QpqClient, st: &mut ReplState, args: &str) -> anyhow
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let peer_kp = quicproquo_sdk::keys::fetch_key_package(rpc, &peer_key)
|
let peer_kp = quicprochat_sdk::keys::fetch_key_package(rpc, &peer_key)
|
||||||
.await?
|
.await?
|
||||||
.ok_or_else(|| anyhow::anyhow!("peer has no available KeyPackage"))?;
|
.ok_or_else(|| anyhow::anyhow!("peer has no available KeyPackage"))?;
|
||||||
|
|
||||||
let mut member = GroupMember::new(Arc::clone(&identity));
|
let mut member = GroupMember::new(Arc::clone(&identity));
|
||||||
|
|
||||||
let (conv_id, was_new) = quicproquo_sdk::groups::create_dm(
|
let (conv_id, was_new) = quicprochat_sdk::groups::create_dm(
|
||||||
rpc, conv_store, &mut member, &identity,
|
rpc, conv_store, &mut member, &identity,
|
||||||
&peer_key, &peer_kp, None, None,
|
&peer_key, &peer_kp, None, None,
|
||||||
).await?;
|
).await?;
|
||||||
@@ -599,7 +608,7 @@ async fn do_send(client: &QpqClient, st: &ReplState, msg: &str) -> anyhow::Resul
|
|||||||
.load_conversation(conv_id)?
|
.load_conversation(conv_id)?
|
||||||
.ok_or_else(|| anyhow::anyhow!("conversation not found"))?;
|
.ok_or_else(|| anyhow::anyhow!("conversation not found"))?;
|
||||||
|
|
||||||
let mut member = quicproquo_sdk::groups::restore_mls_state(&conv, &identity)?;
|
let mut member = quicprochat_sdk::groups::restore_mls_state(&conv, &identity)?;
|
||||||
|
|
||||||
let my_pub = identity.public_key_bytes();
|
let my_pub = identity.public_key_bytes();
|
||||||
let recipients: Vec<Vec<u8>> = conv
|
let recipients: Vec<Vec<u8>> = conv
|
||||||
@@ -614,13 +623,13 @@ async fn do_send(client: &QpqClient, st: &ReplState, msg: &str) -> anyhow::Resul
|
|||||||
}
|
}
|
||||||
|
|
||||||
let hybrid_keys = vec![None; recipients.len()];
|
let hybrid_keys = vec![None; recipients.len()];
|
||||||
quicproquo_sdk::messaging::send_message(
|
quicprochat_sdk::messaging::send_message(
|
||||||
rpc, &mut member, &identity, msg, &recipients, &hybrid_keys, conv_id.0.as_slice(),
|
rpc, &mut member, &identity, msg, &recipients, &hybrid_keys, conv_id.0.as_slice(),
|
||||||
).await?;
|
).await?;
|
||||||
|
|
||||||
quicproquo_sdk::groups::save_mls_state(conv_store, conv_id, &member)?;
|
quicprochat_sdk::groups::save_mls_state(conv_store, conv_id, &member)?;
|
||||||
|
|
||||||
let now = quicproquo_sdk::conversation::now_ms();
|
let now = quicprochat_sdk::conversation::now_ms();
|
||||||
conv_store.save_message(&StoredMessage {
|
conv_store.save_message(&StoredMessage {
|
||||||
conversation_id: conv_id.clone(),
|
conversation_id: conv_id.clone(),
|
||||||
message_id: None,
|
message_id: None,
|
||||||
@@ -647,10 +656,10 @@ async fn do_recv(client: &QpqClient, st: &ReplState) -> anyhow::Result<()> {
|
|||||||
.load_conversation(conv_id)?
|
.load_conversation(conv_id)?
|
||||||
.ok_or_else(|| anyhow::anyhow!("conversation not found"))?;
|
.ok_or_else(|| anyhow::anyhow!("conversation not found"))?;
|
||||||
|
|
||||||
let mut member = quicproquo_sdk::groups::restore_mls_state(&conv, &identity)?;
|
let mut member = quicprochat_sdk::groups::restore_mls_state(&conv, &identity)?;
|
||||||
let my_pub = identity.public_key_bytes();
|
let my_pub = identity.public_key_bytes();
|
||||||
|
|
||||||
let messages = quicproquo_sdk::messaging::receive_messages(
|
let messages = quicprochat_sdk::messaging::receive_messages(
|
||||||
rpc, &mut member, &my_pub, None, conv_id.0.as_slice(), &[],
|
rpc, &mut member, &my_pub, None, conv_id.0.as_slice(), &[],
|
||||||
).await?;
|
).await?;
|
||||||
|
|
||||||
@@ -659,10 +668,10 @@ async fn do_recv(client: &QpqClient, st: &ReplState) -> anyhow::Result<()> {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
quicproquo_sdk::groups::save_mls_state(conv_store, conv_id, &member)?;
|
quicprochat_sdk::groups::save_mls_state(conv_store, conv_id, &member)?;
|
||||||
|
|
||||||
for m in &messages {
|
for m in &messages {
|
||||||
let sender_name = quicproquo_sdk::users::resolve_identity(rpc, &m.sender_key)
|
let sender_name = quicprochat_sdk::users::resolve_identity(rpc, &m.sender_key)
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok()
|
||||||
.flatten();
|
.flatten();
|
||||||
@@ -670,13 +679,13 @@ async fn do_recv(client: &QpqClient, st: &ReplState) -> anyhow::Result<()> {
|
|||||||
let sender = sender_name.as_deref().unwrap_or(&sender_hex);
|
let sender = sender_name.as_deref().unwrap_or(&sender_hex);
|
||||||
|
|
||||||
let body = match &m.message {
|
let body = match &m.message {
|
||||||
quicproquo_core::AppMessage::Chat { body, .. } => {
|
quicprochat_core::AppMessage::Chat { body, .. } => {
|
||||||
String::from_utf8_lossy(body).to_string()
|
String::from_utf8_lossy(body).to_string()
|
||||||
}
|
}
|
||||||
other => format!("{other:?}"),
|
other => format!("{other:?}"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let now = quicproquo_sdk::conversation::now_ms();
|
let now = quicprochat_sdk::conversation::now_ms();
|
||||||
println!("{DIM}[{}]{RESET} {CYAN}{BOLD}{sender}{RESET}: {body}", ts(now));
|
println!("{DIM}[{}]{RESET} {CYAN}{BOLD}{sender}{RESET}: {body}", ts(now));
|
||||||
|
|
||||||
conv_store.save_message(&StoredMessage {
|
conv_store.save_message(&StoredMessage {
|
||||||
@@ -772,7 +781,7 @@ async fn do_group(client: &mut QpqClient, st: &mut ReplState, args: &str) -> any
|
|||||||
let identity = st.require_identity()?;
|
let identity = st.require_identity()?;
|
||||||
let conv_store = client.conversations().map_err(|e| anyhow::anyhow!("{e}"))?;
|
let conv_store = client.conversations().map_err(|e| anyhow::anyhow!("{e}"))?;
|
||||||
let mut member = GroupMember::new(Arc::clone(&identity));
|
let mut member = GroupMember::new(Arc::clone(&identity));
|
||||||
let conv_id = quicproquo_sdk::groups::create_group(conv_store, &mut member, name)?;
|
let conv_id = quicprochat_sdk::groups::create_group(conv_store, &mut member, name)?;
|
||||||
st.set_conversation(conv_id, format!("#{name}"));
|
st.set_conversation(conv_id, format!("#{name}"));
|
||||||
display::print_status(&format!("group #{name} created"));
|
display::print_status(&format!("group #{name} created"));
|
||||||
}
|
}
|
||||||
@@ -788,10 +797,10 @@ async fn do_group(client: &mut QpqClient, st: &mut ReplState, args: &str) -> any
|
|||||||
let rpc = client.rpc().map_err(|e| anyhow::anyhow!("{e}"))?;
|
let rpc = client.rpc().map_err(|e| anyhow::anyhow!("{e}"))?;
|
||||||
let conv_store = client.conversations().map_err(|e| anyhow::anyhow!("{e}"))?;
|
let conv_store = client.conversations().map_err(|e| anyhow::anyhow!("{e}"))?;
|
||||||
|
|
||||||
let peer_key = quicproquo_sdk::users::resolve_user(rpc, user)
|
let peer_key = quicprochat_sdk::users::resolve_user(rpc, user)
|
||||||
.await?
|
.await?
|
||||||
.ok_or_else(|| anyhow::anyhow!("user '{user}' not found"))?;
|
.ok_or_else(|| anyhow::anyhow!("user '{user}' not found"))?;
|
||||||
let peer_kp = quicproquo_sdk::keys::fetch_key_package(rpc, &peer_key)
|
let peer_kp = quicprochat_sdk::keys::fetch_key_package(rpc, &peer_key)
|
||||||
.await?
|
.await?
|
||||||
.ok_or_else(|| anyhow::anyhow!("peer has no KeyPackage"))?;
|
.ok_or_else(|| anyhow::anyhow!("peer has no KeyPackage"))?;
|
||||||
|
|
||||||
@@ -799,9 +808,9 @@ async fn do_group(client: &mut QpqClient, st: &mut ReplState, args: &str) -> any
|
|||||||
let conv = conv_store
|
let conv = conv_store
|
||||||
.load_conversation(&conv_id)?
|
.load_conversation(&conv_id)?
|
||||||
.ok_or_else(|| anyhow::anyhow!("group '{group}' not found"))?;
|
.ok_or_else(|| anyhow::anyhow!("group '{group}' not found"))?;
|
||||||
let mut member = quicproquo_sdk::groups::restore_mls_state(&conv, &identity)?;
|
let mut member = quicprochat_sdk::groups::restore_mls_state(&conv, &identity)?;
|
||||||
|
|
||||||
quicproquo_sdk::groups::invite_to_group(
|
quicprochat_sdk::groups::invite_to_group(
|
||||||
rpc, conv_store, &mut member, &identity,
|
rpc, conv_store, &mut member, &identity,
|
||||||
&conv_id, &peer_key, &peer_kp, None, None,
|
&conv_id, &peer_key, &peer_kp, None, None,
|
||||||
).await?;
|
).await?;
|
||||||
@@ -816,8 +825,8 @@ async fn do_group(client: &mut QpqClient, st: &mut ReplState, args: &str) -> any
|
|||||||
let conv = conv_store
|
let conv = conv_store
|
||||||
.load_conversation(&conv_id)?
|
.load_conversation(&conv_id)?
|
||||||
.ok_or_else(|| anyhow::anyhow!("conversation not found"))?;
|
.ok_or_else(|| anyhow::anyhow!("conversation not found"))?;
|
||||||
let mut member = quicproquo_sdk::groups::restore_mls_state(&conv, &identity)?;
|
let mut member = quicprochat_sdk::groups::restore_mls_state(&conv, &identity)?;
|
||||||
quicproquo_sdk::groups::leave_group(rpc, conv_store, &mut member, &conv_id).await?;
|
quicprochat_sdk::groups::leave_group(rpc, conv_store, &mut member, &conv_id).await?;
|
||||||
display::print_status("left group");
|
display::print_status("left group");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -834,7 +843,7 @@ async fn do_group(client: &mut QpqClient, st: &mut ReplState, args: &str) -> any
|
|||||||
for key in &conv.member_keys {
|
for key in &conv.member_keys {
|
||||||
let short = hex::encode(&key[..4.min(key.len())]);
|
let short = hex::encode(&key[..4.min(key.len())]);
|
||||||
if let Ok(rpc) = client.rpc() {
|
if let Ok(rpc) = client.rpc() {
|
||||||
if let Ok(Some(n)) = quicproquo_sdk::users::resolve_identity(rpc, key).await {
|
if let Ok(Some(n)) = quicprochat_sdk::users::resolve_identity(rpc, key).await {
|
||||||
println!(" @{n} {DIM}({short}){RESET}");
|
println!(" @{n} {DIM}({short}){RESET}");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -855,14 +864,14 @@ async fn do_group(client: &mut QpqClient, st: &mut ReplState, args: &str) -> any
|
|||||||
let rpc = client.rpc().map_err(|e| anyhow::anyhow!("{e}"))?;
|
let rpc = client.rpc().map_err(|e| anyhow::anyhow!("{e}"))?;
|
||||||
let conv_store = client.conversations().map_err(|e| anyhow::anyhow!("{e}"))?;
|
let conv_store = client.conversations().map_err(|e| anyhow::anyhow!("{e}"))?;
|
||||||
|
|
||||||
let peer_key = quicproquo_sdk::users::resolve_user(rpc, user)
|
let peer_key = quicprochat_sdk::users::resolve_user(rpc, user)
|
||||||
.await?
|
.await?
|
||||||
.ok_or_else(|| anyhow::anyhow!("user '{user}' not found"))?;
|
.ok_or_else(|| anyhow::anyhow!("user '{user}' not found"))?;
|
||||||
let conv = conv_store
|
let conv = conv_store
|
||||||
.load_conversation(&conv_id)?
|
.load_conversation(&conv_id)?
|
||||||
.ok_or_else(|| anyhow::anyhow!("conversation not found"))?;
|
.ok_or_else(|| anyhow::anyhow!("conversation not found"))?;
|
||||||
let mut member = quicproquo_sdk::groups::restore_mls_state(&conv, &identity)?;
|
let mut member = quicprochat_sdk::groups::restore_mls_state(&conv, &identity)?;
|
||||||
quicproquo_sdk::groups::remove_member_from_group(
|
quicprochat_sdk::groups::remove_member_from_group(
|
||||||
rpc, conv_store, &mut member, &conv_id, &peer_key,
|
rpc, conv_store, &mut member, &conv_id, &peer_key,
|
||||||
).await?;
|
).await?;
|
||||||
display::print_status(&format!("removed @{user} from group"));
|
display::print_status(&format!("removed @{user} from group"));
|
||||||
@@ -877,7 +886,7 @@ async fn do_group(client: &mut QpqClient, st: &mut ReplState, args: &str) -> any
|
|||||||
let conv_id = st.require_conversation()?.clone();
|
let conv_id = st.require_conversation()?.clone();
|
||||||
let rpc = client.rpc().map_err(|e| anyhow::anyhow!("{e}"))?;
|
let rpc = client.rpc().map_err(|e| anyhow::anyhow!("{e}"))?;
|
||||||
let conv_store = client.conversations().map_err(|e| anyhow::anyhow!("{e}"))?;
|
let conv_store = client.conversations().map_err(|e| anyhow::anyhow!("{e}"))?;
|
||||||
quicproquo_sdk::groups::set_group_metadata(
|
quicprochat_sdk::groups::set_group_metadata(
|
||||||
rpc, conv_store, &conv_id, new_name, "", &[],
|
rpc, conv_store, &conv_id, new_name, "", &[],
|
||||||
).await?;
|
).await?;
|
||||||
st.set_conversation(conv_id, format!("#{new_name}"));
|
st.set_conversation(conv_id, format!("#{new_name}"));
|
||||||
@@ -892,8 +901,8 @@ async fn do_group(client: &mut QpqClient, st: &mut ReplState, args: &str) -> any
|
|||||||
let conv = conv_store
|
let conv = conv_store
|
||||||
.load_conversation(&conv_id)?
|
.load_conversation(&conv_id)?
|
||||||
.ok_or_else(|| anyhow::anyhow!("conversation not found"))?;
|
.ok_or_else(|| anyhow::anyhow!("conversation not found"))?;
|
||||||
let mut member = quicproquo_sdk::groups::restore_mls_state(&conv, &identity)?;
|
let mut member = quicprochat_sdk::groups::restore_mls_state(&conv, &identity)?;
|
||||||
quicproquo_sdk::groups::rotate_group_keys(rpc, conv_store, &mut member, &conv_id).await?;
|
quicprochat_sdk::groups::rotate_group_keys(rpc, conv_store, &mut member, &conv_id).await?;
|
||||||
display::print_status("group keys rotated");
|
display::print_status("group keys rotated");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -911,7 +920,7 @@ async fn do_devices(client: &mut QpqClient, args: &str) -> anyhow::Result<()> {
|
|||||||
match sub {
|
match sub {
|
||||||
"list" => {
|
"list" => {
|
||||||
let rpc = client.rpc().map_err(|e| anyhow::anyhow!("{e}"))?;
|
let rpc = client.rpc().map_err(|e| anyhow::anyhow!("{e}"))?;
|
||||||
let devices = quicproquo_sdk::devices::list_devices(rpc).await?;
|
let devices = quicprochat_sdk::devices::list_devices(rpc).await?;
|
||||||
if devices.is_empty() {
|
if devices.is_empty() {
|
||||||
display::print_status("no devices registered");
|
display::print_status("no devices registered");
|
||||||
} else {
|
} else {
|
||||||
@@ -941,7 +950,7 @@ async fn do_devices(client: &mut QpqClient, args: &str) -> anyhow::Result<()> {
|
|||||||
let mut dev_id = vec![0u8; 16];
|
let mut dev_id = vec![0u8; 16];
|
||||||
rand::rngs::OsRng.fill_bytes(&mut dev_id);
|
rand::rngs::OsRng.fill_bytes(&mut dev_id);
|
||||||
let was_new =
|
let was_new =
|
||||||
quicproquo_sdk::devices::register_device(rpc, &dev_id, name).await?;
|
quicprochat_sdk::devices::register_device(rpc, &dev_id, name).await?;
|
||||||
if was_new {
|
if was_new {
|
||||||
display::print_status(&format!(
|
display::print_status(&format!(
|
||||||
"device registered: {name} (id: {})",
|
"device registered: {name} (id: {})",
|
||||||
@@ -961,7 +970,7 @@ async fn do_devices(client: &mut QpqClient, args: &str) -> anyhow::Result<()> {
|
|||||||
let id_bytes = hex::decode(id_hex)
|
let id_bytes = hex::decode(id_hex)
|
||||||
.map_err(|e| anyhow::anyhow!("invalid device_id hex: {e}"))?;
|
.map_err(|e| anyhow::anyhow!("invalid device_id hex: {e}"))?;
|
||||||
let rpc = client.rpc().map_err(|e| anyhow::anyhow!("{e}"))?;
|
let rpc = client.rpc().map_err(|e| anyhow::anyhow!("{e}"))?;
|
||||||
let revoked = quicproquo_sdk::devices::revoke_device(rpc, &id_bytes).await?;
|
let revoked = quicprochat_sdk::devices::revoke_device(rpc, &id_bytes).await?;
|
||||||
if revoked {
|
if revoked {
|
||||||
display::print_status(&format!("device revoked: {id_hex}"));
|
display::print_status(&format!("device revoked: {id_hex}"));
|
||||||
} else {
|
} else {
|
||||||
@@ -990,6 +999,9 @@ pub async fn run_v2_repl(
|
|||||||
// Connect to server.
|
// Connect to server.
|
||||||
client.connect().await.context("connect to server")?;
|
client.connect().await.context("connect to server")?;
|
||||||
|
|
||||||
|
// Start heartbeat for proactive dead-connection detection.
|
||||||
|
client.start_heartbeat();
|
||||||
|
|
||||||
// Background event listener.
|
// Background event listener.
|
||||||
let rx = client.subscribe();
|
let rx = client.subscribe();
|
||||||
spawn_event_listener(rx);
|
spawn_event_listener(rx);
|
||||||
@@ -1004,8 +1016,8 @@ pub async fn run_v2_repl(
|
|||||||
// Load identity from state.
|
// Load identity from state.
|
||||||
let state_path = client.config_state_path();
|
let state_path = client.config_state_path();
|
||||||
if state_path.exists() {
|
if state_path.exists() {
|
||||||
if let Ok(stored) = quicproquo_sdk::state::load_state(&state_path, Some(pass))
|
if let Ok(stored) = quicprochat_sdk::state::load_state(&state_path, Some(pass))
|
||||||
.or_else(|_| quicproquo_sdk::state::load_state(&state_path, None))
|
.or_else(|_| quicprochat_sdk::state::load_state(&state_path, None))
|
||||||
{
|
{
|
||||||
let kp = IdentityKeypair::from_seed(stored.identity_seed);
|
let kp = IdentityKeypair::from_seed(stored.identity_seed);
|
||||||
st.identity = Some(Arc::new(kp));
|
st.identity = Some(Arc::new(kp));
|
||||||
@@ -1016,7 +1028,7 @@ pub async fn run_v2_repl(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("\n{BOLD}quicproquo v2 REPL{RESET}");
|
println!("\n{BOLD}quicprochat v2 REPL{RESET}");
|
||||||
println!("{DIM}Type /help for commands, /quit to exit.{RESET}\n");
|
println!("{DIM}Type /help for commands, /quit to exit.{RESET}\n");
|
||||||
if let Some(u) = client.username() {
|
if let Some(u) = client.username() {
|
||||||
display::print_status(&format!("authenticated as {u}"));
|
display::print_status(&format!("authenticated as {u}"));
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
//! Full-screen Ratatui TUI for quicproquo v2, driven by the SDK event system.
|
//! Full-screen Ratatui TUI for quicprochat v2, driven by the SDK event system.
|
||||||
//!
|
//!
|
||||||
//! Layout:
|
//! Layout:
|
||||||
//! +-- Conversations -+-- Messages ------------------------------+
|
//! +-- Conversations -+-- Messages ------------------------------+
|
||||||
@@ -20,6 +20,9 @@
|
|||||||
//! Ctrl+C / Ctrl+Q -- quit
|
//! Ctrl+C / Ctrl+Q -- quit
|
||||||
//!
|
//!
|
||||||
//! Feature gate: requires both `v2` and `tui` features.
|
//! Feature gate: requires both `v2` and `tui` features.
|
||||||
|
//!
|
||||||
|
//! **Note:** Message display is currently local-only. Use the REPL client for
|
||||||
|
//! end-to-end encrypted delivery. See `quicprochat-sdk::messaging` for the full pipeline.
|
||||||
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
@@ -38,9 +41,9 @@ use ratatui::{
|
|||||||
};
|
};
|
||||||
use tokio::sync::broadcast;
|
use tokio::sync::broadcast;
|
||||||
|
|
||||||
use quicproquo_sdk::client::QpqClient;
|
use quicprochat_sdk::client::{ConnectionState, QpqClient};
|
||||||
use quicproquo_sdk::conversation::ConversationStore;
|
use quicprochat_sdk::conversation::ConversationStore;
|
||||||
use quicproquo_sdk::events::ClientEvent;
|
use quicprochat_sdk::events::ClientEvent;
|
||||||
|
|
||||||
// ── Data Types ──────────────────────────────────────────────────────────────
|
// ── Data Types ──────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
@@ -84,8 +87,8 @@ pub struct TuiApp {
|
|||||||
focus: Focus,
|
focus: Focus,
|
||||||
/// Notification line (shown briefly, e.g. "Message sent", "Error: ...").
|
/// Notification line (shown briefly, e.g. "Message sent", "Error: ...").
|
||||||
notification: Option<String>,
|
notification: Option<String>,
|
||||||
/// Whether the client is currently connected.
|
/// Current connection state.
|
||||||
connected: bool,
|
conn_state: quicprochat_sdk::client::ConnectionState,
|
||||||
/// Current MLS epoch for the active conversation (if available).
|
/// Current MLS epoch for the active conversation (if available).
|
||||||
mls_epoch: Option<u64>,
|
mls_epoch: Option<u64>,
|
||||||
}
|
}
|
||||||
@@ -105,7 +108,7 @@ impl TuiApp {
|
|||||||
server_addr: server_addr.to_string(),
|
server_addr: server_addr.to_string(),
|
||||||
focus: Focus::Input,
|
focus: Focus::Input,
|
||||||
notification: None,
|
notification: None,
|
||||||
connected: false,
|
conn_state: ConnectionState::Disconnected,
|
||||||
mls_epoch: None,
|
mls_epoch: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -146,7 +149,15 @@ impl TuiApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update_status(&mut self) {
|
fn update_status(&mut self) {
|
||||||
let conn_indicator = if self.connected { "Online" } else { "Offline" };
|
let conn_indicator = match self.conn_state {
|
||||||
|
ConnectionState::Connected => "Connected",
|
||||||
|
ConnectionState::Reconnecting { attempt } => {
|
||||||
|
// We can't use format! in a match arm and return &str,
|
||||||
|
// so we'll handle this below.
|
||||||
|
return self.update_status_reconnecting(attempt);
|
||||||
|
}
|
||||||
|
ConnectionState::Disconnected => "Offline",
|
||||||
|
};
|
||||||
let user = self
|
let user = self
|
||||||
.username
|
.username
|
||||||
.as_deref()
|
.as_deref()
|
||||||
@@ -164,6 +175,25 @@ impl TuiApp {
|
|||||||
if conv_count == 1 { "" } else { "s" }
|
if conv_count == 1 { "" } else { "s" }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn update_status_reconnecting(&mut self, attempt: u32) {
|
||||||
|
let user = self
|
||||||
|
.username
|
||||||
|
.as_deref()
|
||||||
|
.unwrap_or("not logged in");
|
||||||
|
let conv_count = self.conversations.len();
|
||||||
|
let epoch_str = match self.mls_epoch {
|
||||||
|
Some(e) => format!("epoch {e}"),
|
||||||
|
None => "epoch --".to_string(),
|
||||||
|
};
|
||||||
|
self.status_line = format!(
|
||||||
|
"Reconnecting... (attempt {attempt}) | {} | {} | {} conversation{} | MLS {epoch_str}",
|
||||||
|
self.server_addr,
|
||||||
|
user,
|
||||||
|
conv_count,
|
||||||
|
if conv_count == 1 { "" } else { "s" }
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Terminal Drop Guard ─────────────────────────────────────────────────────
|
// ── Terminal Drop Guard ─────────────────────────────────────────────────────
|
||||||
@@ -195,7 +225,7 @@ pub async fn run_v2_tui(client: &mut QpqClient) -> anyhow::Result<()> {
|
|||||||
"disconnected"
|
"disconnected"
|
||||||
};
|
};
|
||||||
let mut app = TuiApp::new(server_addr);
|
let mut app = TuiApp::new(server_addr);
|
||||||
app.connected = client.is_connected();
|
app.conn_state = client.connection_state();
|
||||||
|
|
||||||
// Populate initial state from client.
|
// Populate initial state from client.
|
||||||
if let Some(name) = client.username() {
|
if let Some(name) = client.username() {
|
||||||
@@ -222,6 +252,9 @@ pub async fn run_v2_tui(client: &mut QpqClient) -> anyhow::Result<()> {
|
|||||||
|
|
||||||
app.update_status();
|
app.update_status();
|
||||||
|
|
||||||
|
// Start heartbeat for proactive dead-connection detection.
|
||||||
|
client.start_heartbeat();
|
||||||
|
|
||||||
// Subscribe to SDK events.
|
// Subscribe to SDK events.
|
||||||
let mut event_rx = client.subscribe();
|
let mut event_rx = client.subscribe();
|
||||||
|
|
||||||
@@ -275,15 +308,20 @@ pub async fn run_v2_tui(client: &mut QpqClient) -> anyhow::Result<()> {
|
|||||||
fn handle_sdk_event(app: &mut TuiApp, event: ClientEvent) {
|
fn handle_sdk_event(app: &mut TuiApp, event: ClientEvent) {
|
||||||
match event {
|
match event {
|
||||||
ClientEvent::Connected => {
|
ClientEvent::Connected => {
|
||||||
app.connected = true;
|
app.conn_state = ConnectionState::Connected;
|
||||||
app.notification = Some("Connected to server".to_string());
|
app.notification = Some("Connected to server".to_string());
|
||||||
app.update_status();
|
app.update_status();
|
||||||
}
|
}
|
||||||
ClientEvent::Disconnected { reason } => {
|
ClientEvent::Disconnected { reason } => {
|
||||||
app.connected = false;
|
app.conn_state = ConnectionState::Disconnected;
|
||||||
app.notification = Some(format!("Disconnected: {reason}"));
|
app.notification = Some(format!("Disconnected: {reason}"));
|
||||||
app.update_status();
|
app.update_status();
|
||||||
}
|
}
|
||||||
|
ClientEvent::Reconnecting { attempt } => {
|
||||||
|
app.conn_state = ConnectionState::Reconnecting { attempt };
|
||||||
|
app.notification = Some(format!("Reconnecting... (attempt {attempt})"));
|
||||||
|
app.update_status();
|
||||||
|
}
|
||||||
ClientEvent::Registered { username } => {
|
ClientEvent::Registered { username } => {
|
||||||
app.notification = Some(format!("Registered as {username}"));
|
app.notification = Some(format!("Registered as {username}"));
|
||||||
}
|
}
|
||||||
@@ -535,9 +573,11 @@ async fn handle_input(app: &mut TuiApp, client: &mut QpqClient, text: &str) {
|
|||||||
// Snap to bottom.
|
// Snap to bottom.
|
||||||
app.scroll_offset = 0;
|
app.scroll_offset = 0;
|
||||||
|
|
||||||
// TODO: actually send via SDK when the send pipeline is wired up.
|
// NOTE: TUI message display is local-only. The full MLS encryption
|
||||||
// For now, emit a notification.
|
// pipeline (sealed sender + hybrid wrap + enqueue) is implemented in
|
||||||
app.notification = Some(format!("Sent: {text}"));
|
// quicprochat-sdk/src/messaging.rs but is not yet wired into the TUI.
|
||||||
|
// Use the REPL client (`qpc repl`) for end-to-end message delivery.
|
||||||
|
app.notification = Some("Message queued locally (TUI send not yet wired to SDK)".to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -824,7 +864,7 @@ fn draw_input(frame: &mut Frame, app: &TuiApp, area: Rect) {
|
|||||||
frame.render_widget(input_text, area);
|
frame.render_widget(input_text, area);
|
||||||
|
|
||||||
// Position cursor in the input area.
|
// Position cursor in the input area.
|
||||||
if !app.input.is_empty() || true {
|
if !app.input.is_empty() {
|
||||||
let cursor_x = area.x + 1 + app.input_cursor as u16;
|
let cursor_x = area.x + 1 + app.input_cursor as u16;
|
||||||
let cursor_y = area.y + 1;
|
let cursor_y = area.y + 1;
|
||||||
if cursor_x < area.x + area.width - 1 {
|
if cursor_x < area.x + area.width - 1 {
|
||||||
@@ -834,12 +874,11 @@ fn draw_input(frame: &mut Frame, app: &TuiApp, area: Rect) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn draw_status(frame: &mut Frame, app: &TuiApp, area: Rect) {
|
fn draw_status(frame: &mut Frame, app: &TuiApp, area: Rect) {
|
||||||
let conn_color = if app.connected {
|
let (conn_color, conn_indicator) = match app.conn_state {
|
||||||
Color::Green
|
ConnectionState::Connected => (Color::Green, " ON "),
|
||||||
} else {
|
ConnectionState::Reconnecting { .. } => (Color::Yellow, " ... "),
|
||||||
Color::Red
|
ConnectionState::Disconnected => (Color::Red, " OFF "),
|
||||||
};
|
};
|
||||||
let conn_indicator = if app.connected { " ON " } else { " OFF " };
|
|
||||||
|
|
||||||
let spans = vec![
|
let spans = vec![
|
||||||
Span::styled(
|
Span::styled(
|
||||||
@@ -859,7 +898,7 @@ fn draw_status(frame: &mut Frame, app: &TuiApp, area: Rect) {
|
|||||||
fn draw_help(frame: &mut Frame, area: Rect) {
|
fn draw_help(frame: &mut Frame, area: Rect) {
|
||||||
let help_text = vec![
|
let help_text = vec![
|
||||||
Line::from(Span::styled(
|
Line::from(Span::styled(
|
||||||
" quicproquo TUI -- Help",
|
" quicprochat TUI -- Help",
|
||||||
Style::default()
|
Style::default()
|
||||||
.fg(Color::Cyan)
|
.fg(Color::Cyan)
|
||||||
.add_modifier(Modifier::BOLD),
|
.add_modifier(Modifier::BOLD),
|
||||||
@@ -954,7 +993,7 @@ fn load_messages_for_selected(app: &mut TuiApp, client: &QpqClient) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let sdk_conv_id =
|
let sdk_conv_id =
|
||||||
quicproquo_sdk::conversation::ConversationId::from_slice(&conv_id);
|
quicprochat_sdk::conversation::ConversationId::from_slice(&conv_id);
|
||||||
let sdk_conv_id = match sdk_conv_id {
|
let sdk_conv_id = match sdk_conv_id {
|
||||||
Some(id) => id,
|
Some(id) => id,
|
||||||
None => return,
|
None => return,
|
||||||
@@ -1014,7 +1053,7 @@ mod tests {
|
|||||||
|
|
||||||
fn make_app() -> TuiApp {
|
fn make_app() -> TuiApp {
|
||||||
let mut app = TuiApp::new("127.0.0.1:7000");
|
let mut app = TuiApp::new("127.0.0.1:7000");
|
||||||
app.connected = true;
|
app.conn_state = ConnectionState::Connected;
|
||||||
app.username = Some("alice".to_string());
|
app.username = Some("alice".to_string());
|
||||||
app.conversations.push(ConversationItem {
|
app.conversations.push(ConversationItem {
|
||||||
id: [1u8; 16],
|
id: [1u8; 16],
|
||||||
@@ -1062,12 +1101,12 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn status_bar_shows_online() {
|
fn status_bar_shows_connected() {
|
||||||
let mut app = TuiApp::new("127.0.0.1:7000");
|
let mut app = TuiApp::new("127.0.0.1:7000");
|
||||||
app.connected = true;
|
app.conn_state = ConnectionState::Connected;
|
||||||
app.username = Some("alice".to_string());
|
app.username = Some("alice".to_string());
|
||||||
app.update_status();
|
app.update_status();
|
||||||
assert!(app.status_line.contains("Online"));
|
assert!(app.status_line.contains("Connected"));
|
||||||
assert!(app.status_line.contains("alice"));
|
assert!(app.status_line.contains("alice"));
|
||||||
assert!(app.status_line.contains("MLS epoch --"));
|
assert!(app.status_line.contains("MLS epoch --"));
|
||||||
}
|
}
|
||||||
@@ -1075,15 +1114,32 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn status_bar_shows_offline() {
|
fn status_bar_shows_offline() {
|
||||||
let mut app = TuiApp::new("127.0.0.1:7000");
|
let mut app = TuiApp::new("127.0.0.1:7000");
|
||||||
app.connected = false;
|
app.conn_state = ConnectionState::Disconnected;
|
||||||
app.update_status();
|
app.update_status();
|
||||||
assert!(app.status_line.contains("Offline"));
|
assert!(app.status_line.contains("Offline"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn status_bar_shows_reconnecting() {
|
||||||
|
let mut app = TuiApp::new("127.0.0.1:7000");
|
||||||
|
app.conn_state = ConnectionState::Reconnecting { attempt: 2 };
|
||||||
|
app.update_status();
|
||||||
|
assert!(
|
||||||
|
app.status_line.contains("Reconnecting"),
|
||||||
|
"expected Reconnecting in: {}",
|
||||||
|
app.status_line
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
app.status_line.contains("attempt 2"),
|
||||||
|
"expected attempt count in: {}",
|
||||||
|
app.status_line
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn status_bar_shows_epoch() {
|
fn status_bar_shows_epoch() {
|
||||||
let mut app = TuiApp::new("127.0.0.1:7000");
|
let mut app = TuiApp::new("127.0.0.1:7000");
|
||||||
app.connected = true;
|
app.conn_state = ConnectionState::Connected;
|
||||||
app.mls_epoch = Some(42);
|
app.mls_epoch = Some(42);
|
||||||
app.update_status();
|
app.update_status();
|
||||||
assert!(app.status_line.contains("MLS epoch 42"));
|
assert!(app.status_line.contains("MLS epoch 42"));
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
//! quicproquo CLI client library.
|
//! quicprochat CLI client library.
|
||||||
//!
|
//!
|
||||||
//! # KeyPackage expiry and refresh
|
//! # KeyPackage expiry and refresh
|
||||||
//!
|
//!
|
||||||
//! KeyPackages are single-use (consumed when someone fetches them for an invite) and the server
|
//! KeyPackages are single-use (consumed when someone fetches them for an invite) and the server
|
||||||
//! may enforce a TTL (e.g. 24 hours). To stay invitable, run `qpq refresh-keypackage`
|
//! may enforce a TTL (e.g. 24 hours). To stay invitable, run `qpc refresh-keypackage`
|
||||||
//! periodically (e.g. before the server TTL) or after your KeyPackage was consumed:
|
//! periodically (e.g. before the server TTL) or after your KeyPackage was consumed:
|
||||||
//!
|
//!
|
||||||
//! ```bash
|
//! ```bash
|
||||||
//! qpq refresh-keypackage --state qpq-state.bin --server 127.0.0.1:7000
|
//! qpc refresh-keypackage --state qpc-state.bin --server 127.0.0.1:7000
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! Use the same `--access-token` (or `QPQ_ACCESS_TOKEN`) as for other authenticated
|
//! Use the same `--access-token` (or `QPQ_ACCESS_TOKEN`) as for other authenticated
|
||||||
//! commands. See the [running-the-client](https://docs.quicproquo.dev/getting-started/running-the-client)
|
//! commands. See the [running-the-client](https://docs.quicprochat.dev/getting-started/running-the-client)
|
||||||
//! docs for details.
|
//! docs for details.
|
||||||
|
|
||||||
use std::sync::RwLock;
|
use std::sync::RwLock;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
//! quicproquo CLI client.
|
//! quicprochat CLI client.
|
||||||
|
|
||||||
// ── v2 feature gate: when compiled with --features v2, use the SDK-based CLI.
|
// ── v2 feature gate: when compiled with --features v2, use the SDK-based CLI.
|
||||||
#[cfg(feature = "v2")]
|
#[cfg(feature = "v2")]
|
||||||
@@ -19,21 +19,168 @@ use anyhow::Context;
|
|||||||
#[cfg(not(feature = "v2"))]
|
#[cfg(not(feature = "v2"))]
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
#[cfg(not(feature = "v2"))]
|
#[cfg(not(feature = "v2"))]
|
||||||
use quicproquo_client::{
|
use quicprochat_client::{
|
||||||
cmd_chat, cmd_check_key, cmd_create_group, cmd_demo_group, cmd_export, cmd_export_verify,
|
cmd_chat, cmd_check_key, cmd_create_group, cmd_demo_group, cmd_export, cmd_export_verify,
|
||||||
cmd_fetch_key, cmd_health, cmd_invite, cmd_join, cmd_login, cmd_ping, cmd_recv, cmd_register,
|
cmd_fetch_key, cmd_health, cmd_invite, cmd_join, cmd_login, cmd_ping, cmd_recv, cmd_register,
|
||||||
cmd_register_state, cmd_refresh_keypackage, cmd_register_user, cmd_send, cmd_whoami,
|
cmd_register_state, cmd_refresh_keypackage, cmd_register_user, cmd_send, cmd_whoami,
|
||||||
init_auth, run_repl, set_insecure_skip_verify, ClientAuth,
|
init_auth, run_repl, set_insecure_skip_verify, ClientAuth,
|
||||||
};
|
};
|
||||||
#[cfg(all(feature = "tui", not(feature = "v2")))]
|
#[cfg(all(feature = "tui", not(feature = "v2")))]
|
||||||
use quicproquo_client::client::tui::run_tui;
|
use quicprochat_client::client::tui::run_tui;
|
||||||
|
|
||||||
|
// ── Config file loading ──────────────────────────────────────────────────────
|
||||||
|
//
|
||||||
|
// Loads a TOML config file and sets QPQ_* environment variables for values
|
||||||
|
// not already set. This runs BEFORE clap parses, so the natural precedence is:
|
||||||
|
// CLI flags > environment variables > config file > compiled defaults.
|
||||||
|
//
|
||||||
|
// Config file search order:
|
||||||
|
// 1. --config <path> (parsed manually from argv)
|
||||||
|
// 2. $QPC_CONFIG env var
|
||||||
|
// 3. $XDG_CONFIG_HOME/qpc/config.toml (usually ~/.config/qpc/config.toml)
|
||||||
|
// 4. ~/.qpc.toml
|
||||||
|
#[cfg(not(feature = "v2"))]
|
||||||
|
mod client_config {
|
||||||
|
use serde::Deserialize;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
#[derive(Debug, Default, Deserialize)]
|
||||||
|
pub struct ClientFileConfig {
|
||||||
|
pub server: Option<String>,
|
||||||
|
pub server_name: Option<String>,
|
||||||
|
pub ca_cert: Option<String>,
|
||||||
|
pub username: Option<String>,
|
||||||
|
pub password: Option<String>,
|
||||||
|
pub access_token: Option<String>,
|
||||||
|
pub device_id: Option<String>,
|
||||||
|
pub state_password: Option<String>,
|
||||||
|
pub state: Option<String>,
|
||||||
|
pub danger_accept_invalid_certs: Option<bool>,
|
||||||
|
pub no_server: Option<bool>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Find and load the config file. Returns the parsed config (or default if
|
||||||
|
/// no file is found).
|
||||||
|
pub fn load_client_config() -> ClientFileConfig {
|
||||||
|
let path = find_config_path();
|
||||||
|
let path = match path {
|
||||||
|
Some(p) if p.exists() => p,
|
||||||
|
_ => return ClientFileConfig::default(),
|
||||||
|
};
|
||||||
|
|
||||||
|
match std::fs::read_to_string(&path) {
|
||||||
|
Ok(contents) => match toml::from_str(&contents) {
|
||||||
|
Ok(cfg) => {
|
||||||
|
eprintln!("Loaded config: {}", path.display());
|
||||||
|
cfg
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("Warning: failed to parse {}: {e}", path.display());
|
||||||
|
ClientFileConfig::default()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("Warning: failed to read {}: {e}", path.display());
|
||||||
|
ClientFileConfig::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn find_config_path() -> Option<PathBuf> {
|
||||||
|
// 1. --config <path> from argv (before clap parses).
|
||||||
|
let args: Vec<String> = std::env::args().collect();
|
||||||
|
for i in 0..args.len().saturating_sub(1) {
|
||||||
|
if args[i] == "--config" || args[i] == "-c" {
|
||||||
|
return Some(PathBuf::from(&args[i + 1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. $QPC_CONFIG env var.
|
||||||
|
if let Ok(p) = std::env::var("QPC_CONFIG") {
|
||||||
|
return Some(PathBuf::from(p));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. $XDG_CONFIG_HOME/qpc/config.toml
|
||||||
|
let xdg = std::env::var("XDG_CONFIG_HOME")
|
||||||
|
.map(PathBuf::from)
|
||||||
|
.unwrap_or_else(|_| {
|
||||||
|
let home = std::env::var("HOME").unwrap_or_else(|_| ".".to_string());
|
||||||
|
PathBuf::from(home).join(".config")
|
||||||
|
});
|
||||||
|
let xdg_path = xdg.join("qpc").join("config.toml");
|
||||||
|
if xdg_path.exists() {
|
||||||
|
return Some(xdg_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. ~/.qpc.toml
|
||||||
|
if let Ok(home) = std::env::var("HOME") {
|
||||||
|
let home_path = PathBuf::from(home).join(".qpc.toml");
|
||||||
|
if home_path.exists() {
|
||||||
|
return Some(home_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set QPQ_* env vars from config values, but only if they're not already set.
|
||||||
|
pub fn apply_config_to_env(cfg: &ClientFileConfig) {
|
||||||
|
fn set_if_empty(key: &str, val: &str) {
|
||||||
|
if std::env::var(key).is_err() {
|
||||||
|
std::env::set_var(key, val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(ref v) = cfg.server {
|
||||||
|
set_if_empty("QPQ_SERVER", v);
|
||||||
|
}
|
||||||
|
if let Some(ref v) = cfg.server_name {
|
||||||
|
set_if_empty("QPQ_SERVER_NAME", v);
|
||||||
|
}
|
||||||
|
if let Some(ref v) = cfg.ca_cert {
|
||||||
|
set_if_empty("QPQ_CA_CERT", v);
|
||||||
|
}
|
||||||
|
if let Some(ref v) = cfg.username {
|
||||||
|
set_if_empty("QPQ_USERNAME", v);
|
||||||
|
}
|
||||||
|
if let Some(ref v) = cfg.password {
|
||||||
|
set_if_empty("QPQ_PASSWORD", v);
|
||||||
|
}
|
||||||
|
if let Some(ref v) = cfg.access_token {
|
||||||
|
set_if_empty("QPQ_ACCESS_TOKEN", v);
|
||||||
|
}
|
||||||
|
if let Some(ref v) = cfg.device_id {
|
||||||
|
set_if_empty("QPQ_DEVICE_ID", v);
|
||||||
|
}
|
||||||
|
if let Some(ref v) = cfg.state_password {
|
||||||
|
set_if_empty("QPQ_STATE_PASSWORD", v);
|
||||||
|
}
|
||||||
|
if let Some(ref v) = cfg.state {
|
||||||
|
set_if_empty("QPQ_STATE", v);
|
||||||
|
}
|
||||||
|
if let Some(v) = cfg.danger_accept_invalid_certs {
|
||||||
|
if v {
|
||||||
|
set_if_empty("QPQ_DANGER_ACCEPT_INVALID_CERTS", "true");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(v) = cfg.no_server {
|
||||||
|
if v {
|
||||||
|
set_if_empty("QPQ_NO_SERVER", "true");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ── CLI ───────────────────────────────────────────────────────────────────────
|
// ── CLI ───────────────────────────────────────────────────────────────────────
|
||||||
#[cfg(not(feature = "v2"))]
|
#[cfg(not(feature = "v2"))]
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
#[command(name = "qpq", about = "quicproquo CLI client", version)]
|
#[command(name = "qpc", about = "quicprochat CLI client", version)]
|
||||||
struct Args {
|
struct Args {
|
||||||
|
/// Path to a TOML config file (auto-detected from ~/.config/qpc/config.toml or ~/.qpc.toml).
|
||||||
|
#[arg(long, short = 'c', global = true, env = "QPC_CONFIG")]
|
||||||
|
config: Option<PathBuf>,
|
||||||
|
|
||||||
/// Path to the server's TLS certificate (self-signed by default).
|
/// Path to the server's TLS certificate (self-signed by default).
|
||||||
#[arg(
|
#[arg(
|
||||||
long,
|
long,
|
||||||
@@ -82,7 +229,7 @@ struct Args {
|
|||||||
|
|
||||||
// ── Default-repl args (used when no subcommand is given) ─────────
|
// ── Default-repl args (used when no subcommand is given) ─────────
|
||||||
/// State file path (identity + MLS state). Used when running the default REPL.
|
/// State file path (identity + MLS state). Used when running the default REPL.
|
||||||
#[arg(long, default_value = "qpq-state.bin", env = "QPQ_STATE")]
|
#[arg(long, default_value = "qpc-state.bin", env = "QPQ_STATE")]
|
||||||
state: PathBuf,
|
state: PathBuf,
|
||||||
|
|
||||||
/// Server address (host:port). Used when running the default REPL.
|
/// Server address (host:port). Used when running the default REPL.
|
||||||
@@ -97,7 +244,7 @@ struct Args {
|
|||||||
#[arg(long, env = "QPQ_PASSWORD")]
|
#[arg(long, env = "QPQ_PASSWORD")]
|
||||||
password: Option<String>,
|
password: Option<String>,
|
||||||
|
|
||||||
/// Do not auto-start a local qpq-server (useful when connecting to a remote server).
|
/// Do not auto-start a local qpc-server (useful when connecting to a remote server).
|
||||||
#[arg(long, env = "QPQ_NO_SERVER")]
|
#[arg(long, env = "QPQ_NO_SERVER")]
|
||||||
no_server: bool,
|
no_server: bool,
|
||||||
|
|
||||||
@@ -144,7 +291,7 @@ enum Command {
|
|||||||
/// State file path (identity + MLS state).
|
/// State file path (identity + MLS state).
|
||||||
#[arg(
|
#[arg(
|
||||||
long,
|
long,
|
||||||
default_value = "qpq-state.bin",
|
default_value = "qpc-state.bin",
|
||||||
env = "QPQ_STATE"
|
env = "QPQ_STATE"
|
||||||
)]
|
)]
|
||||||
state: PathBuf,
|
state: PathBuf,
|
||||||
@@ -203,7 +350,7 @@ enum Command {
|
|||||||
/// State file path (identity + MLS state).
|
/// State file path (identity + MLS state).
|
||||||
#[arg(
|
#[arg(
|
||||||
long,
|
long,
|
||||||
default_value = "qpq-state.bin",
|
default_value = "qpc-state.bin",
|
||||||
env = "QPQ_STATE"
|
env = "QPQ_STATE"
|
||||||
)]
|
)]
|
||||||
state: PathBuf,
|
state: PathBuf,
|
||||||
@@ -219,7 +366,7 @@ enum Command {
|
|||||||
/// State file path (identity + MLS state).
|
/// State file path (identity + MLS state).
|
||||||
#[arg(
|
#[arg(
|
||||||
long,
|
long,
|
||||||
default_value = "qpq-state.bin",
|
default_value = "qpc-state.bin",
|
||||||
env = "QPQ_STATE"
|
env = "QPQ_STATE"
|
||||||
)]
|
)]
|
||||||
state: PathBuf,
|
state: PathBuf,
|
||||||
@@ -234,7 +381,7 @@ enum Command {
|
|||||||
/// State file path (identity + MLS state).
|
/// State file path (identity + MLS state).
|
||||||
#[arg(
|
#[arg(
|
||||||
long,
|
long,
|
||||||
default_value = "qpq-state.bin",
|
default_value = "qpc-state.bin",
|
||||||
env = "QPQ_STATE"
|
env = "QPQ_STATE"
|
||||||
)]
|
)]
|
||||||
state: PathBuf,
|
state: PathBuf,
|
||||||
@@ -252,7 +399,7 @@ enum Command {
|
|||||||
Invite {
|
Invite {
|
||||||
#[arg(
|
#[arg(
|
||||||
long,
|
long,
|
||||||
default_value = "qpq-state.bin",
|
default_value = "qpc-state.bin",
|
||||||
env = "QPQ_STATE"
|
env = "QPQ_STATE"
|
||||||
)]
|
)]
|
||||||
state: PathBuf,
|
state: PathBuf,
|
||||||
@@ -267,7 +414,7 @@ enum Command {
|
|||||||
Join {
|
Join {
|
||||||
#[arg(
|
#[arg(
|
||||||
long,
|
long,
|
||||||
default_value = "qpq-state.bin",
|
default_value = "qpc-state.bin",
|
||||||
env = "QPQ_STATE"
|
env = "QPQ_STATE"
|
||||||
)]
|
)]
|
||||||
state: PathBuf,
|
state: PathBuf,
|
||||||
@@ -279,7 +426,7 @@ enum Command {
|
|||||||
Send {
|
Send {
|
||||||
#[arg(
|
#[arg(
|
||||||
long,
|
long,
|
||||||
default_value = "qpq-state.bin",
|
default_value = "qpc-state.bin",
|
||||||
env = "QPQ_STATE"
|
env = "QPQ_STATE"
|
||||||
)]
|
)]
|
||||||
state: PathBuf,
|
state: PathBuf,
|
||||||
@@ -300,7 +447,7 @@ enum Command {
|
|||||||
Recv {
|
Recv {
|
||||||
#[arg(
|
#[arg(
|
||||||
long,
|
long,
|
||||||
default_value = "qpq-state.bin",
|
default_value = "qpc-state.bin",
|
||||||
env = "QPQ_STATE"
|
env = "QPQ_STATE"
|
||||||
)]
|
)]
|
||||||
state: PathBuf,
|
state: PathBuf,
|
||||||
@@ -321,7 +468,7 @@ enum Command {
|
|||||||
Repl {
|
Repl {
|
||||||
#[arg(
|
#[arg(
|
||||||
long,
|
long,
|
||||||
default_value = "qpq-state.bin",
|
default_value = "qpc-state.bin",
|
||||||
env = "QPQ_STATE"
|
env = "QPQ_STATE"
|
||||||
)]
|
)]
|
||||||
state: PathBuf,
|
state: PathBuf,
|
||||||
@@ -333,7 +480,7 @@ enum Command {
|
|||||||
/// OPAQUE password (prompted securely if --username is set but --password is not).
|
/// OPAQUE password (prompted securely if --username is set but --password is not).
|
||||||
#[arg(long, env = "QPQ_PASSWORD")]
|
#[arg(long, env = "QPQ_PASSWORD")]
|
||||||
password: Option<String>,
|
password: Option<String>,
|
||||||
/// Do not auto-start a local qpq-server.
|
/// Do not auto-start a local qpc-server.
|
||||||
#[arg(long, env = "QPQ_NO_SERVER")]
|
#[arg(long, env = "QPQ_NO_SERVER")]
|
||||||
no_server: bool,
|
no_server: bool,
|
||||||
},
|
},
|
||||||
@@ -344,7 +491,7 @@ enum Command {
|
|||||||
Tui {
|
Tui {
|
||||||
#[arg(
|
#[arg(
|
||||||
long,
|
long,
|
||||||
default_value = "qpq-state.bin",
|
default_value = "qpc-state.bin",
|
||||||
env = "QPQ_STATE"
|
env = "QPQ_STATE"
|
||||||
)]
|
)]
|
||||||
state: PathBuf,
|
state: PathBuf,
|
||||||
@@ -358,12 +505,12 @@ enum Command {
|
|||||||
password: Option<String>,
|
password: Option<String>,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Interactive 1:1 chat: type to send, incoming messages printed as [peer] <msg>. Ctrl+D to exit.
|
/// Interactive 1:1 chat: type to send, incoming messages printed as \[peer\] msg. Ctrl+D to exit.
|
||||||
/// In a two-person group, peer is chosen automatically; use --peer-key only with 3+ members.
|
/// In a two-person group, peer is chosen automatically; use --peer-key only with 3+ members.
|
||||||
Chat {
|
Chat {
|
||||||
#[arg(
|
#[arg(
|
||||||
long,
|
long,
|
||||||
default_value = "qpq-state.bin",
|
default_value = "qpc-state.bin",
|
||||||
env = "QPQ_STATE"
|
env = "QPQ_STATE"
|
||||||
)]
|
)]
|
||||||
state: PathBuf,
|
state: PathBuf,
|
||||||
@@ -380,18 +527,18 @@ enum Command {
|
|||||||
/// Export a conversation's message history to an encrypted, tamper-evident transcript file.
|
/// Export a conversation's message history to an encrypted, tamper-evident transcript file.
|
||||||
///
|
///
|
||||||
/// The output file uses Argon2id + ChaCha20-Poly1305 encryption with a SHA-256 hash chain
|
/// The output file uses Argon2id + ChaCha20-Poly1305 encryption with a SHA-256 hash chain
|
||||||
/// linking every record. Use `qpq export verify` to check chain integrity without decrypting.
|
/// linking every record. Use `qpc export verify` to check chain integrity without decrypting.
|
||||||
Export {
|
Export {
|
||||||
/// Path to the conversation database (.convdb file).
|
/// Path to the conversation database (.convdb file).
|
||||||
#[arg(long, default_value = "qpq-convdb.sqlite", env = "QPQ_CONV_DB")]
|
#[arg(long, default_value = "qpc-convdb.sqlite", env = "QPQ_CONV_DB")]
|
||||||
conv_db: PathBuf,
|
conv_db: PathBuf,
|
||||||
|
|
||||||
/// Conversation ID to export (32 hex chars = 16 bytes).
|
/// Conversation ID to export (32 hex chars = 16 bytes).
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
conv_id: String,
|
conv_id: String,
|
||||||
|
|
||||||
/// Output path for the .qpqt transcript file.
|
/// Output path for the .qpct transcript file.
|
||||||
#[arg(long, default_value = "transcript.qpqt")]
|
#[arg(long, default_value = "transcript.qpct")]
|
||||||
output: PathBuf,
|
output: PathBuf,
|
||||||
|
|
||||||
/// Password used to encrypt the transcript (separate from the state/DB password).
|
/// Password used to encrypt the transcript (separate from the state/DB password).
|
||||||
@@ -405,7 +552,7 @@ enum Command {
|
|||||||
|
|
||||||
/// Verify the hash-chain integrity of a transcript file without decrypting content.
|
/// Verify the hash-chain integrity of a transcript file without decrypting content.
|
||||||
ExportVerify {
|
ExportVerify {
|
||||||
/// Path to the .qpqt transcript file to verify.
|
/// Path to the .qpct transcript file to verify.
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
input: PathBuf,
|
input: PathBuf,
|
||||||
},
|
},
|
||||||
@@ -418,7 +565,7 @@ enum Command {
|
|||||||
playbook: PathBuf,
|
playbook: PathBuf,
|
||||||
|
|
||||||
/// State file path (identity + MLS state).
|
/// State file path (identity + MLS state).
|
||||||
#[arg(long, default_value = "qpq-state.bin", env = "QPQ_STATE")]
|
#[arg(long, default_value = "qpc-state.bin", env = "QPQ_STATE")]
|
||||||
state: PathBuf,
|
state: PathBuf,
|
||||||
|
|
||||||
/// Server address (host:port).
|
/// Server address (host:port).
|
||||||
@@ -441,14 +588,14 @@ enum Command {
|
|||||||
|
|
||||||
// ── Helpers ───────────────────────────────────────────────────────────────────
|
// ── Helpers ───────────────────────────────────────────────────────────────────
|
||||||
#[cfg(not(feature = "v2"))]
|
#[cfg(not(feature = "v2"))]
|
||||||
/// Returns `qpq-{username}.bin` when `state` is still at the default
|
/// Returns `qpc-{username}.bin` when `state` is still at the default
|
||||||
/// (`qpq-state.bin`) and a username has been provided. Otherwise returns
|
/// (`qpc-state.bin`) and a username has been provided. Otherwise returns
|
||||||
/// `state` unchanged. This lets `qpq --username alice` automatically isolate
|
/// `state` unchanged. This lets `qpc --username alice` automatically isolate
|
||||||
/// Alice's state without requiring a manual `--state` flag.
|
/// Alice's state without requiring a manual `--state` flag.
|
||||||
fn derive_state_path(state: PathBuf, username: Option<&str>) -> PathBuf {
|
fn derive_state_path(state: PathBuf, username: Option<&str>) -> PathBuf {
|
||||||
if state == Path::new("qpq-state.bin") {
|
if state == Path::new("qpc-state.bin") {
|
||||||
if let Some(uname) = username {
|
if let Some(uname) = username {
|
||||||
return PathBuf::from(format!("qpq-{uname}.bin"));
|
return PathBuf::from(format!("qpc-{uname}.bin"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
state
|
state
|
||||||
@@ -470,24 +617,24 @@ async fn run_playbook(
|
|||||||
device_id: Option<&str>,
|
device_id: Option<&str>,
|
||||||
extra_vars: &[String],
|
extra_vars: &[String],
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
use quicproquo_client::PlaybookRunner;
|
use quicprochat_client::PlaybookRunner;
|
||||||
|
|
||||||
let insecure = std::env::var("QPQ_DANGER_ACCEPT_INVALID_CERTS").is_ok();
|
let insecure = std::env::var("QPQ_DANGER_ACCEPT_INVALID_CERTS").is_ok();
|
||||||
|
|
||||||
// Connect to server.
|
// Connect to server.
|
||||||
let client =
|
let client =
|
||||||
quicproquo_client::connect_node_opt(server, ca_cert, server_name, insecure)
|
quicprochat_client::connect_node_opt(server, ca_cert, server_name, insecure)
|
||||||
.await
|
.await
|
||||||
.context("connect to server")?;
|
.context("connect to server")?;
|
||||||
|
|
||||||
// Build session state.
|
// Build session state.
|
||||||
let mut session = quicproquo_client::client::session::SessionState::load(state, state_pw)
|
let mut session = quicprochat_client::client::session::SessionState::load(state, state_pw)
|
||||||
.context("load session state")?;
|
.context("load session state")?;
|
||||||
|
|
||||||
// If username/password provided, do OPAQUE login.
|
// If username/password provided, do OPAQUE login.
|
||||||
if let (Some(uname), Some(pw)) = (username, password) {
|
if let (Some(uname), Some(pw)) = (username, password) {
|
||||||
if let Err(e) =
|
if let Err(e) =
|
||||||
quicproquo_client::opaque_login(&client, uname, pw, &session.identity.public_key_bytes()).await
|
quicprochat_client::opaque_login(&client, uname, pw, &session.identity.public_key_bytes()).await
|
||||||
{
|
{
|
||||||
eprintln!("OPAQUE login failed: {e:#}");
|
eprintln!("OPAQUE login failed: {e:#}");
|
||||||
}
|
}
|
||||||
@@ -540,6 +687,13 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
)
|
)
|
||||||
.init();
|
.init();
|
||||||
|
|
||||||
|
// Load config file and apply to env BEFORE clap parses (so config values
|
||||||
|
// act as defaults that env vars and CLI flags can override).
|
||||||
|
{
|
||||||
|
let cfg = client_config::load_client_config();
|
||||||
|
client_config::apply_config_to_env(&cfg);
|
||||||
|
}
|
||||||
|
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
if args.danger_accept_invalid_certs {
|
if args.danger_accept_invalid_certs {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
//! v2 CLI command implementations — thin wrappers over the SDK.
|
//! v2 CLI command implementations — thin wrappers over the SDK.
|
||||||
|
|
||||||
use quicproquo_sdk::client::QpqClient;
|
use quicprochat_sdk::client::QpqClient;
|
||||||
use quicproquo_sdk::error::SdkError;
|
use quicprochat_sdk::error::SdkError;
|
||||||
|
|
||||||
/// Register a new user account via OPAQUE.
|
/// Register a new user account via OPAQUE.
|
||||||
pub async fn cmd_register_user(
|
pub async fn cmd_register_user(
|
||||||
@@ -61,7 +61,7 @@ pub async fn cmd_health(client: &mut QpqClient) -> Result<(), SdkError> {
|
|||||||
/// Resolve a username to its identity key.
|
/// Resolve a username to its identity key.
|
||||||
pub async fn cmd_resolve(client: &mut QpqClient, username: &str) -> Result<(), SdkError> {
|
pub async fn cmd_resolve(client: &mut QpqClient, username: &str) -> Result<(), SdkError> {
|
||||||
let rpc = client.rpc()?;
|
let rpc = client.rpc()?;
|
||||||
match quicproquo_sdk::users::resolve_user(rpc, username).await? {
|
match quicprochat_sdk::users::resolve_user(rpc, username).await? {
|
||||||
Some(key) => {
|
Some(key) => {
|
||||||
println!("{username} -> {}", hex::encode(&key));
|
println!("{username} -> {}", hex::encode(&key));
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,7 @@ pub async fn cmd_resolve(client: &mut QpqClient, username: &str) -> Result<(), S
|
|||||||
/// List registered devices.
|
/// List registered devices.
|
||||||
pub async fn cmd_devices_list(client: &mut QpqClient) -> Result<(), SdkError> {
|
pub async fn cmd_devices_list(client: &mut QpqClient) -> Result<(), SdkError> {
|
||||||
let rpc = client.rpc()?;
|
let rpc = client.rpc()?;
|
||||||
let devices = quicproquo_sdk::devices::list_devices(rpc).await?;
|
let devices = quicprochat_sdk::devices::list_devices(rpc).await?;
|
||||||
if devices.is_empty() {
|
if devices.is_empty() {
|
||||||
println!("no devices registered");
|
println!("no devices registered");
|
||||||
} else {
|
} else {
|
||||||
@@ -101,7 +101,7 @@ pub async fn cmd_devices_register(
|
|||||||
let rpc = client.rpc()?;
|
let rpc = client.rpc()?;
|
||||||
let id_bytes = hex::decode(device_id)
|
let id_bytes = hex::decode(device_id)
|
||||||
.map_err(|e| SdkError::Other(anyhow::anyhow!("invalid device_id hex: {e}")))?;
|
.map_err(|e| SdkError::Other(anyhow::anyhow!("invalid device_id hex: {e}")))?;
|
||||||
let was_new = quicproquo_sdk::devices::register_device(rpc, &id_bytes, device_name).await?;
|
let was_new = quicprochat_sdk::devices::register_device(rpc, &id_bytes, device_name).await?;
|
||||||
if was_new {
|
if was_new {
|
||||||
println!("device registered: {device_name}");
|
println!("device registered: {device_name}");
|
||||||
} else {
|
} else {
|
||||||
@@ -118,7 +118,7 @@ pub async fn cmd_devices_revoke(
|
|||||||
let rpc = client.rpc()?;
|
let rpc = client.rpc()?;
|
||||||
let id_bytes = hex::decode(device_id)
|
let id_bytes = hex::decode(device_id)
|
||||||
.map_err(|e| SdkError::Other(anyhow::anyhow!("invalid device_id hex: {e}")))?;
|
.map_err(|e| SdkError::Other(anyhow::anyhow!("invalid device_id hex: {e}")))?;
|
||||||
let revoked = quicproquo_sdk::devices::revoke_device(rpc, &id_bytes).await?;
|
let revoked = quicprochat_sdk::devices::revoke_device(rpc, &id_bytes).await?;
|
||||||
if revoked {
|
if revoked {
|
||||||
println!("device revoked: {device_id}");
|
println!("device revoked: {device_id}");
|
||||||
} else {
|
} else {
|
||||||
@@ -131,12 +131,12 @@ pub async fn cmd_devices_revoke(
|
|||||||
pub async fn cmd_recovery_setup(client: &mut QpqClient) -> Result<(), SdkError> {
|
pub async fn cmd_recovery_setup(client: &mut QpqClient) -> Result<(), SdkError> {
|
||||||
// Load identity seed from state file.
|
// Load identity seed from state file.
|
||||||
let state_path = client.config_state_path();
|
let state_path = client.config_state_path();
|
||||||
let stored = quicproquo_sdk::state::load_state(&state_path, None)
|
let stored = quicprochat_sdk::state::load_state(&state_path, None)
|
||||||
.map_err(|e| SdkError::Crypto(format!("load identity for recovery: {e}")))?;
|
.map_err(|e| SdkError::Crypto(format!("load identity for recovery: {e}")))?;
|
||||||
|
|
||||||
let rpc = client.rpc()?;
|
let rpc = client.rpc()?;
|
||||||
let codes =
|
let codes =
|
||||||
quicproquo_sdk::recovery::setup_recovery(rpc, &stored.identity_seed, &[]).await?;
|
quicprochat_sdk::recovery::setup_recovery(rpc, &stored.identity_seed, &[]).await?;
|
||||||
|
|
||||||
println!("=== RECOVERY CODES ===");
|
println!("=== RECOVERY CODES ===");
|
||||||
println!("Save these codes securely. They will NOT be shown again.");
|
println!("Save these codes securely. They will NOT be shown again.");
|
||||||
@@ -155,7 +155,7 @@ pub async fn cmd_recovery_setup(client: &mut QpqClient) -> Result<(), SdkError>
|
|||||||
/// List pending outbox entries.
|
/// List pending outbox entries.
|
||||||
pub fn cmd_outbox_list(client: &QpqClient) -> Result<(), SdkError> {
|
pub fn cmd_outbox_list(client: &QpqClient) -> Result<(), SdkError> {
|
||||||
let store = client.conversations()?;
|
let store = client.conversations()?;
|
||||||
let entries = quicproquo_sdk::outbox::list_pending(store)?;
|
let entries = quicprochat_sdk::outbox::list_pending(store)?;
|
||||||
if entries.is_empty() {
|
if entries.is_empty() {
|
||||||
println!("outbox is empty — no pending messages");
|
println!("outbox is empty — no pending messages");
|
||||||
} else {
|
} else {
|
||||||
@@ -178,7 +178,7 @@ pub fn cmd_outbox_list(client: &QpqClient) -> Result<(), SdkError> {
|
|||||||
pub async fn cmd_outbox_retry(client: &mut QpqClient) -> Result<(), SdkError> {
|
pub async fn cmd_outbox_retry(client: &mut QpqClient) -> Result<(), SdkError> {
|
||||||
let rpc = client.rpc()?;
|
let rpc = client.rpc()?;
|
||||||
let store = client.conversations()?;
|
let store = client.conversations()?;
|
||||||
let (sent, failed) = quicproquo_sdk::outbox::flush_outbox(rpc, store).await?;
|
let (sent, failed) = quicprochat_sdk::outbox::flush_outbox(rpc, store).await?;
|
||||||
println!("outbox flush: {sent} sent, {failed} permanently failed");
|
println!("outbox flush: {sent} sent, {failed} permanently failed");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -186,7 +186,7 @@ pub async fn cmd_outbox_retry(client: &mut QpqClient) -> Result<(), SdkError> {
|
|||||||
/// Clear permanently failed outbox entries.
|
/// Clear permanently failed outbox entries.
|
||||||
pub fn cmd_outbox_clear(client: &QpqClient) -> Result<(), SdkError> {
|
pub fn cmd_outbox_clear(client: &QpqClient) -> Result<(), SdkError> {
|
||||||
let store = client.conversations()?;
|
let store = client.conversations()?;
|
||||||
let cleared = quicproquo_sdk::outbox::clear_failed(store)?;
|
let cleared = quicprochat_sdk::outbox::clear_failed(store)?;
|
||||||
println!("cleared {cleared} failed outbox entries");
|
println!("cleared {cleared} failed outbox entries");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -198,10 +198,10 @@ pub async fn cmd_recovery_restore(
|
|||||||
) -> Result<(), SdkError> {
|
) -> Result<(), SdkError> {
|
||||||
let rpc = client.rpc()?;
|
let rpc = client.rpc()?;
|
||||||
let (identity_seed, conversation_ids) =
|
let (identity_seed, conversation_ids) =
|
||||||
quicproquo_sdk::recovery::recover_account(rpc, code).await?;
|
quicprochat_sdk::recovery::recover_account(rpc, code).await?;
|
||||||
|
|
||||||
// Restore identity.
|
// Restore identity.
|
||||||
let keypair = quicproquo_core::IdentityKeypair::from_seed(identity_seed);
|
let keypair = quicprochat_core::IdentityKeypair::from_seed(identity_seed);
|
||||||
client.set_identity_key(keypair.public_key_bytes().to_vec());
|
client.set_identity_key(keypair.public_key_bytes().to_vec());
|
||||||
|
|
||||||
println!("account recovered successfully");
|
println!("account recovered successfully");
|
||||||
@@ -214,14 +214,14 @@ pub async fn cmd_recovery_restore(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save recovered state.
|
// Save recovered state.
|
||||||
let state = quicproquo_sdk::state::StoredState {
|
let state = quicprochat_sdk::state::StoredState {
|
||||||
identity_seed,
|
identity_seed,
|
||||||
group: None,
|
group: None,
|
||||||
hybrid_key: None,
|
hybrid_key: None,
|
||||||
member_keys: Vec::new(),
|
member_keys: Vec::new(),
|
||||||
};
|
};
|
||||||
let state_path = client.config_state_path();
|
let state_path = client.config_state_path();
|
||||||
quicproquo_sdk::state::save_state(&state_path, &state, None)?;
|
quicprochat_sdk::state::save_state(&state_path, &state, None)?;
|
||||||
println!("state saved to {}", state_path.display());
|
println!("state saved to {}", state_path.display());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
//! v2 CLI entry point — thin shell over `quicproquo_sdk::QpqClient`.
|
//! v2 CLI entry point — thin shell over `quicprochat_sdk::QpqClient`.
|
||||||
//!
|
//!
|
||||||
//! Activated via `--features v2`. Replaces the v1 Cap'n Proto RPC main
|
//! Activated via `--features v2`. Replaces the v1 Cap'n Proto RPC main
|
||||||
//! with a simplified command surface backed by the SDK.
|
//! with a simplified command surface backed by the SDK.
|
||||||
@@ -10,15 +10,15 @@ use std::time::Duration;
|
|||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
|
||||||
use quicproquo_sdk::client::QpqClient;
|
use quicprochat_sdk::client::QpqClient;
|
||||||
use quicproquo_sdk::config::ClientConfig;
|
use quicprochat_sdk::config::ClientConfig;
|
||||||
|
|
||||||
use crate::v2_commands;
|
use crate::v2_commands;
|
||||||
|
|
||||||
// ── CLI ───────────────────────────────────────────────────────────────────────
|
// ── CLI ───────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
#[command(name = "qpq", about = "quicproquo CLI client (v2)", version)]
|
#[command(name = "qpc", about = "quicprochat CLI client (v2)", version)]
|
||||||
struct Args {
|
struct Args {
|
||||||
/// Server address (host:port).
|
/// Server address (host:port).
|
||||||
#[arg(long, global = true, default_value = "127.0.0.1:7000", env = "QPQ_SERVER")]
|
#[arg(long, global = true, default_value = "127.0.0.1:7000", env = "QPQ_SERVER")]
|
||||||
@@ -37,7 +37,7 @@ struct Args {
|
|||||||
db_password: Option<String>,
|
db_password: Option<String>,
|
||||||
|
|
||||||
/// Path to the client state file (identity key, MLS state).
|
/// Path to the client state file (identity key, MLS state).
|
||||||
#[arg(long, global = true, default_value = "qpq-state.bin", env = "QPQ_STATE")]
|
#[arg(long, global = true, default_value = "qpc-state.bin", env = "QPQ_STATE")]
|
||||||
state: PathBuf,
|
state: PathBuf,
|
||||||
|
|
||||||
/// DANGER: Skip TLS certificate verification. Development only.
|
/// DANGER: Skip TLS certificate verification. Development only.
|
||||||
@@ -48,7 +48,7 @@ struct Args {
|
|||||||
)]
|
)]
|
||||||
danger_accept_invalid_certs: bool,
|
danger_accept_invalid_certs: bool,
|
||||||
|
|
||||||
/// Do not auto-start a local qpq-server.
|
/// Do not auto-start a local qpc-server.
|
||||||
#[arg(long, global = true, env = "QPQ_NO_SERVER")]
|
#[arg(long, global = true, env = "QPQ_NO_SERVER")]
|
||||||
no_server: bool,
|
no_server: bool,
|
||||||
|
|
||||||
@@ -210,17 +210,17 @@ impl Drop for ServerGuard {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Find the `qpq-server` binary: same directory as current exe, then PATH.
|
/// Find the `qpc-server` binary: same directory as current exe, then PATH.
|
||||||
fn find_server_binary() -> Option<PathBuf> {
|
fn find_server_binary() -> Option<PathBuf> {
|
||||||
if let Ok(exe) = std::env::current_exe() {
|
if let Ok(exe) = std::env::current_exe() {
|
||||||
let sibling = exe.with_file_name("qpq-server");
|
let sibling = exe.with_file_name("qpc-server");
|
||||||
if sibling.exists() {
|
if sibling.exists() {
|
||||||
return Some(sibling);
|
return Some(sibling);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::env::var_os("PATH").and_then(|paths| {
|
std::env::var_os("PATH").and_then(|paths| {
|
||||||
std::env::split_paths(&paths)
|
std::env::split_paths(&paths)
|
||||||
.map(|dir| dir.join("qpq-server"))
|
.map(|dir| dir.join("qpc-server"))
|
||||||
.find(|p| p.exists())
|
.find(|p| p.exists())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -241,7 +241,7 @@ async fn probe_server(server_addr: &str) -> bool {
|
|||||||
.is_ok()
|
.is_ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Start a local qpq-server if one isn't already running.
|
/// Start a local qpc-server if one isn't already running.
|
||||||
/// Returns a guard that kills the child on drop (if we started one).
|
/// Returns a guard that kills the child on drop (if we started one).
|
||||||
async fn ensure_server_running(
|
async fn ensure_server_running(
|
||||||
server_addr: &str,
|
server_addr: &str,
|
||||||
@@ -258,8 +258,8 @@ async fn ensure_server_running(
|
|||||||
|
|
||||||
let binary = find_server_binary().ok_or_else(|| {
|
let binary = find_server_binary().ok_or_else(|| {
|
||||||
anyhow::anyhow!(
|
anyhow::anyhow!(
|
||||||
"server at {server_addr} is not reachable and qpq-server binary not found; \
|
"server at {server_addr} is not reachable and qpc-server binary not found; \
|
||||||
start a server manually or install qpq-server"
|
start a server manually or install qpc-server"
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
@@ -300,7 +300,7 @@ async fn ensure_server_running(
|
|||||||
|
|
||||||
if start.elapsed() > max_wait {
|
if start.elapsed() > max_wait {
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
"auto-started qpq-server but it did not become ready within {max_wait:?}"
|
"auto-started qpc-server but it did not become ready within {max_wait:?}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,9 +336,9 @@ async fn connect_client(args: &Args) -> anyhow::Result<QpqClient> {
|
|||||||
|
|
||||||
// Try loading identity from state file.
|
// Try loading identity from state file.
|
||||||
if args.state.exists() {
|
if args.state.exists() {
|
||||||
match quicproquo_sdk::state::load_state(&args.state, args.db_password.as_deref()) {
|
match quicprochat_sdk::state::load_state(&args.state, args.db_password.as_deref()) {
|
||||||
Ok(stored) => {
|
Ok(stored) => {
|
||||||
let keypair = quicproquo_core::IdentityKeypair::from_seed(stored.identity_seed);
|
let keypair = quicprochat_core::IdentityKeypair::from_seed(stored.identity_seed);
|
||||||
client.set_identity_key(keypair.public_key_bytes().to_vec());
|
client.set_identity_key(keypair.public_key_bytes().to_vec());
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@@ -414,13 +414,13 @@ async fn run(args: Args) -> anyhow::Result<()> {
|
|||||||
let config = build_config(&args)?;
|
let config = build_config(&args)?;
|
||||||
let mut client = QpqClient::new(config);
|
let mut client = QpqClient::new(config);
|
||||||
if args.state.exists() {
|
if args.state.exists() {
|
||||||
match quicproquo_sdk::state::load_state(
|
match quicprochat_sdk::state::load_state(
|
||||||
&args.state,
|
&args.state,
|
||||||
args.db_password.as_deref(),
|
args.db_password.as_deref(),
|
||||||
) {
|
) {
|
||||||
Ok(stored) => {
|
Ok(stored) => {
|
||||||
let keypair =
|
let keypair =
|
||||||
quicproquo_core::IdentityKeypair::from_seed(stored.identity_seed);
|
quicprochat_core::IdentityKeypair::from_seed(stored.identity_seed);
|
||||||
client.set_identity_key(keypair.public_key_bytes().to_vec());
|
client.set_identity_key(keypair.public_key_bytes().to_vec());
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// cargo_bin! only works for current package's binary; we spawn qpq-server from another package.
|
// cargo_bin! only works for current package's binary; we spawn qpc-server from another package.
|
||||||
#![allow(deprecated)]
|
#![allow(deprecated)]
|
||||||
#![allow(clippy::unwrap_used)]
|
#![allow(clippy::unwrap_used)]
|
||||||
#![allow(clippy::await_holding_lock)] // AUTH_LOCK intentionally held across await to serialize tests
|
#![allow(clippy::await_holding_lock)] // AUTH_LOCK intentionally held across await to serialize tests
|
||||||
@@ -18,12 +18,12 @@ fn ensure_rustls_provider() {
|
|||||||
|
|
||||||
use sha2::{Sha256, Digest};
|
use sha2::{Sha256, Digest};
|
||||||
|
|
||||||
use quicproquo_client::{
|
use quicprochat_client::{
|
||||||
cmd_create_group, cmd_invite, cmd_join, cmd_login, cmd_ping, cmd_register_state,
|
cmd_create_group, cmd_invite, cmd_join, cmd_login, cmd_ping, cmd_register_state,
|
||||||
cmd_register_user, cmd_send, connect_node, create_channel, enqueue, fetch_wait, init_auth,
|
cmd_register_user, cmd_send, connect_node, create_channel, enqueue, fetch_wait, init_auth,
|
||||||
opaque_login, receive_pending_plaintexts, resolve_user, ClientAuth,
|
opaque_login, receive_pending_plaintexts, resolve_user, ClientAuth,
|
||||||
};
|
};
|
||||||
use quicproquo_core::{GroupMember, HybridKeypair, IdentityKeypair, ReceivedMessage};
|
use quicprochat_core::{GroupMember, HybridKeypair, IdentityKeypair, ReceivedMessage};
|
||||||
|
|
||||||
/// Serialises ALL tests that call `init_auth` to prevent the global `AUTH_CONTEXT`
|
/// Serialises ALL tests that call `init_auth` to prevent the global `AUTH_CONTEXT`
|
||||||
/// from being overwritten by concurrent tests. Every test that mutates auth state
|
/// from being overwritten by concurrent tests. Every test that mutates auth state
|
||||||
@@ -71,7 +71,7 @@ fn spawn_server(base: &std::path::Path, extra_args: &[&str]) -> (String, PathBuf
|
|||||||
let tls_key = base.join("server-key.der");
|
let tls_key = base.join("server-key.der");
|
||||||
let data_dir = base.join("data");
|
let data_dir = base.join("data");
|
||||||
|
|
||||||
let server_bin = cargo_bin("qpq-server");
|
let server_bin = cargo_bin("qpc-server");
|
||||||
let mut cmd = Command::new(server_bin);
|
let mut cmd = Command::new(server_bin);
|
||||||
cmd.arg("--listen")
|
cmd.arg("--listen")
|
||||||
.arg(&listen)
|
.arg(&listen)
|
||||||
@@ -948,14 +948,14 @@ async fn e2e_dm_multi_message_epoch_synchronized() -> anyhow::Result<()> {
|
|||||||
/// Helper: load a state file and reconstruct a GroupMember with its keystore.
|
/// Helper: load a state file and reconstruct a GroupMember with its keystore.
|
||||||
fn load_member(state_path: &std::path::Path) -> (GroupMember, Option<HybridKeypair>) {
|
fn load_member(state_path: &std::path::Path) -> (GroupMember, Option<HybridKeypair>) {
|
||||||
let bytes = std::fs::read(state_path).expect("read state");
|
let bytes = std::fs::read(state_path).expect("read state");
|
||||||
let state: quicproquo_client::client::state::StoredState =
|
let state: quicprochat_client::client::state::StoredState =
|
||||||
bincode::deserialize(&bytes).expect("decode state");
|
bincode::deserialize(&bytes).expect("decode state");
|
||||||
state.into_parts(state_path).expect("into_parts")
|
state.into_parts(state_path).expect("into_parts")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper: save a GroupMember back to its state file.
|
/// Helper: save a GroupMember back to its state file.
|
||||||
fn save_member(state_path: &std::path::Path, member: &GroupMember, hybrid: Option<&HybridKeypair>) {
|
fn save_member(state_path: &std::path::Path, member: &GroupMember, hybrid: Option<&HybridKeypair>) {
|
||||||
quicproquo_client::client::state::save_state(state_path, member, hybrid, None)
|
quicprochat_client::client::state::save_state(state_path, member, hybrid, None)
|
||||||
.expect("save state");
|
.expect("save state");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1394,7 +1394,7 @@ async fn e2e_file_upload_download() -> anyhow::Result<()> {
|
|||||||
{
|
{
|
||||||
let mut p = req.get();
|
let mut p = req.get();
|
||||||
let mut auth = p.reborrow().init_auth();
|
let mut auth = p.reborrow().init_auth();
|
||||||
quicproquo_client::client::rpc::set_auth(&mut auth)?;
|
quicprochat_client::client::rpc::set_auth(&mut auth)?;
|
||||||
p.set_blob_hash(&hash);
|
p.set_blob_hash(&hash);
|
||||||
p.set_chunk(file_data);
|
p.set_chunk(file_data);
|
||||||
p.set_offset(0);
|
p.set_offset(0);
|
||||||
@@ -1426,7 +1426,7 @@ async fn e2e_file_upload_download() -> anyhow::Result<()> {
|
|||||||
{
|
{
|
||||||
let mut p = req.get();
|
let mut p = req.get();
|
||||||
let mut auth = p.reborrow().init_auth();
|
let mut auth = p.reborrow().init_auth();
|
||||||
quicproquo_client::client::rpc::set_auth(&mut auth)?;
|
quicprochat_client::client::rpc::set_auth(&mut auth)?;
|
||||||
p.set_blob_id(&blob_id);
|
p.set_blob_id(&blob_id);
|
||||||
p.set_offset(0);
|
p.set_offset(0);
|
||||||
p.set_length(file_data.len() as u32);
|
p.set_length(file_data.len() as u32);
|
||||||
@@ -1463,7 +1463,7 @@ async fn e2e_file_upload_download() -> anyhow::Result<()> {
|
|||||||
{
|
{
|
||||||
let mut p = req.get();
|
let mut p = req.get();
|
||||||
let mut auth = p.reborrow().init_auth();
|
let mut auth = p.reborrow().init_auth();
|
||||||
quicproquo_client::client::rpc::set_auth(&mut auth)?;
|
quicprochat_client::client::rpc::set_auth(&mut auth)?;
|
||||||
p.set_blob_id(&blob_id);
|
p.set_blob_id(&blob_id);
|
||||||
p.set_offset(100);
|
p.set_offset(100);
|
||||||
p.set_length(200);
|
p.set_length(200);
|
||||||
@@ -1521,7 +1521,7 @@ async fn e2e_blob_hash_mismatch() -> anyhow::Result<()> {
|
|||||||
{
|
{
|
||||||
let mut p = req.get();
|
let mut p = req.get();
|
||||||
let mut auth = p.reborrow().init_auth();
|
let mut auth = p.reborrow().init_auth();
|
||||||
quicproquo_client::client::rpc::set_auth(&mut auth)?;
|
quicprochat_client::client::rpc::set_auth(&mut auth)?;
|
||||||
p.set_blob_hash(&wrong_hash);
|
p.set_blob_hash(&wrong_hash);
|
||||||
p.set_chunk(&chunk_data[..]);
|
p.set_chunk(&chunk_data[..]);
|
||||||
p.set_offset(0);
|
p.set_offset(0);
|
||||||
@@ -1560,7 +1560,7 @@ fn spawn_server_custom(base: &std::path::Path, args: &[&str]) -> (String, PathBu
|
|||||||
let tls_key = base.join("server-key.der");
|
let tls_key = base.join("server-key.der");
|
||||||
let data_dir = base.join("data");
|
let data_dir = base.join("data");
|
||||||
|
|
||||||
let server_bin = cargo_bin("qpq-server");
|
let server_bin = cargo_bin("qpc-server");
|
||||||
let mut cmd = Command::new(server_bin);
|
let mut cmd = Command::new(server_bin);
|
||||||
cmd.arg("--listen")
|
cmd.arg("--listen")
|
||||||
.arg(&listen)
|
.arg(&listen)
|
||||||
@@ -1888,7 +1888,7 @@ async fn e2e_keypackage_exhaustion_graceful() -> anyhow::Result<()> {
|
|||||||
// Now try to fetch A's KeyPackage again — it should be exhausted.
|
// Now try to fetch A's KeyPackage again — it should be exhausted.
|
||||||
let client = local.run_until(connect_node(&server, &ca_cert, "localhost")).await?;
|
let client = local.run_until(connect_node(&server, &ca_cert, "localhost")).await?;
|
||||||
let pkg = local
|
let pkg = local
|
||||||
.run_until(quicproquo_client::client::rpc::fetch_key_package(&client, &a_pk))
|
.run_until(quicprochat_client::client::rpc::fetch_key_package(&client, &a_pk))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// Graceful: either empty (no package available) or an error — but NOT a panic.
|
// Graceful: either empty (no package available) or an error — but NOT a panic.
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "quicproquo-core"
|
name = "quicprochat-core"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition.workspace = true
|
||||||
description = "Crypto primitives, MLS state machine, and hybrid post-quantum KEM for quicproquo."
|
description = "Crypto primitives, MLS state machine, and hybrid post-quantum KEM for quicprochat."
|
||||||
license = "MIT"
|
license = "Apache-2.0 OR MIT"
|
||||||
|
repository.workspace = true
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["native"]
|
default = ["native"]
|
||||||
@@ -14,11 +15,12 @@ native = [
|
|||||||
"dep:openmls",
|
"dep:openmls",
|
||||||
"dep:openmls_rust_crypto",
|
"dep:openmls_rust_crypto",
|
||||||
"dep:openmls_traits",
|
"dep:openmls_traits",
|
||||||
|
"dep:openmls_memory_storage",
|
||||||
"dep:tls_codec",
|
"dep:tls_codec",
|
||||||
"dep:opaque-ke",
|
"dep:opaque-ke",
|
||||||
"dep:bincode",
|
"dep:bincode",
|
||||||
"dep:capnp",
|
"dep:capnp",
|
||||||
"dep:quicproquo-proto",
|
"dep:quicprochat-proto",
|
||||||
"dep:tokio",
|
"dep:tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -48,12 +50,13 @@ opaque-ke = { workspace = true, optional = true }
|
|||||||
openmls = { workspace = true, optional = true }
|
openmls = { workspace = true, optional = true }
|
||||||
openmls_rust_crypto = { workspace = true, optional = true }
|
openmls_rust_crypto = { workspace = true, optional = true }
|
||||||
openmls_traits = { workspace = true, optional = true }
|
openmls_traits = { workspace = true, optional = true }
|
||||||
|
openmls_memory_storage = { workspace = true, optional = true }
|
||||||
tls_codec = { workspace = true, optional = true }
|
tls_codec = { workspace = true, optional = true }
|
||||||
bincode = { workspace = true, optional = true }
|
bincode = { workspace = true, optional = true }
|
||||||
|
|
||||||
# Serialisation (native only)
|
# Serialisation (native only)
|
||||||
capnp = { workspace = true, optional = true }
|
capnp = { workspace = true, optional = true }
|
||||||
quicproquo-proto = { path = "../quicproquo-proto", optional = true }
|
quicprochat-proto = { path = "../quicprochat-proto", optional = true }
|
||||||
|
|
||||||
# Async runtime (native only)
|
# Async runtime (native only)
|
||||||
tokio = { workspace = true, optional = true }
|
tokio = { workspace = true, optional = true }
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
|
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
|
||||||
|
|
||||||
use quicproquo_core::{compute_safety_number, IdentityKeypair, padding};
|
use quicprochat_core::{compute_safety_number, IdentityKeypair, padding};
|
||||||
|
|
||||||
// ── Identity keypair benchmarks ──────────────────────────────────────────────
|
// ── Identity keypair benchmarks ──────────────────────────────────────────────
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ fn bench_identity_verify(c: &mut Criterion) {
|
|||||||
// ── Sealed sender benchmarks ─────────────────────────────────────────────────
|
// ── Sealed sender benchmarks ─────────────────────────────────────────────────
|
||||||
|
|
||||||
fn bench_sealed_sender(c: &mut Criterion) {
|
fn bench_sealed_sender(c: &mut Criterion) {
|
||||||
use quicproquo_core::sealed_sender::{seal, unseal};
|
use quicprochat_core::sealed_sender::{seal, unseal};
|
||||||
|
|
||||||
let sizes: &[(&str, usize)] = &[
|
let sizes: &[(&str, usize)] = &[
|
||||||
("32B", 32),
|
("32B", 32),
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
|
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
|
||||||
|
|
||||||
use quicproquo_core::{hybrid_encrypt, hybrid_decrypt, HybridKeypair};
|
use quicprochat_core::{hybrid_encrypt, hybrid_decrypt, HybridKeypair};
|
||||||
|
|
||||||
// ── Classical baseline (X25519 + ChaCha20-Poly1305) ─────────────────────────
|
// ── Classical baseline (X25519 + ChaCha20-Poly1305) ─────────────────────────
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion};
|
use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion};
|
||||||
use quicproquo_core::{GroupMember, IdentityKeypair};
|
use quicprochat_core::{GroupMember, IdentityKeypair};
|
||||||
|
|
||||||
/// Create identities and a group of the given size.
|
/// Create identities and a group of the given size.
|
||||||
/// Returns (creator, Vec<members>).
|
/// Returns (creator, Vec<members>).
|
||||||
@@ -11,17 +11,17 @@ use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criteri
|
|||||||
fn capnp_serialize_envelope(seq: u64, data: &[u8]) -> Vec<u8> {
|
fn capnp_serialize_envelope(seq: u64, data: &[u8]) -> Vec<u8> {
|
||||||
let mut msg = capnp::message::Builder::new_default();
|
let mut msg = capnp::message::Builder::new_default();
|
||||||
{
|
{
|
||||||
let mut envelope = msg.init_root::<quicproquo_proto::node_capnp::envelope::Builder>();
|
let mut envelope = msg.init_root::<quicprochat_proto::node_capnp::envelope::Builder>();
|
||||||
envelope.set_seq(seq);
|
envelope.set_seq(seq);
|
||||||
envelope.set_data(data);
|
envelope.set_data(data);
|
||||||
}
|
}
|
||||||
quicproquo_proto::to_bytes(&msg).unwrap()
|
quicprochat_proto::to_bytes(&msg).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn capnp_deserialize_envelope(bytes: &[u8]) -> (u64, Vec<u8>) {
|
fn capnp_deserialize_envelope(bytes: &[u8]) -> (u64, Vec<u8>) {
|
||||||
let reader = quicproquo_proto::from_bytes(bytes).unwrap();
|
let reader = quicprochat_proto::from_bytes(bytes).unwrap();
|
||||||
let envelope = reader
|
let envelope = reader
|
||||||
.get_root::<quicproquo_proto::node_capnp::envelope::Reader>()
|
.get_root::<quicprochat_proto::node_capnp::envelope::Reader>()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
(envelope.get_seq(), envelope.get_data().unwrap().to_vec())
|
(envelope.get_seq(), envelope.get_data().unwrap().to_vec())
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
package quicproquo.bench;
|
package quicprochat.bench;
|
||||||
|
|
||||||
// Equivalent to the Envelope struct in delivery.capnp
|
// Equivalent to the Envelope struct in delivery.capnp
|
||||||
message Envelope {
|
message Envelope {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
//! Error types for `quicproquo-core`.
|
//! Error types for `quicprochat-core`.
|
||||||
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
//! # Ratchet tree
|
//! # Ratchet tree
|
||||||
//!
|
//!
|
||||||
//! `use_ratchet_tree_extension = true` so that the ratchet tree is embedded
|
//! `use_ratchet_tree_extension = true` so that the ratchet tree is embedded
|
||||||
//! in Welcome messages. `new_from_welcome` is called with `ratchet_tree = None`;
|
//! in Welcome messages. `new_from_welcome` is called without a ratchet_tree;
|
||||||
//! openmls extracts the tree from the Welcome's `GroupInfo` extension.
|
//! openmls extracts the tree from the Welcome's `GroupInfo` extension.
|
||||||
|
|
||||||
use std::{path::Path, sync::Arc};
|
use std::{path::Path, sync::Arc};
|
||||||
@@ -37,12 +37,13 @@ use std::{path::Path, sync::Arc};
|
|||||||
use zeroize::Zeroizing;
|
use zeroize::Zeroizing;
|
||||||
|
|
||||||
use openmls::prelude::{
|
use openmls::prelude::{
|
||||||
Ciphersuite, Credential, CredentialType, CredentialWithKey, CryptoConfig, GroupId, KeyPackage,
|
BasicCredential, Ciphersuite, Credential, CredentialWithKey, GroupId, KeyPackage,
|
||||||
KeyPackageIn, MlsGroup, MlsGroupConfig, MlsMessageInBody, MlsMessageOut,
|
KeyPackageIn, LeafNodeParameters, MlsGroup, MlsGroupCreateConfig, MlsGroupJoinConfig,
|
||||||
ProcessedMessageContent, ProtocolMessage, ProtocolVersion, TlsDeserializeTrait,
|
MlsMessageBodyIn, MlsMessageOut, ProcessedMessageContent, ProtocolMessage,
|
||||||
TlsSerializeTrait,
|
ProtocolVersion, StagedWelcome,
|
||||||
};
|
};
|
||||||
use openmls_traits::OpenMlsCryptoProvider;
|
use openmls_traits::OpenMlsProvider;
|
||||||
|
use tls_codec::{Deserialize as TlsDeserializeTrait, Serialize as TlsSerializeTrait};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
error::CoreError,
|
error::CoreError,
|
||||||
@@ -102,8 +103,10 @@ pub struct GroupMember {
|
|||||||
identity: Arc<IdentityKeypair>,
|
identity: Arc<IdentityKeypair>,
|
||||||
/// Active MLS group, if any.
|
/// Active MLS group, if any.
|
||||||
group: Option<MlsGroup>,
|
group: Option<MlsGroup>,
|
||||||
/// Shared group configuration (wire format, ratchet tree extension, etc.).
|
/// Shared group creation configuration (wire format, ratchet tree extension, etc.).
|
||||||
config: MlsGroupConfig,
|
create_config: MlsGroupCreateConfig,
|
||||||
|
/// Shared group join configuration (wire format, ratchet tree extension, etc.).
|
||||||
|
join_config: MlsGroupJoinConfig,
|
||||||
/// Whether this member uses hybrid (X25519 + ML-KEM-768) HPKE keys.
|
/// Whether this member uses hybrid (X25519 + ML-KEM-768) HPKE keys.
|
||||||
hybrid: bool,
|
hybrid: bool,
|
||||||
}
|
}
|
||||||
@@ -139,7 +142,11 @@ impl GroupMember {
|
|||||||
group: Option<MlsGroup>,
|
group: Option<MlsGroup>,
|
||||||
hybrid: bool,
|
hybrid: bool,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let config = MlsGroupConfig::builder()
|
let create_config = MlsGroupCreateConfig::builder()
|
||||||
|
.use_ratchet_tree_extension(true)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
let join_config = MlsGroupJoinConfig::builder()
|
||||||
.use_ratchet_tree_extension(true)
|
.use_ratchet_tree_extension(true)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@@ -153,7 +160,8 @@ impl GroupMember {
|
|||||||
backend,
|
backend,
|
||||||
identity,
|
identity,
|
||||||
group,
|
group,
|
||||||
config,
|
create_config,
|
||||||
|
join_config,
|
||||||
hybrid,
|
hybrid,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -175,18 +183,19 @@ impl GroupMember {
|
|||||||
///
|
///
|
||||||
/// Returns [`CoreError::Mls`] if openmls fails to create the KeyPackage.
|
/// Returns [`CoreError::Mls`] if openmls fails to create the KeyPackage.
|
||||||
pub fn generate_key_package(&mut self) -> Result<Vec<u8>, CoreError> {
|
pub fn generate_key_package(&mut self) -> Result<Vec<u8>, CoreError> {
|
||||||
let credential_with_key = self.make_credential_with_key()?;
|
let credential_with_key = self.make_credential_with_key();
|
||||||
|
|
||||||
let key_package = KeyPackage::builder()
|
let key_package_bundle = KeyPackage::builder()
|
||||||
.build(
|
.build(
|
||||||
CryptoConfig::with_default_version(CIPHERSUITE),
|
CIPHERSUITE,
|
||||||
&self.backend,
|
&self.backend,
|
||||||
self.identity.as_ref(),
|
self.identity.as_ref(),
|
||||||
credential_with_key,
|
credential_with_key,
|
||||||
)
|
)
|
||||||
.map_err(|e| CoreError::Mls(format!("{e:?}")))?;
|
.map_err(|e| CoreError::Mls(format!("{e:?}")))?;
|
||||||
|
|
||||||
key_package
|
key_package_bundle
|
||||||
|
.key_package()
|
||||||
.tls_serialize_detached()
|
.tls_serialize_detached()
|
||||||
.map_err(|e| CoreError::Mls(format!("{e:?}")))
|
.map_err(|e| CoreError::Mls(format!("{e:?}")))
|
||||||
}
|
}
|
||||||
@@ -205,13 +214,13 @@ impl GroupMember {
|
|||||||
///
|
///
|
||||||
/// Returns [`CoreError::Mls`] if the group already exists or openmls fails.
|
/// Returns [`CoreError::Mls`] if the group already exists or openmls fails.
|
||||||
pub fn create_group(&mut self, group_id: &[u8]) -> Result<(), CoreError> {
|
pub fn create_group(&mut self, group_id: &[u8]) -> Result<(), CoreError> {
|
||||||
let credential_with_key = self.make_credential_with_key()?;
|
let credential_with_key = self.make_credential_with_key();
|
||||||
let mls_id = GroupId::from_slice(group_id);
|
let mls_id = GroupId::from_slice(group_id);
|
||||||
|
|
||||||
let group = MlsGroup::new_with_group_id(
|
let group = MlsGroup::new_with_group_id(
|
||||||
&self.backend,
|
&self.backend,
|
||||||
self.identity.as_ref(),
|
self.identity.as_ref(),
|
||||||
&self.config,
|
&self.create_config,
|
||||||
mls_id,
|
mls_id,
|
||||||
credential_with_key,
|
credential_with_key,
|
||||||
)
|
)
|
||||||
@@ -303,7 +312,7 @@ impl GroupMember {
|
|||||||
|
|
||||||
let leaf_index = group
|
let leaf_index = group
|
||||||
.members()
|
.members()
|
||||||
.find(|m| m.credential.identity() == member_identity)
|
.find(|m| m.credential.serialized_content() == member_identity)
|
||||||
.map(|m| m.index)
|
.map(|m| m.index)
|
||||||
.ok_or_else(|| CoreError::Mls("member not found in group".into()))?;
|
.ok_or_else(|| CoreError::Mls("member not found in group".into()))?;
|
||||||
|
|
||||||
@@ -384,7 +393,11 @@ impl GroupMember {
|
|||||||
.ok_or_else(|| CoreError::Mls("no active group".into()))?;
|
.ok_or_else(|| CoreError::Mls("no active group".into()))?;
|
||||||
|
|
||||||
let (proposal_out, _ref) = group
|
let (proposal_out, _ref) = group
|
||||||
.propose_self_update(&self.backend, self.identity.as_ref(), None)
|
.propose_self_update(
|
||||||
|
&self.backend,
|
||||||
|
self.identity.as_ref(),
|
||||||
|
LeafNodeParameters::default(),
|
||||||
|
)
|
||||||
.map_err(|e| CoreError::Mls(format!("propose_self_update: {e:?}")))?;
|
.map_err(|e| CoreError::Mls(format!("propose_self_update: {e:?}")))?;
|
||||||
|
|
||||||
proposal_out
|
proposal_out
|
||||||
@@ -396,7 +409,7 @@ impl GroupMember {
|
|||||||
pub fn has_pending_proposals(&self) -> bool {
|
pub fn has_pending_proposals(&self) -> bool {
|
||||||
self.group
|
self.group
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|g| g.pending_proposals().next().is_some())
|
.map(|g| g.has_pending_proposals())
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -417,16 +430,22 @@ impl GroupMember {
|
|||||||
let msg_in = openmls::prelude::MlsMessageIn::tls_deserialize(&mut welcome_bytes)
|
let msg_in = openmls::prelude::MlsMessageIn::tls_deserialize(&mut welcome_bytes)
|
||||||
.map_err(|e| CoreError::Mls(format!("Welcome deserialise: {e:?}")))?;
|
.map_err(|e| CoreError::Mls(format!("Welcome deserialise: {e:?}")))?;
|
||||||
|
|
||||||
// into_welcome() is feature-gated in openmls 0.5; extract() is public.
|
|
||||||
let welcome = match msg_in.extract() {
|
let welcome = match msg_in.extract() {
|
||||||
MlsMessageInBody::Welcome(w) => w,
|
MlsMessageBodyIn::Welcome(w) => w,
|
||||||
_ => return Err(CoreError::Mls("expected a Welcome message".into())),
|
_ => return Err(CoreError::Mls("expected a Welcome message".into())),
|
||||||
};
|
};
|
||||||
|
|
||||||
// ratchet_tree = None because use_ratchet_tree_extension = true embeds
|
let staged = StagedWelcome::new_from_welcome(
|
||||||
// the tree inside the Welcome's GroupInfo extension.
|
&self.backend,
|
||||||
let group = MlsGroup::new_from_welcome(&self.backend, &self.config, welcome, None)
|
&self.join_config,
|
||||||
.map_err(|e| CoreError::Mls(format!("new_from_welcome: {e:?}")))?;
|
welcome,
|
||||||
|
None, // ratchet tree extracted from the Welcome's GroupInfo extension
|
||||||
|
)
|
||||||
|
.map_err(|e| CoreError::Mls(format!("new_from_welcome: {e:?}")))?;
|
||||||
|
|
||||||
|
let group = staged
|
||||||
|
.into_group(&self.backend)
|
||||||
|
.map_err(|e| CoreError::Mls(format!("into_group: {e:?}")))?;
|
||||||
|
|
||||||
self.group = Some(group);
|
self.group = Some(group);
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -508,10 +527,9 @@ impl GroupMember {
|
|||||||
let msg_in = openmls::prelude::MlsMessageIn::tls_deserialize(&mut bytes)
|
let msg_in = openmls::prelude::MlsMessageIn::tls_deserialize(&mut bytes)
|
||||||
.map_err(|e| CoreError::Mls(format!("message deserialise: {e:?}")))?;
|
.map_err(|e| CoreError::Mls(format!("message deserialise: {e:?}")))?;
|
||||||
|
|
||||||
// into_protocol_message() is feature-gated; extract() + manual construction is not.
|
let protocol_message: ProtocolMessage = match msg_in.extract() {
|
||||||
let protocol_message = match msg_in.extract() {
|
MlsMessageBodyIn::PrivateMessage(m) => m.into(),
|
||||||
MlsMessageInBody::PrivateMessage(m) => ProtocolMessage::PrivateMessage(m),
|
MlsMessageBodyIn::PublicMessage(m) => m.into(),
|
||||||
MlsMessageInBody::PublicMessage(m) => ProtocolMessage::PublicMessage(m),
|
|
||||||
_ => return Err(CoreError::Mls("not a protocol message".into())),
|
_ => return Err(CoreError::Mls("not a protocol message".into())),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -519,7 +537,7 @@ impl GroupMember {
|
|||||||
.process_message(&self.backend, protocol_message)
|
.process_message(&self.backend, protocol_message)
|
||||||
.map_err(|e| CoreError::Mls(format!("process_message: {e:?}")))?;
|
.map_err(|e| CoreError::Mls(format!("process_message: {e:?}")))?;
|
||||||
|
|
||||||
let sender_identity = processed.credential().identity().to_vec();
|
let sender_identity = processed.credential().serialized_content().to_vec();
|
||||||
|
|
||||||
match processed.into_content() {
|
match processed.into_content() {
|
||||||
ProcessedMessageContent::ApplicationMessage(app) => {
|
ProcessedMessageContent::ApplicationMessage(app) => {
|
||||||
@@ -545,11 +563,15 @@ impl GroupMember {
|
|||||||
}
|
}
|
||||||
// Proposals are stored for a later Commit; nothing to return yet.
|
// Proposals are stored for a later Commit; nothing to return yet.
|
||||||
ProcessedMessageContent::ProposalMessage(proposal) => {
|
ProcessedMessageContent::ProposalMessage(proposal) => {
|
||||||
group.store_pending_proposal(*proposal);
|
group
|
||||||
|
.store_pending_proposal(self.backend.storage(), *proposal)
|
||||||
|
.map_err(|e| CoreError::Mls(format!("store_pending_proposal: {e:?}")))?;
|
||||||
Ok((sender_identity, ReceivedMessage::StateChanged))
|
Ok((sender_identity, ReceivedMessage::StateChanged))
|
||||||
}
|
}
|
||||||
ProcessedMessageContent::ExternalJoinProposalMessage(proposal) => {
|
ProcessedMessageContent::ExternalJoinProposalMessage(proposal) => {
|
||||||
group.store_pending_proposal(*proposal);
|
group
|
||||||
|
.store_pending_proposal(self.backend.storage(), *proposal)
|
||||||
|
.map_err(|e| CoreError::Mls(format!("store_pending_proposal: {e:?}")))?;
|
||||||
Ok((sender_identity, ReceivedMessage::StateChanged))
|
Ok((sender_identity, ReceivedMessage::StateChanged))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -597,6 +619,69 @@ impl GroupMember {
|
|||||||
self.group.as_ref()
|
self.group.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Serialize the MLS group state (via the backing `StorageProvider`).
|
||||||
|
///
|
||||||
|
/// In openmls 0.8 the `MlsGroup` is no longer `Serialize`; its state is
|
||||||
|
/// held inside the `StorageProvider`. This method serializes the full
|
||||||
|
/// provider storage to bytes, which can later be restored with
|
||||||
|
/// [`new_from_storage_bytes`].
|
||||||
|
///
|
||||||
|
/// Returns `None` if no active group exists.
|
||||||
|
///
|
||||||
|
/// [`new_from_storage_bytes`]: Self::new_from_storage_bytes
|
||||||
|
pub fn serialize_mls_state(&self) -> Result<Option<Vec<u8>>, CoreError> {
|
||||||
|
if self.group.is_none() {
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
let bytes = self
|
||||||
|
.backend
|
||||||
|
.storage()
|
||||||
|
.to_bytes()
|
||||||
|
.map_err(|e| CoreError::Mls(format!("serialize storage: {e}")))?;
|
||||||
|
Ok(Some(bytes))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a `GroupMember` from previously serialized storage bytes.
|
||||||
|
///
|
||||||
|
/// Reconstructs the `DiskKeyStore` from the blob, then loads the
|
||||||
|
/// `MlsGroup` from the storage provider using the given `group_id`.
|
||||||
|
pub fn new_from_storage_bytes(
|
||||||
|
identity: Arc<IdentityKeypair>,
|
||||||
|
storage_bytes: &[u8],
|
||||||
|
group_id: &[u8],
|
||||||
|
hybrid: bool,
|
||||||
|
) -> Result<Self, CoreError> {
|
||||||
|
let key_store = DiskKeyStore::from_bytes(storage_bytes)
|
||||||
|
.map_err(|e| CoreError::Mls(format!("deserialize storage: {e}")))?;
|
||||||
|
|
||||||
|
let create_config = MlsGroupCreateConfig::builder()
|
||||||
|
.use_ratchet_tree_extension(true)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
let join_config = MlsGroupJoinConfig::builder()
|
||||||
|
.use_ratchet_tree_extension(true)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
let backend = if hybrid {
|
||||||
|
HybridCryptoProvider::new_hybrid(key_store)
|
||||||
|
} else {
|
||||||
|
HybridCryptoProvider::new_classical(key_store)
|
||||||
|
};
|
||||||
|
|
||||||
|
let mls_group_id = GroupId::from_slice(group_id);
|
||||||
|
let group = MlsGroup::load(backend.storage(), &mls_group_id)
|
||||||
|
.map_err(|e| CoreError::Mls(format!("load group from storage: {e}")))?;
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
|
backend,
|
||||||
|
identity,
|
||||||
|
group,
|
||||||
|
create_config,
|
||||||
|
join_config,
|
||||||
|
hybrid,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// Return the identity (credential) bytes of all current group members.
|
/// Return the identity (credential) bytes of all current group members.
|
||||||
///
|
///
|
||||||
/// Each entry is the raw credential payload (Ed25519 public key bytes)
|
/// Each entry is the raw credential payload (Ed25519 public key bytes)
|
||||||
@@ -608,23 +693,20 @@ impl GroupMember {
|
|||||||
};
|
};
|
||||||
group
|
group
|
||||||
.members()
|
.members()
|
||||||
.map(|m| m.credential.identity().to_vec())
|
.map(|m| m.credential.serialized_content().to_vec())
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Private helpers ───────────────────────────────────────────────────────
|
// ── Private helpers ───────────────────────────────────────────────────────
|
||||||
|
|
||||||
fn make_credential_with_key(&self) -> Result<CredentialWithKey, CoreError> {
|
fn make_credential_with_key(&self) -> CredentialWithKey {
|
||||||
let credential = Credential::new(
|
let credential: Credential =
|
||||||
self.identity.public_key_bytes().to_vec(),
|
BasicCredential::new(self.identity.public_key_bytes().to_vec()).into();
|
||||||
CredentialType::Basic,
|
|
||||||
)
|
|
||||||
.map_err(|e| CoreError::Mls(format!("{e:?}")))?;
|
|
||||||
|
|
||||||
Ok(CredentialWithKey {
|
CredentialWithKey {
|
||||||
credential,
|
credential,
|
||||||
signature_key: self.identity.public_key_bytes().to_vec().into(),
|
signature_key: self.identity.public_key_bytes().to_vec().into(),
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -758,11 +840,6 @@ mod tests {
|
|||||||
let (_commit_a, welcome_a) = creator.add_member(&a_kp).expect("add A");
|
let (_commit_a, welcome_a) = creator.add_member(&a_kp).expect("add A");
|
||||||
a.join_group(&welcome_a).expect("A join");
|
a.join_group(&welcome_a).expect("A join");
|
||||||
|
|
||||||
// A must process the commit that added them (it's a StateChanged for A since
|
|
||||||
// the commit itself is what brought them in — but actually A joined via Welcome,
|
|
||||||
// so A doesn't process the add-commit). The creator already merged the pending
|
|
||||||
// commit in add_member, so creator is at epoch 2.
|
|
||||||
|
|
||||||
// Add B — at this point creator is at epoch 2 (after adding A).
|
// Add B — at this point creator is at epoch 2 (after adding A).
|
||||||
let (commit_b, welcome_b) = creator.add_member(&b_kp).expect("add B");
|
let (commit_b, welcome_b) = creator.add_member(&b_kp).expect("add B");
|
||||||
b.join_group(&welcome_b).expect("B join");
|
b.join_group(&welcome_b).expect("B join");
|
||||||
@@ -958,7 +1035,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 10 messages alternating Alice→Bob and Bob→Alice all decrypt successfully.
|
/// 10 messages alternating Alice->Bob and Bob->Alice all decrypt successfully.
|
||||||
/// Verifies that epoch state stays in sync across multiple application messages.
|
/// Verifies that epoch state stays in sync across multiple application messages.
|
||||||
#[test]
|
#[test]
|
||||||
fn multi_message_roundtrip_epoch_stays_in_sync() {
|
fn multi_message_roundtrip_epoch_stays_in_sync() {
|
||||||
@@ -27,8 +27,9 @@ use openmls_traits::{
|
|||||||
crypto::OpenMlsCrypto,
|
crypto::OpenMlsCrypto,
|
||||||
types::{
|
types::{
|
||||||
CryptoError, ExporterSecret, HpkeCiphertext, HpkeConfig, HpkeKeyPair, HpkeKemType,
|
CryptoError, ExporterSecret, HpkeCiphertext, HpkeConfig, HpkeKeyPair, HpkeKemType,
|
||||||
|
KemOutput,
|
||||||
},
|
},
|
||||||
OpenMlsCryptoProvider,
|
OpenMlsProvider,
|
||||||
};
|
};
|
||||||
use tls_codec::SecretVLBytes;
|
use tls_codec::SecretVLBytes;
|
||||||
|
|
||||||
@@ -128,6 +129,15 @@ impl OpenMlsCrypto for HybridCrypto {
|
|||||||
self.rust_crypto.hkdf_extract(hash_type, salt, ikm)
|
self.rust_crypto.hkdf_extract(hash_type, salt, ikm)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn hmac(
|
||||||
|
&self,
|
||||||
|
hash_type: HashType,
|
||||||
|
key: &[u8],
|
||||||
|
message: &[u8],
|
||||||
|
) -> Result<SecretVLBytes, CryptoError> {
|
||||||
|
self.rust_crypto.hmac(hash_type, key, message)
|
||||||
|
}
|
||||||
|
|
||||||
fn hkdf_expand(
|
fn hkdf_expand(
|
||||||
&self,
|
&self,
|
||||||
hash_type: HashType,
|
hash_type: HashType,
|
||||||
@@ -189,25 +199,18 @@ impl OpenMlsCrypto for HybridCrypto {
|
|||||||
info: &[u8],
|
info: &[u8],
|
||||||
aad: &[u8],
|
aad: &[u8],
|
||||||
ptxt: &[u8],
|
ptxt: &[u8],
|
||||||
) -> HpkeCiphertext {
|
) -> Result<HpkeCiphertext, CryptoError> {
|
||||||
if Self::is_hybrid_public_key(pk_r) {
|
if Self::is_hybrid_public_key(pk_r) {
|
||||||
// The trait `OpenMlsCrypto::hpke_seal` returns `HpkeCiphertext` (not
|
|
||||||
// `Result`), so we cannot propagate errors through the return type.
|
|
||||||
// Returning an empty ciphertext would silently cause data loss.
|
|
||||||
// Instead, panic on failure — a hybrid key that passes the length
|
|
||||||
// check but fails deserialization or encryption indicates a critical
|
|
||||||
// bug (corrupted key material), not a recoverable condition.
|
|
||||||
let recipient_pk = HybridPublicKey::from_bytes(pk_r)
|
let recipient_pk = HybridPublicKey::from_bytes(pk_r)
|
||||||
.expect("hybrid public key deserialization failed — key material is corrupted");
|
.map_err(|_| CryptoError::CryptoLibraryError)?;
|
||||||
// Pass HPKE info and aad through for proper context binding (RFC 9180).
|
|
||||||
let envelope = hybrid_encrypt(&recipient_pk, ptxt, info, aad)
|
let envelope = hybrid_encrypt(&recipient_pk, ptxt, info, aad)
|
||||||
.expect("hybrid HPKE encryption failed — critical crypto error");
|
.map_err(|_| CryptoError::CryptoLibraryError)?;
|
||||||
let kem_output = envelope[..HYBRID_KEM_OUTPUT_LEN].to_vec();
|
let kem_output = envelope[..HYBRID_KEM_OUTPUT_LEN].to_vec();
|
||||||
let ciphertext = envelope[HYBRID_KEM_OUTPUT_LEN..].to_vec();
|
let ciphertext = envelope[HYBRID_KEM_OUTPUT_LEN..].to_vec();
|
||||||
HpkeCiphertext {
|
Ok(HpkeCiphertext {
|
||||||
kem_output: kem_output.into(),
|
kem_output: kem_output.into(),
|
||||||
ciphertext: ciphertext.into(),
|
ciphertext: ciphertext.into(),
|
||||||
}
|
})
|
||||||
} else {
|
} else {
|
||||||
self.rust_crypto.hpke_seal(config, pk_r, info, aad, ptxt)
|
self.rust_crypto.hpke_seal(config, pk_r, info, aad, ptxt)
|
||||||
}
|
}
|
||||||
@@ -245,7 +248,7 @@ impl OpenMlsCrypto for HybridCrypto {
|
|||||||
info: &[u8],
|
info: &[u8],
|
||||||
exporter_context: &[u8],
|
exporter_context: &[u8],
|
||||||
exporter_length: usize,
|
exporter_length: usize,
|
||||||
) -> Result<(Vec<u8>, ExporterSecret), CryptoError> {
|
) -> Result<(KemOutput, ExporterSecret), CryptoError> {
|
||||||
if Self::is_hybrid_public_key(pk_r) {
|
if Self::is_hybrid_public_key(pk_r) {
|
||||||
// A key that passes the hybrid length check but fails deserialization
|
// A key that passes the hybrid length check but fails deserialization
|
||||||
// is corrupted — return an error instead of silently downgrading to
|
// is corrupted — return an error instead of silently downgrading to
|
||||||
@@ -286,14 +289,14 @@ impl OpenMlsCrypto for HybridCrypto {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn derive_hpke_keypair(&self, config: HpkeConfig, ikm: &[u8]) -> HpkeKeyPair {
|
fn derive_hpke_keypair(&self, config: HpkeConfig, ikm: &[u8]) -> Result<HpkeKeyPair, CryptoError> {
|
||||||
if self.hybrid_enabled && config.0 == HpkeKemType::DhKem25519 {
|
if self.hybrid_enabled && config.0 == HpkeKemType::DhKem25519 {
|
||||||
let kp = HybridKeypair::derive_from_ikm(ikm);
|
let kp = HybridKeypair::derive_from_ikm(ikm);
|
||||||
let private_bytes = kp.private_to_bytes();
|
let private_bytes = kp.private_to_bytes();
|
||||||
HpkeKeyPair {
|
Ok(HpkeKeyPair {
|
||||||
private: private_bytes.as_slice().into(),
|
private: private_bytes.as_slice().into(),
|
||||||
public: kp.public_key().to_bytes(),
|
public: kp.public_key().to_bytes(),
|
||||||
}
|
})
|
||||||
} else {
|
} else {
|
||||||
self.rust_crypto.derive_hpke_keypair(config, ikm)
|
self.rust_crypto.derive_hpke_keypair(config, ikm)
|
||||||
}
|
}
|
||||||
@@ -343,10 +346,10 @@ impl Default for HybridCryptoProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OpenMlsCryptoProvider for HybridCryptoProvider {
|
impl OpenMlsProvider for HybridCryptoProvider {
|
||||||
type CryptoProvider = HybridCrypto;
|
type CryptoProvider = HybridCrypto;
|
||||||
type RandProvider = RustCrypto;
|
type RandProvider = RustCrypto;
|
||||||
type KeyStoreProvider = DiskKeyStore;
|
type StorageProvider = DiskKeyStore;
|
||||||
|
|
||||||
fn crypto(&self) -> &Self::CryptoProvider {
|
fn crypto(&self) -> &Self::CryptoProvider {
|
||||||
&self.crypto
|
&self.crypto
|
||||||
@@ -356,7 +359,7 @@ impl OpenMlsCryptoProvider for HybridCryptoProvider {
|
|||||||
self.crypto.rust_crypto()
|
self.crypto.rust_crypto()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn key_store(&self) -> &Self::KeyStoreProvider {
|
fn storage(&self) -> &Self::StorageProvider {
|
||||||
&self.key_store
|
&self.key_store
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -383,7 +386,7 @@ mod tests {
|
|||||||
let crypto = HybridCrypto::new();
|
let crypto = HybridCrypto::new();
|
||||||
let ikm = b"test-ikm-for-hybrid-hpke-keypair";
|
let ikm = b"test-ikm-for-hybrid-hpke-keypair";
|
||||||
|
|
||||||
let keypair = crypto.derive_hpke_keypair(hpke_config_dhkem_x25519(), ikm);
|
let keypair = crypto.derive_hpke_keypair(hpke_config_dhkem_x25519(), ikm).unwrap();
|
||||||
assert_eq!(keypair.public.len(), HYBRID_PUBLIC_KEY_LEN);
|
assert_eq!(keypair.public.len(), HYBRID_PUBLIC_KEY_LEN);
|
||||||
assert_eq!(keypair.private.as_ref().len(), HYBRID_PRIVATE_KEY_LEN);
|
assert_eq!(keypair.private.as_ref().len(), HYBRID_PRIVATE_KEY_LEN);
|
||||||
|
|
||||||
@@ -397,7 +400,7 @@ mod tests {
|
|||||||
info,
|
info,
|
||||||
aad,
|
aad,
|
||||||
plaintext,
|
plaintext,
|
||||||
);
|
).unwrap();
|
||||||
assert!(!ct.kem_output.as_slice().is_empty());
|
assert!(!ct.kem_output.as_slice().is_empty());
|
||||||
assert!(!ct.ciphertext.as_slice().is_empty());
|
assert!(!ct.ciphertext.as_slice().is_empty());
|
||||||
|
|
||||||
@@ -419,7 +422,7 @@ mod tests {
|
|||||||
let crypto = HybridCrypto::new();
|
let crypto = HybridCrypto::new();
|
||||||
let ikm = b"exporter-ikm";
|
let ikm = b"exporter-ikm";
|
||||||
|
|
||||||
let keypair = crypto.derive_hpke_keypair(hpke_config_dhkem_x25519(), ikm);
|
let keypair = crypto.derive_hpke_keypair(hpke_config_dhkem_x25519(), ikm).unwrap();
|
||||||
let info = b"";
|
let info = b"";
|
||||||
let exporter_context = b"MLS 1.0 external init";
|
let exporter_context = b"MLS 1.0 external init";
|
||||||
let exporter_length = 32;
|
let exporter_length = 32;
|
||||||
@@ -457,7 +460,7 @@ mod tests {
|
|||||||
let crypto = HybridCrypto::new_classical();
|
let crypto = HybridCrypto::new_classical();
|
||||||
let ikm = b"test-ikm-for-classical-hpke";
|
let ikm = b"test-ikm-for-classical-hpke";
|
||||||
|
|
||||||
let keypair = crypto.derive_hpke_keypair(hpke_config_dhkem_x25519(), ikm);
|
let keypair = crypto.derive_hpke_keypair(hpke_config_dhkem_x25519(), ikm).unwrap();
|
||||||
// Classical X25519 keys are 32 bytes
|
// Classical X25519 keys are 32 bytes
|
||||||
assert_eq!(keypair.public.len(), 32);
|
assert_eq!(keypair.public.len(), 32);
|
||||||
assert_eq!(keypair.private.as_ref().len(), 32);
|
assert_eq!(keypair.private.as_ref().len(), 32);
|
||||||
@@ -469,7 +472,7 @@ mod tests {
|
|||||||
let crypto = HybridCrypto::new_classical();
|
let crypto = HybridCrypto::new_classical();
|
||||||
let ikm = b"test-ikm-for-classical-round-trip";
|
let ikm = b"test-ikm-for-classical-round-trip";
|
||||||
|
|
||||||
let keypair = crypto.derive_hpke_keypair(hpke_config_dhkem_x25519(), ikm);
|
let keypair = crypto.derive_hpke_keypair(hpke_config_dhkem_x25519(), ikm).unwrap();
|
||||||
assert_eq!(keypair.public.len(), 32); // classical key
|
assert_eq!(keypair.public.len(), 32); // classical key
|
||||||
|
|
||||||
let plaintext = b"hello classical MLS";
|
let plaintext = b"hello classical MLS";
|
||||||
@@ -482,7 +485,7 @@ mod tests {
|
|||||||
info,
|
info,
|
||||||
aad,
|
aad,
|
||||||
plaintext,
|
plaintext,
|
||||||
);
|
).unwrap();
|
||||||
assert!(!ct.kem_output.as_slice().is_empty());
|
assert!(!ct.kem_output.as_slice().is_empty());
|
||||||
|
|
||||||
let decrypted = crypto
|
let decrypted = crypto
|
||||||
@@ -501,7 +504,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn key_package_generation_with_hybrid_provider() {
|
fn key_package_generation_with_hybrid_provider() {
|
||||||
use openmls::prelude::{
|
use openmls::prelude::{
|
||||||
Credential, CredentialType, CredentialWithKey, CryptoConfig, KeyPackage,
|
BasicCredential, CredentialWithKey, KeyPackage,
|
||||||
};
|
};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tls_codec::Serialize;
|
use tls_codec::Serialize;
|
||||||
@@ -514,26 +517,24 @@ mod tests {
|
|||||||
let provider = HybridCryptoProvider::default();
|
let provider = HybridCryptoProvider::default();
|
||||||
let identity = Arc::new(IdentityKeypair::generate());
|
let identity = Arc::new(IdentityKeypair::generate());
|
||||||
|
|
||||||
let credential = Credential::new(
|
let credential: openmls::prelude::Credential =
|
||||||
identity.public_key_bytes().to_vec(),
|
BasicCredential::new(identity.public_key_bytes().to_vec()).into();
|
||||||
CredentialType::Basic,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
let credential_with_key = CredentialWithKey {
|
let credential_with_key = CredentialWithKey {
|
||||||
credential,
|
credential,
|
||||||
signature_key: identity.public_key_bytes().to_vec().into(),
|
signature_key: identity.public_key_bytes().to_vec().into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let key_package = KeyPackage::builder()
|
let key_package_bundle = KeyPackage::builder()
|
||||||
.build(
|
.build(
|
||||||
CryptoConfig::with_default_version(CIPHERSUITE),
|
CIPHERSUITE,
|
||||||
&provider,
|
&provider,
|
||||||
identity.as_ref(),
|
identity.as_ref(),
|
||||||
credential_with_key,
|
credential_with_key,
|
||||||
)
|
)
|
||||||
.expect("KeyPackage with hybrid HPKE");
|
.expect("KeyPackage with hybrid HPKE");
|
||||||
|
|
||||||
let bytes = key_package
|
let bytes = key_package_bundle
|
||||||
|
.key_package()
|
||||||
.tls_serialize_detached()
|
.tls_serialize_detached()
|
||||||
.expect("serialize KeyPackage");
|
.expect("serialize KeyPackage");
|
||||||
assert!(!bytes.is_empty());
|
assert!(!bytes.is_empty());
|
||||||
@@ -90,7 +90,7 @@ impl IdentityKeypair {
|
|||||||
/// `openmls_basic_credential` crate.
|
/// `openmls_basic_credential` crate.
|
||||||
#[cfg(feature = "native")]
|
#[cfg(feature = "native")]
|
||||||
impl openmls_traits::signatures::Signer for IdentityKeypair {
|
impl openmls_traits::signatures::Signer for IdentityKeypair {
|
||||||
fn sign(&self, payload: &[u8]) -> Result<Vec<u8>, openmls_traits::types::Error> {
|
fn sign(&self, payload: &[u8]) -> Result<Vec<u8>, openmls_traits::signatures::SignerError> {
|
||||||
let sk = self.signing_key();
|
let sk = self.signing_key();
|
||||||
let sig: ed25519_dalek::Signature = sk.sign(payload);
|
let sig: ed25519_dalek::Signature = sk.sign(payload);
|
||||||
Ok(sig.to_bytes().to_vec())
|
Ok(sig.to_bytes().to_vec())
|
||||||
@@ -14,18 +14,18 @@
|
|||||||
//! # Wire format
|
//! # Wire format
|
||||||
//!
|
//!
|
||||||
//! KeyPackages are TLS-encoded using `tls_codec` (same version as openmls).
|
//! KeyPackages are TLS-encoded using `tls_codec` (same version as openmls).
|
||||||
//! The resulting bytes are opaque to the quicproquo transport layer.
|
//! The resulting bytes are opaque to the quicprochat transport layer.
|
||||||
|
|
||||||
use openmls::prelude::{
|
use openmls::prelude::{
|
||||||
Ciphersuite, Credential, CredentialType, CredentialWithKey, CryptoConfig, KeyPackage,
|
BasicCredential, Ciphersuite, CredentialWithKey, KeyPackage, KeyPackageIn,
|
||||||
KeyPackageIn, TlsDeserializeTrait, TlsSerializeTrait,
|
|
||||||
};
|
};
|
||||||
use openmls_rust_crypto::OpenMlsRustCrypto;
|
use openmls_rust_crypto::OpenMlsRustCrypto;
|
||||||
|
use tls_codec::{Deserialize as TlsDeserializeTrait, Serialize as TlsSerializeTrait};
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
|
|
||||||
use crate::{error::CoreError, identity::IdentityKeypair};
|
use crate::{error::CoreError, identity::IdentityKeypair};
|
||||||
|
|
||||||
/// The MLS ciphersuite used throughout quicproquo (RFC 9420 §17.1).
|
/// The MLS ciphersuite used throughout quicprochat (RFC 9420 §17.1).
|
||||||
pub const ALLOWED_CIPHERSUITE: Ciphersuite =
|
pub const ALLOWED_CIPHERSUITE: Ciphersuite =
|
||||||
Ciphersuite::MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519;
|
Ciphersuite::MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519;
|
||||||
|
|
||||||
@@ -74,8 +74,8 @@ pub fn generate_key_package(identity: &IdentityKeypair) -> Result<(Vec<u8>, Vec<
|
|||||||
|
|
||||||
// Build a BasicCredential using the raw Ed25519 public key bytes as the
|
// Build a BasicCredential using the raw Ed25519 public key bytes as the
|
||||||
// MLS identity. Per RFC 9420, any byte string may serve as the identity.
|
// MLS identity. Per RFC 9420, any byte string may serve as the identity.
|
||||||
let credential = Credential::new(identity.public_key_bytes().to_vec(), CredentialType::Basic)
|
let credential: openmls::prelude::Credential =
|
||||||
.map_err(|e| CoreError::Mls(format!("{e:?}")))?;
|
BasicCredential::new(identity.public_key_bytes().to_vec()).into();
|
||||||
|
|
||||||
// The `signature_key` in CredentialWithKey is the Ed25519 public key that
|
// The `signature_key` in CredentialWithKey is the Ed25519 public key that
|
||||||
// will be used to verify the KeyPackage's leaf node signature.
|
// will be used to verify the KeyPackage's leaf node signature.
|
||||||
@@ -87,19 +87,13 @@ pub fn generate_key_package(identity: &IdentityKeypair) -> Result<(Vec<u8>, Vec<
|
|||||||
|
|
||||||
// `IdentityKeypair` implements `openmls_traits::signatures::Signer`
|
// `IdentityKeypair` implements `openmls_traits::signatures::Signer`
|
||||||
// so it can be passed directly to the builder.
|
// so it can be passed directly to the builder.
|
||||||
let key_package = KeyPackage::builder()
|
let key_package_bundle = KeyPackage::builder()
|
||||||
.build(
|
.build(CIPHERSUITE, &backend, identity, credential_with_key)
|
||||||
CryptoConfig::with_default_version(CIPHERSUITE),
|
|
||||||
&backend,
|
|
||||||
identity,
|
|
||||||
credential_with_key,
|
|
||||||
)
|
|
||||||
.map_err(|e| CoreError::Mls(format!("{e:?}")))?;
|
.map_err(|e| CoreError::Mls(format!("{e:?}")))?;
|
||||||
|
|
||||||
// TLS-encode the KeyPackage using the trait from the openmls prelude.
|
// TLS-encode the KeyPackage.
|
||||||
// This uses tls_codec 0.3 (the same version openmls uses internally),
|
let tls_bytes = key_package_bundle
|
||||||
// avoiding a duplicate-trait conflict with tls_codec 0.4.
|
.key_package()
|
||||||
let tls_bytes = key_package
|
|
||||||
.tls_serialize_detached()
|
.tls_serialize_detached()
|
||||||
.map_err(|e| CoreError::Mls(format!("{e:?}")))?;
|
.map_err(|e| CoreError::Mls(format!("{e:?}")))?;
|
||||||
|
|
||||||
713
crates/quicprochat-core/src/keystore.rs
Normal file
713
crates/quicprochat-core/src/keystore.rs
Normal file
@@ -0,0 +1,713 @@
|
|||||||
|
use std::{
|
||||||
|
fs,
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
};
|
||||||
|
|
||||||
|
use openmls_memory_storage::MemoryStorage;
|
||||||
|
use openmls_traits::storage::{traits, StorageProvider, CURRENT_VERSION};
|
||||||
|
|
||||||
|
/// A disk-backed storage provider implementing `StorageProvider`.
|
||||||
|
///
|
||||||
|
/// Wraps `openmls_memory_storage::MemoryStorage` and flushes to disk on every
|
||||||
|
/// write so that HPKE init keys and group state survive process restarts.
|
||||||
|
///
|
||||||
|
/// # Serialization
|
||||||
|
///
|
||||||
|
/// Uses bincode for the outer `HashMap<Vec<u8>, Vec<u8>>` container when
|
||||||
|
/// persisting to disk. The inner values use serde_json (matching
|
||||||
|
/// `MemoryStorage`'s serialization format).
|
||||||
|
///
|
||||||
|
/// # Persistence security
|
||||||
|
///
|
||||||
|
/// When `path` is set, file permissions are restricted to owner-only (0o600)
|
||||||
|
/// on Unix platforms, since the store may contain HPKE private keys.
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct DiskKeyStore {
|
||||||
|
path: Option<PathBuf>,
|
||||||
|
storage: MemoryStorage,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(thiserror::Error, Debug)]
|
||||||
|
pub enum DiskKeyStoreError {
|
||||||
|
#[error("serialization error")]
|
||||||
|
Serialization,
|
||||||
|
#[error("io error: {0}")]
|
||||||
|
Io(String),
|
||||||
|
#[error("memory storage error: {0}")]
|
||||||
|
MemoryStorage(#[from] openmls_memory_storage::MemoryStorageError),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DiskKeyStore {
|
||||||
|
/// In-memory keystore (no persistence).
|
||||||
|
pub fn ephemeral() -> Self {
|
||||||
|
Self {
|
||||||
|
path: None,
|
||||||
|
storage: MemoryStorage::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Persistent keystore backed by `path`. Creates an empty store if missing.
|
||||||
|
pub fn persistent(path: impl AsRef<Path>) -> Result<Self, DiskKeyStoreError> {
|
||||||
|
let path = path.as_ref().to_path_buf();
|
||||||
|
let storage = if path.exists() {
|
||||||
|
let bytes = fs::read(&path).map_err(|e| DiskKeyStoreError::Io(e.to_string()))?;
|
||||||
|
if bytes.is_empty() {
|
||||||
|
MemoryStorage::default()
|
||||||
|
} else {
|
||||||
|
let map: std::collections::HashMap<Vec<u8>, Vec<u8>> =
|
||||||
|
bincode::deserialize(&bytes)
|
||||||
|
.map_err(|_| DiskKeyStoreError::Serialization)?;
|
||||||
|
let storage = MemoryStorage::default();
|
||||||
|
let mut values = storage.values.write()
|
||||||
|
.map_err(|_| DiskKeyStoreError::Io("lock poisoned".into()))?;
|
||||||
|
*values = map;
|
||||||
|
drop(values);
|
||||||
|
storage
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
MemoryStorage::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let store = Self {
|
||||||
|
path: Some(path),
|
||||||
|
storage,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Set restrictive file permissions on the keystore file.
|
||||||
|
store.set_file_permissions()?;
|
||||||
|
|
||||||
|
Ok(store)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn flush(&self) -> Result<(), DiskKeyStoreError> {
|
||||||
|
let Some(path) = &self.path else {
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
let values = self.storage.values.read()
|
||||||
|
.map_err(|_| DiskKeyStoreError::Io("lock poisoned".into()))?;
|
||||||
|
let bytes = bincode::serialize(&*values)
|
||||||
|
.map_err(|_| DiskKeyStoreError::Serialization)?;
|
||||||
|
if let Some(parent) = path.parent() {
|
||||||
|
fs::create_dir_all(parent).map_err(|e| DiskKeyStoreError::Io(e.to_string()))?;
|
||||||
|
}
|
||||||
|
fs::write(path, &bytes).map_err(|e| DiskKeyStoreError::Io(e.to_string()))?;
|
||||||
|
self.set_file_permissions()?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Serialize the backing storage to bytes (bincode).
|
||||||
|
///
|
||||||
|
/// This captures all key material *and* MLS group state held by the
|
||||||
|
/// `StorageProvider`, allowing the caller to persist it in a database
|
||||||
|
/// column instead of (or in addition to) on-disk files.
|
||||||
|
pub fn to_bytes(&self) -> Result<Vec<u8>, DiskKeyStoreError> {
|
||||||
|
let values = self.storage.values.read()
|
||||||
|
.map_err(|_| DiskKeyStoreError::Io("lock poisoned".into()))?;
|
||||||
|
bincode::serialize(&*values).map_err(|_| DiskKeyStoreError::Serialization)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Restore a `DiskKeyStore` from bytes previously produced by [`to_bytes`].
|
||||||
|
pub fn from_bytes(bytes: &[u8]) -> Result<Self, DiskKeyStoreError> {
|
||||||
|
let map: std::collections::HashMap<Vec<u8>, Vec<u8>> =
|
||||||
|
bincode::deserialize(bytes).map_err(|_| DiskKeyStoreError::Serialization)?;
|
||||||
|
let storage = MemoryStorage::default();
|
||||||
|
let mut values = storage.values.write()
|
||||||
|
.map_err(|_| DiskKeyStoreError::Io("lock poisoned".into()))?;
|
||||||
|
*values = map;
|
||||||
|
drop(values);
|
||||||
|
Ok(Self {
|
||||||
|
path: None,
|
||||||
|
storage,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Restrict file permissions to owner-only (0o600) on Unix.
|
||||||
|
#[cfg(unix)]
|
||||||
|
fn set_file_permissions(&self) -> Result<(), DiskKeyStoreError> {
|
||||||
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
if let Some(path) = &self.path {
|
||||||
|
if path.exists() {
|
||||||
|
let perms = std::fs::Permissions::from_mode(0o600);
|
||||||
|
fs::set_permissions(path, perms)
|
||||||
|
.map_err(|e| DiskKeyStoreError::Io(format!("set permissions: {e}")))?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(unix))]
|
||||||
|
fn set_file_permissions(&self) -> Result<(), DiskKeyStoreError> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for DiskKeyStore {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::ephemeral()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Delegate all `StorageProvider` methods to the inner `MemoryStorage`,
|
||||||
|
/// flushing to disk after every write/delete operation.
|
||||||
|
///
|
||||||
|
/// The flush errors are mapped to `DiskKeyStoreError` via the
|
||||||
|
/// `MemoryStorageError` conversion. If a flush fails, the in-memory state
|
||||||
|
/// is still updated (matching the old DiskKeyStore behavior).
|
||||||
|
impl StorageProvider<CURRENT_VERSION> for DiskKeyStore {
|
||||||
|
type Error = DiskKeyStoreError;
|
||||||
|
|
||||||
|
fn write_mls_join_config<
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
MlsGroupJoinConfig: traits::MlsGroupJoinConfig<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
config: &MlsGroupJoinConfig,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.write_mls_join_config(group_id, config)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn append_own_leaf_node<
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
LeafNode: traits::LeafNode<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
leaf_node: &LeafNode,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.append_own_leaf_node(group_id, leaf_node)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn queue_proposal<
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
ProposalRef: traits::ProposalRef<CURRENT_VERSION>,
|
||||||
|
QueuedProposal: traits::QueuedProposal<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
proposal_ref: &ProposalRef,
|
||||||
|
proposal: &QueuedProposal,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.queue_proposal(group_id, proposal_ref, proposal)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_tree<
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
TreeSync: traits::TreeSync<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
tree: &TreeSync,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.write_tree(group_id, tree)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_interim_transcript_hash<
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
InterimTranscriptHash: traits::InterimTranscriptHash<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
interim_transcript_hash: &InterimTranscriptHash,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.write_interim_transcript_hash(group_id, interim_transcript_hash)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_context<
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
GroupContext: traits::GroupContext<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
group_context: &GroupContext,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.write_context(group_id, group_context)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_confirmation_tag<
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
ConfirmationTag: traits::ConfirmationTag<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
confirmation_tag: &ConfirmationTag,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.write_confirmation_tag(group_id, confirmation_tag)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_group_state<
|
||||||
|
GroupState: traits::GroupState<CURRENT_VERSION>,
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
group_state: &GroupState,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.write_group_state(group_id, group_state)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_message_secrets<
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
MessageSecrets: traits::MessageSecrets<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
message_secrets: &MessageSecrets,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.write_message_secrets(group_id, message_secrets)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_resumption_psk_store<
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
ResumptionPskStore: traits::ResumptionPskStore<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
resumption_psk_store: &ResumptionPskStore,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.write_resumption_psk_store(group_id, resumption_psk_store)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_own_leaf_index<
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
LeafNodeIndex: traits::LeafNodeIndex<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
own_leaf_index: &LeafNodeIndex,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.write_own_leaf_index(group_id, own_leaf_index)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_group_epoch_secrets<
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
GroupEpochSecrets: traits::GroupEpochSecrets<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
group_epoch_secrets: &GroupEpochSecrets,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.write_group_epoch_secrets(group_id, group_epoch_secrets)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_signature_key_pair<
|
||||||
|
SignaturePublicKey: traits::SignaturePublicKey<CURRENT_VERSION>,
|
||||||
|
SignatureKeyPair: traits::SignatureKeyPair<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
public_key: &SignaturePublicKey,
|
||||||
|
signature_key_pair: &SignatureKeyPair,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.write_signature_key_pair(public_key, signature_key_pair)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_encryption_key_pair<
|
||||||
|
EncryptionKey: traits::EncryptionKey<CURRENT_VERSION>,
|
||||||
|
HpkeKeyPair: traits::HpkeKeyPair<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
public_key: &EncryptionKey,
|
||||||
|
key_pair: &HpkeKeyPair,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.write_encryption_key_pair(public_key, key_pair)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_encryption_epoch_key_pairs<
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
EpochKey: traits::EpochKey<CURRENT_VERSION>,
|
||||||
|
HpkeKeyPair: traits::HpkeKeyPair<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
epoch: &EpochKey,
|
||||||
|
leaf_index: u32,
|
||||||
|
key_pairs: &[HpkeKeyPair],
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.write_encryption_epoch_key_pairs(group_id, epoch, leaf_index, key_pairs)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_key_package<
|
||||||
|
HashReference: traits::HashReference<CURRENT_VERSION>,
|
||||||
|
KeyPackage: traits::KeyPackage<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
hash_ref: &HashReference,
|
||||||
|
key_package: &KeyPackage,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.write_key_package(hash_ref, key_package)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_psk<
|
||||||
|
PskId: traits::PskId<CURRENT_VERSION>,
|
||||||
|
PskBundle: traits::PskBundle<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
psk_id: &PskId,
|
||||||
|
psk: &PskBundle,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.write_psk(psk_id, psk)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- getters (no flush needed) ---
|
||||||
|
|
||||||
|
fn mls_group_join_config<
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
MlsGroupJoinConfig: traits::MlsGroupJoinConfig<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
) -> Result<Option<MlsGroupJoinConfig>, Self::Error> {
|
||||||
|
Ok(self.storage.mls_group_join_config(group_id)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn own_leaf_nodes<
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
LeafNode: traits::LeafNode<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
) -> Result<Vec<LeafNode>, Self::Error> {
|
||||||
|
Ok(self.storage.own_leaf_nodes(group_id)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn queued_proposal_refs<
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
ProposalRef: traits::ProposalRef<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
) -> Result<Vec<ProposalRef>, Self::Error> {
|
||||||
|
Ok(self.storage.queued_proposal_refs(group_id)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn queued_proposals<
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
ProposalRef: traits::ProposalRef<CURRENT_VERSION>,
|
||||||
|
QueuedProposal: traits::QueuedProposal<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
) -> Result<Vec<(ProposalRef, QueuedProposal)>, Self::Error> {
|
||||||
|
Ok(self.storage.queued_proposals(group_id)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn tree<
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
TreeSync: traits::TreeSync<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
) -> Result<Option<TreeSync>, Self::Error> {
|
||||||
|
Ok(self.storage.tree(group_id)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn group_context<
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
GroupContext: traits::GroupContext<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
) -> Result<Option<GroupContext>, Self::Error> {
|
||||||
|
Ok(self.storage.group_context(group_id)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn interim_transcript_hash<
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
InterimTranscriptHash: traits::InterimTranscriptHash<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
) -> Result<Option<InterimTranscriptHash>, Self::Error> {
|
||||||
|
Ok(self.storage.interim_transcript_hash(group_id)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn confirmation_tag<
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
ConfirmationTag: traits::ConfirmationTag<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
) -> Result<Option<ConfirmationTag>, Self::Error> {
|
||||||
|
Ok(self.storage.confirmation_tag(group_id)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn group_state<
|
||||||
|
GroupState: traits::GroupState<CURRENT_VERSION>,
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
) -> Result<Option<GroupState>, Self::Error> {
|
||||||
|
Ok(self.storage.group_state(group_id)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn message_secrets<
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
MessageSecrets: traits::MessageSecrets<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
) -> Result<Option<MessageSecrets>, Self::Error> {
|
||||||
|
Ok(self.storage.message_secrets(group_id)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn resumption_psk_store<
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
ResumptionPskStore: traits::ResumptionPskStore<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
) -> Result<Option<ResumptionPskStore>, Self::Error> {
|
||||||
|
Ok(self.storage.resumption_psk_store(group_id)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn own_leaf_index<
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
LeafNodeIndex: traits::LeafNodeIndex<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
) -> Result<Option<LeafNodeIndex>, Self::Error> {
|
||||||
|
Ok(self.storage.own_leaf_index(group_id)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn group_epoch_secrets<
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
GroupEpochSecrets: traits::GroupEpochSecrets<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
) -> Result<Option<GroupEpochSecrets>, Self::Error> {
|
||||||
|
Ok(self.storage.group_epoch_secrets(group_id)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn signature_key_pair<
|
||||||
|
SignaturePublicKey: traits::SignaturePublicKey<CURRENT_VERSION>,
|
||||||
|
SignatureKeyPair: traits::SignatureKeyPair<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
public_key: &SignaturePublicKey,
|
||||||
|
) -> Result<Option<SignatureKeyPair>, Self::Error> {
|
||||||
|
Ok(self.storage.signature_key_pair(public_key)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn encryption_key_pair<
|
||||||
|
HpkeKeyPair: traits::HpkeKeyPair<CURRENT_VERSION>,
|
||||||
|
EncryptionKey: traits::EncryptionKey<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
public_key: &EncryptionKey,
|
||||||
|
) -> Result<Option<HpkeKeyPair>, Self::Error> {
|
||||||
|
Ok(self.storage.encryption_key_pair(public_key)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn encryption_epoch_key_pairs<
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
EpochKey: traits::EpochKey<CURRENT_VERSION>,
|
||||||
|
HpkeKeyPair: traits::HpkeKeyPair<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
epoch: &EpochKey,
|
||||||
|
leaf_index: u32,
|
||||||
|
) -> Result<Vec<HpkeKeyPair>, Self::Error> {
|
||||||
|
Ok(self.storage.encryption_epoch_key_pairs(group_id, epoch, leaf_index)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn key_package<
|
||||||
|
KeyPackageRef: traits::HashReference<CURRENT_VERSION>,
|
||||||
|
KeyPackage: traits::KeyPackage<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
hash_ref: &KeyPackageRef,
|
||||||
|
) -> Result<Option<KeyPackage>, Self::Error> {
|
||||||
|
Ok(self.storage.key_package(hash_ref)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn psk<
|
||||||
|
PskBundle: traits::PskBundle<CURRENT_VERSION>,
|
||||||
|
PskId: traits::PskId<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
psk_id: &PskId,
|
||||||
|
) -> Result<Option<PskBundle>, Self::Error> {
|
||||||
|
Ok(self.storage.psk(psk_id)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- deleters (flush needed) ---
|
||||||
|
|
||||||
|
fn remove_proposal<
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
ProposalRef: traits::ProposalRef<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
proposal_ref: &ProposalRef,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.remove_proposal(group_id, proposal_ref)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete_own_leaf_nodes<GroupId: traits::GroupId<CURRENT_VERSION>>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.delete_own_leaf_nodes(group_id)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete_group_config<GroupId: traits::GroupId<CURRENT_VERSION>>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.delete_group_config(group_id)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete_tree<GroupId: traits::GroupId<CURRENT_VERSION>>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.delete_tree(group_id)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete_confirmation_tag<GroupId: traits::GroupId<CURRENT_VERSION>>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.delete_confirmation_tag(group_id)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete_group_state<GroupId: traits::GroupId<CURRENT_VERSION>>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.delete_group_state(group_id)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete_context<GroupId: traits::GroupId<CURRENT_VERSION>>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.delete_context(group_id)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete_interim_transcript_hash<GroupId: traits::GroupId<CURRENT_VERSION>>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.delete_interim_transcript_hash(group_id)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete_message_secrets<GroupId: traits::GroupId<CURRENT_VERSION>>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.delete_message_secrets(group_id)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete_all_resumption_psk_secrets<GroupId: traits::GroupId<CURRENT_VERSION>>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.delete_all_resumption_psk_secrets(group_id)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete_own_leaf_index<GroupId: traits::GroupId<CURRENT_VERSION>>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.delete_own_leaf_index(group_id)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete_group_epoch_secrets<GroupId: traits::GroupId<CURRENT_VERSION>>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.delete_group_epoch_secrets(group_id)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn clear_proposal_queue<
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
ProposalRef: traits::ProposalRef<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.clear_proposal_queue::<GroupId, ProposalRef>(group_id)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete_signature_key_pair<
|
||||||
|
SignaturePublicKey: traits::SignaturePublicKey<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
public_key: &SignaturePublicKey,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.delete_signature_key_pair(public_key)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete_encryption_key_pair<EncryptionKey: traits::EncryptionKey<CURRENT_VERSION>>(
|
||||||
|
&self,
|
||||||
|
public_key: &EncryptionKey,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.delete_encryption_key_pair(public_key)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete_encryption_epoch_key_pairs<
|
||||||
|
GroupId: traits::GroupId<CURRENT_VERSION>,
|
||||||
|
EpochKey: traits::EpochKey<CURRENT_VERSION>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
group_id: &GroupId,
|
||||||
|
epoch: &EpochKey,
|
||||||
|
leaf_index: u32,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.delete_encryption_epoch_key_pairs(group_id, epoch, leaf_index)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete_key_package<KeyPackageRef: traits::HashReference<CURRENT_VERSION>>(
|
||||||
|
&self,
|
||||||
|
hash_ref: &KeyPackageRef,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.delete_key_package(hash_ref)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete_psk<PskKey: traits::PskId<CURRENT_VERSION>>(
|
||||||
|
&self,
|
||||||
|
psk_id: &PskKey,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
self.storage.delete_psk(psk_id)?;
|
||||||
|
self.flush()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
//! Core cryptographic primitives, MLS group state machine, and hybrid
|
//! Core cryptographic primitives, MLS group state machine, and hybrid
|
||||||
//! post-quantum KEM for quicproquo.
|
//! post-quantum KEM for quicprochat.
|
||||||
//!
|
//!
|
||||||
//! # WASM support
|
//! # WASM support
|
||||||
//!
|
//!
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
use opaque_ke::CipherSuite;
|
use opaque_ke::CipherSuite;
|
||||||
|
|
||||||
/// OPAQUE cipher suite for quicproquo.
|
/// OPAQUE cipher suite for quicprochat.
|
||||||
///
|
///
|
||||||
/// - **OPRF**: Ristretto255 (curve25519-based, ~128-bit security)
|
/// - **OPRF**: Ristretto255 (curve25519-based, ~128-bit security)
|
||||||
/// - **Key exchange**: Triple-DH (3DH) over Ristretto255 with SHA-512
|
/// - **Key exchange**: Triple-DH (3DH) over Ristretto255 with SHA-512
|
||||||
@@ -48,7 +48,7 @@ use zeroize::Zeroizing;
|
|||||||
use crate::error::CoreError;
|
use crate::error::CoreError;
|
||||||
|
|
||||||
/// Domain separation label for the hybrid Noise handshake.
|
/// Domain separation label for the hybrid Noise handshake.
|
||||||
const PROTOCOL_NAME: &[u8] = b"quicproquo-pq-noise-v1";
|
const PROTOCOL_NAME: &[u8] = b"quicprochat-pq-noise-v1";
|
||||||
|
|
||||||
/// ML-KEM-768 encapsulation key length.
|
/// ML-KEM-768 encapsulation key length.
|
||||||
const MLKEM_EK_LEN: usize = 1184;
|
const MLKEM_EK_LEN: usize = 1184;
|
||||||
@@ -91,10 +91,10 @@ fn generate_code(rng: &mut impl RngCore) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Derive a 32-byte recovery token from a code (used for server-side lookup).
|
/// Derive a 32-byte recovery token from a code (used for server-side lookup).
|
||||||
/// The token is `SHA-256("qpq-recovery-token:" || code)`.
|
/// The token is `SHA-256("qpc-recovery-token:" || code)`.
|
||||||
fn derive_recovery_token(code: &str) -> [u8; 32] {
|
fn derive_recovery_token(code: &str) -> [u8; 32] {
|
||||||
let mut hasher = Sha256::new();
|
let mut hasher = Sha256::new();
|
||||||
hasher.update(b"qpq-recovery-token:");
|
hasher.update(b"qpc-recovery-token:");
|
||||||
hasher.update(code.as_bytes());
|
hasher.update(code.as_bytes());
|
||||||
hasher.finalize().into()
|
hasher.finalize().into()
|
||||||
}
|
}
|
||||||
@@ -206,7 +206,7 @@ pub fn recover_from_bundle(
|
|||||||
|
|
||||||
/// Compute the token hash for a recovery code (for server-side lookup).
|
/// Compute the token hash for a recovery code (for server-side lookup).
|
||||||
///
|
///
|
||||||
/// This is `SHA-256(SHA-256("qpq-recovery-token:" || code))`.
|
/// This is `SHA-256(SHA-256("qpc-recovery-token:" || code))`.
|
||||||
pub fn recovery_token_hash(code: &str) -> Vec<u8> {
|
pub fn recovery_token_hash(code: &str) -> Vec<u8> {
|
||||||
let token = derive_recovery_token(code);
|
let token = derive_recovery_token(code);
|
||||||
Sha256::digest(token).to_vec()
|
Sha256::digest(token).to_vec()
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
//! 1. Sort the keys lexicographically so the result is symmetric.
|
//! 1. Sort the keys lexicographically so the result is symmetric.
|
||||||
//! 2. Concatenate: `input = key_lo || key_hi` (64 bytes).
|
//! 2. Concatenate: `input = key_lo || key_hi` (64 bytes).
|
||||||
//! 3. Compute HMAC-SHA256(key=info, data=input) where
|
//! 3. Compute HMAC-SHA256(key=info, data=input) where
|
||||||
//! `info = b"quicproquo-safety-number-v1"`.
|
//! `info = b"quicprochat-safety-number-v1"`.
|
||||||
//! 4. Iterate the HMAC 5200 times: `hash = HMAC-SHA256(key=info, data=hash)`.
|
//! 4. Iterate the HMAC 5200 times: `hash = HMAC-SHA256(key=info, data=hash)`.
|
||||||
//! 5. Interpret the 32-byte result as 4× 64-bit big-endian integers
|
//! 5. Interpret the 32-byte result as 4× 64-bit big-endian integers
|
||||||
//! (= 256 bits → 4 groups of 64 bits). Extract 3 decimal groups per
|
//! (= 256 bits → 4 groups of 64 bits). Extract 3 decimal groups per
|
||||||
@@ -23,7 +23,7 @@ use sha2::Sha256;
|
|||||||
type HmacSha256 = Hmac<Sha256>;
|
type HmacSha256 = Hmac<Sha256>;
|
||||||
|
|
||||||
/// Fixed info string used as the HMAC key throughout the key-stretching loop.
|
/// Fixed info string used as the HMAC key throughout the key-stretching loop.
|
||||||
const INFO: &[u8] = b"quicproquo-safety-number-v1";
|
const INFO: &[u8] = b"quicprochat-safety-number-v1";
|
||||||
|
|
||||||
/// Compute a 60-digit safety number from two 32-byte Ed25519 public keys.
|
/// Compute a 60-digit safety number from two 32-byte Ed25519 public keys.
|
||||||
///
|
///
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "quicproquo-kt"
|
name = "quicprochat-kt"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition.workspace = true
|
||||||
description = "Key Transparency: append-only SHA-256 Merkle log for (username, identity_key) bindings."
|
description = "Key Transparency: append-only SHA-256 Merkle log for (username, identity_key) bindings."
|
||||||
license = "MIT"
|
license = "Apache-2.0 OR MIT"
|
||||||
|
repository.workspace = true
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
workspace = true
|
workspace = true
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "quicproquo-p2p"
|
name = "quicprochat-p2p"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition.workspace = true
|
||||||
description = "P2P transport layer for quicproquo using iroh."
|
description = "P2P transport layer for quicprochat using iroh."
|
||||||
license = "MIT"
|
license = "Apache-2.0 OR MIT"
|
||||||
|
repository.workspace = true
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
traffic-resistance = []
|
traffic-resistance = []
|
||||||
@@ -18,7 +19,7 @@ tracing = "0.1"
|
|||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
|
|
||||||
# Mesh identity & store-and-forward
|
# Mesh identity & store-and-forward
|
||||||
quicproquo-core = { path = "../quicproquo-core", default-features = false }
|
quicprochat-core = { path = "../quicprochat-core", default-features = false }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
sha2 = { workspace = true }
|
sha2 = { workspace = true }
|
||||||
@@ -149,7 +149,7 @@ impl MeshEnvelope {
|
|||||||
self.max_hops,
|
self.max_hops,
|
||||||
self.timestamp,
|
self.timestamp,
|
||||||
);
|
);
|
||||||
quicproquo_core::IdentityKeypair::verify_raw(&sender_key, &signable, &sig).is_ok()
|
quicprochat_core::IdentityKeypair::verify_raw(&sender_key, &signable, &sig).is_ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check whether this envelope has expired (TTL elapsed since timestamp).
|
/// Check whether this envelope has expired (TTL elapsed since timestamp).
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
//! Self-sovereign mesh identity backed by quicproquo-core Ed25519 keypairs.
|
//! Self-sovereign mesh identity backed by quicprochat-core Ed25519 keypairs.
|
||||||
//!
|
//!
|
||||||
//! A [`MeshIdentity`] wraps an [`IdentityKeypair`] with a peer directory,
|
//! A [`MeshIdentity`] wraps an [`IdentityKeypair`] with a peer directory,
|
||||||
//! enabling P2P nodes to persist identity and track known peers across
|
//! enabling P2P nodes to persist identity and track known peers across
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use quicproquo_core::IdentityKeypair;
|
use quicprochat_core::IdentityKeypair;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
@@ -130,7 +130,7 @@ mod tests {
|
|||||||
let msg = b"test message";
|
let msg = b"test message";
|
||||||
let sig = id.sign(msg);
|
let sig = id.sign(msg);
|
||||||
|
|
||||||
// Verify through quicproquo_core
|
// Verify through quicprochat_core
|
||||||
let pk = id.public_key();
|
let pk = id.public_key();
|
||||||
IdentityKeypair::verify_raw(&pk, msg, &sig).expect("valid signature");
|
IdentityKeypair::verify_raw(&pk, msg, &sig).expect("valid signature");
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
//! P2P transport layer for quicproquo using iroh.
|
//! P2P transport layer for quicprochat using iroh.
|
||||||
//!
|
//!
|
||||||
//! Provides direct peer-to-peer QUIC connections with NAT traversal via iroh
|
//! Provides direct peer-to-peer QUIC connections with NAT traversal via iroh
|
||||||
//! relay servers. When both peers are online, messages bypass the central
|
//! relay servers. When both peers are online, messages bypass the central
|
||||||
@@ -29,10 +29,10 @@ use crate::envelope::MeshEnvelope;
|
|||||||
use crate::identity::MeshIdentity;
|
use crate::identity::MeshIdentity;
|
||||||
use crate::store::MeshStore;
|
use crate::store::MeshStore;
|
||||||
|
|
||||||
/// ALPN protocol identifier for quicproquo P2P messaging.
|
/// ALPN protocol identifier for quicprochat P2P messaging.
|
||||||
/// Updated from the original project name "quicnprotochat" to "quicproquo" (breaking wire change;
|
/// Updated from the original project name "quicnprotochat" to "quicprochat" (breaking wire change;
|
||||||
/// all peers must be on the same version to connect).
|
/// all peers must be on the same version to connect).
|
||||||
const P2P_ALPN: &[u8] = b"quicproquo/p2p/1";
|
const P2P_ALPN: &[u8] = b"quicprochat/p2p/1";
|
||||||
|
|
||||||
/// A P2P node backed by an iroh endpoint.
|
/// A P2P node backed by an iroh endpoint.
|
||||||
///
|
///
|
||||||
@@ -413,10 +413,10 @@ mod tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
router.add_peer(pk, route);
|
router.add_peer(pk, route);
|
||||||
assert!(router.peers.lock().unwrap().contains_key(&pk));
|
assert!(router.peers.lock().expect("routing table lock poisoned").contains_key(&pk));
|
||||||
|
|
||||||
router.remove_peer(&pk);
|
router.remove_peer(&pk);
|
||||||
assert!(!router.peers.lock().unwrap().contains_key(&pk));
|
assert!(!router.peers.lock().expect("routing table lock poisoned").contains_key(&pk));
|
||||||
|
|
||||||
drop(router);
|
drop(router);
|
||||||
Arc::try_unwrap(node).ok().expect("sole owner").close().await;
|
Arc::try_unwrap(node).ok().expect("sole owner").close().await;
|
||||||
@@ -30,7 +30,7 @@ pub struct MeshTrafficConfig {
|
|||||||
impl Default for MeshTrafficConfig {
|
impl Default for MeshTrafficConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
padding_boundary: quicproquo_core::padding::DEFAULT_PADDING_BOUNDARY,
|
padding_boundary: quicprochat_core::padding::DEFAULT_PADDING_BOUNDARY,
|
||||||
decoy_interval_ms: 5000,
|
decoy_interval_ms: 5000,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -38,7 +38,7 @@ impl Default for MeshTrafficConfig {
|
|||||||
|
|
||||||
/// Pad a mesh payload to the nearest boundary before wrapping in a [`MeshEnvelope`].
|
/// Pad a mesh payload to the nearest boundary before wrapping in a [`MeshEnvelope`].
|
||||||
pub fn pad_mesh_payload(payload: &[u8], boundary: usize) -> Vec<u8> {
|
pub fn pad_mesh_payload(payload: &[u8], boundary: usize) -> Vec<u8> {
|
||||||
quicproquo_core::padding::pad_uniform(payload, boundary)
|
quicprochat_core::padding::pad_uniform(payload, boundary)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a [`MeshEnvelope`] with a uniformly padded payload.
|
/// Create a [`MeshEnvelope`] with a uniformly padded payload.
|
||||||
@@ -85,7 +85,7 @@ pub fn spawn_mesh_decoy_generator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate a decoy: padded empty payload with a random recipient.
|
// Generate a decoy: padded empty payload with a random recipient.
|
||||||
let decoy_payload = quicproquo_core::padding::generate_decoy(config.padding_boundary);
|
let decoy_payload = quicprochat_core::padding::generate_decoy(config.padding_boundary);
|
||||||
let mut fake_recipient = [0u8; 32];
|
let mut fake_recipient = [0u8; 32];
|
||||||
rand::thread_rng().fill(&mut fake_recipient);
|
rand::thread_rng().fill(&mut fake_recipient);
|
||||||
|
|
||||||
@@ -121,7 +121,7 @@ mod tests {
|
|||||||
let padded = pad_mesh_payload(payload, 256);
|
let padded = pad_mesh_payload(payload, 256);
|
||||||
assert_eq!(padded.len() % 256, 0);
|
assert_eq!(padded.len() % 256, 0);
|
||||||
|
|
||||||
let unpadded = quicproquo_core::padding::unpad_uniform(&padded).unwrap();
|
let unpadded = quicprochat_core::padding::unpad_uniform(&padded).unwrap();
|
||||||
assert_eq!(unpadded, payload);
|
assert_eq!(unpadded, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,7 +136,7 @@ mod tests {
|
|||||||
assert!(env.verify());
|
assert!(env.verify());
|
||||||
|
|
||||||
// The inner payload should unpad correctly.
|
// The inner payload should unpad correctly.
|
||||||
let unpadded = quicproquo_core::padding::unpad_uniform(&env.payload).unwrap();
|
let unpadded = quicprochat_core::padding::unpad_uniform(&env.payload).unwrap();
|
||||||
assert_eq!(unpadded, b"short");
|
assert_eq!(unpadded, b"short");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,7 +149,7 @@ mod tests {
|
|||||||
assert_eq!(env.payload.len() % 256, 0);
|
assert_eq!(env.payload.len() % 256, 0);
|
||||||
assert_eq!(env.payload.len(), 512); // 500 + 4 = 504, rounds to 512
|
assert_eq!(env.payload.len(), 512); // 500 + 4 = 504, rounds to 512
|
||||||
|
|
||||||
let unpadded = quicproquo_core::padding::unpad_uniform(&env.payload).unwrap();
|
let unpadded = quicprochat_core::padding::unpad_uniform(&env.payload).unwrap();
|
||||||
assert_eq!(unpadded, payload);
|
assert_eq!(unpadded, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
13
crates/quicprochat-plugin-api/Cargo.toml
Normal file
13
crates/quicprochat-plugin-api/Cargo.toml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
[package]
|
||||||
|
name = "quicprochat-plugin-api"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition.workspace = true
|
||||||
|
description = "C-ABI vtable for quicprochat server plugins. No std dependency; usable from bare-metal plugin authors."
|
||||||
|
license = "Apache-2.0 OR MIT"
|
||||||
|
repository.workspace = true
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
|
||||||
|
# No dependencies — intentionally minimal so plugin authors have zero forced transitive deps.
|
||||||
|
[dependencies]
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
//! quicproquo server plugin API — C-ABI vtable.
|
//! quicprochat server plugin API — C-ABI vtable.
|
||||||
//!
|
//!
|
||||||
//! # Overview
|
//! # Overview
|
||||||
//!
|
//!
|
||||||
//! Every plugin is a `cdylib` that exports one symbol:
|
//! Every plugin is a `cdylib` that exports one symbol:
|
||||||
//!
|
//!
|
||||||
//! ```c
|
//! ```c
|
||||||
//! extern "C" int32_t qpq_plugin_init(HookVTable *vtable);
|
//! extern "C" int32_t qpc_plugin_init(HookVTable *vtable);
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! The server passes a zeroed [`HookVTable`] to `qpq_plugin_init`. The plugin
|
//! The server passes a zeroed [`HookVTable`] to the init function. The plugin
|
||||||
//! fills in whichever function pointers it cares about and returns `0` on
|
//! fills in whichever function pointers it cares about and returns `0` on
|
||||||
//! success or a negative error code on failure. Unused slots remain null and
|
//! success or a negative error code on failure. Unused slots remain null and
|
||||||
//! the server treats them as no-ops.
|
//! the server treats them as no-ops.
|
||||||
@@ -27,9 +27,9 @@
|
|||||||
//!
|
//!
|
||||||
//! # Return values
|
//! # Return values
|
||||||
//!
|
//!
|
||||||
//! Hooks that can reject an operation return [`HookResult`]. The server maps
|
//! Hooks that can reject an operation return an `i32` result code. The server maps
|
||||||
//! `HOOK_CONTINUE` to `HookAction::Continue` and any other value to
|
//! [`HOOK_CONTINUE`] to allow and any other value to reject, reading the reason
|
||||||
//! `HookAction::Reject` with the reason string from [`HookVTable::error_message`].
|
//! string from [`HookVTable::error_message`].
|
||||||
|
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ pub struct CFetchEvent {
|
|||||||
|
|
||||||
// ── HookVTable ────────────────────────────────────────────────────────────────
|
// ── HookVTable ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
/// C-ABI function-pointer table filled by [`qpq_plugin_init`].
|
/// C-ABI function-pointer table filled by the plugin's `qpc_plugin_init` export.
|
||||||
///
|
///
|
||||||
/// All fields default to null (no-op). The server only calls a slot when its
|
/// All fields default to null (no-op). The server only calls a slot when its
|
||||||
/// pointer is non-null. The `user_data` field is passed as the first argument
|
/// pointer is non-null. The `user_data` field is passed as the first argument
|
||||||
@@ -180,6 +180,11 @@ pub struct HookVTable {
|
|||||||
/// Called by the server when it is done with this plugin (shutdown).
|
/// Called by the server when it is done with this plugin (shutdown).
|
||||||
/// Release resources / join threads here. May be null.
|
/// Release resources / join threads here. May be null.
|
||||||
pub destroy: Option<unsafe extern "C" fn(user_data: *mut core::ffi::c_void)>,
|
pub destroy: Option<unsafe extern "C" fn(user_data: *mut core::ffi::c_void)>,
|
||||||
|
|
||||||
|
/// Called when the server is shutting down, before connections are closed.
|
||||||
|
/// Plugins can use this to flush buffers, close external connections, etc.
|
||||||
|
/// May be null (server treats it as a no-op).
|
||||||
|
pub on_shutdown: Option<unsafe extern "C" fn(user_data: *mut core::ffi::c_void)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// SAFETY: `HookVTable` contains raw pointers (`user_data`, function pointers)
|
// SAFETY: `HookVTable` contains raw pointers (`user_data`, function pointers)
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "quicproquo-proto"
|
name = "quicprochat-proto"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
edition = "2021"
|
edition.workspace = true
|
||||||
description = "Protocol types for quicproquo — v1 Cap'n Proto (legacy) + v2 Protobuf (prost)"
|
description = "Protocol types for quicprochat — v1 Cap'n Proto (legacy) + v2 Protobuf (prost)"
|
||||||
|
license = "Apache-2.0 OR MIT"
|
||||||
|
repository.workspace = true
|
||||||
|
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
//! Build script for quicproquo-proto.
|
//! Build script for quicprochat-proto.
|
||||||
//!
|
//!
|
||||||
//! Runs two code generators:
|
//! Runs two code generators:
|
||||||
//! 1. Cap'n Proto (v1 legacy) — from `schemas/*.capnp`
|
//! 1. Cap'n Proto (v1 legacy) — from `schemas/*.capnp`
|
||||||
//! 2. Protobuf/prost (v2) — from `proto/qpq/v1/*.proto`
|
//! 2. Protobuf/prost (v2) — from `proto/qpc/v1/*.proto`
|
||||||
|
|
||||||
use std::{env, path::PathBuf};
|
use std::{env, path::PathBuf};
|
||||||
|
|
||||||
@@ -40,20 +40,20 @@ fn main() {
|
|||||||
let proto_dir = workspace_root.join("proto");
|
let proto_dir = workspace_root.join("proto");
|
||||||
|
|
||||||
let proto_files = [
|
let proto_files = [
|
||||||
"qpq/v1/common.proto",
|
"qpc/v1/common.proto",
|
||||||
"qpq/v1/auth.proto",
|
"qpc/v1/auth.proto",
|
||||||
"qpq/v1/delivery.proto",
|
"qpc/v1/delivery.proto",
|
||||||
"qpq/v1/keys.proto",
|
"qpc/v1/keys.proto",
|
||||||
"qpq/v1/channel.proto",
|
"qpc/v1/channel.proto",
|
||||||
"qpq/v1/user.proto",
|
"qpc/v1/user.proto",
|
||||||
"qpq/v1/blob.proto",
|
"qpc/v1/blob.proto",
|
||||||
"qpq/v1/device.proto",
|
"qpc/v1/device.proto",
|
||||||
"qpq/v1/p2p.proto",
|
"qpc/v1/p2p.proto",
|
||||||
"qpq/v1/federation.proto",
|
"qpc/v1/federation.proto",
|
||||||
"qpq/v1/push.proto",
|
"qpc/v1/push.proto",
|
||||||
"qpq/v1/group.proto",
|
"qpc/v1/group.proto",
|
||||||
"qpq/v1/moderation.proto",
|
"qpc/v1/moderation.proto",
|
||||||
"qpq/v1/recovery.proto",
|
"qpc/v1/recovery.proto",
|
||||||
];
|
];
|
||||||
|
|
||||||
let full_paths: Vec<PathBuf> = proto_files.iter().map(|f| proto_dir.join(f)).collect();
|
let full_paths: Vec<PathBuf> = proto_files.iter().map(|f| proto_dir.join(f)).collect();
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
//! Protocol types for quicproquo.
|
//! Protocol types for quicprochat.
|
||||||
//!
|
//!
|
||||||
//! This crate contains both:
|
//! This crate contains both:
|
||||||
//! - **v1 (legacy)**: Cap'n Proto generated types from `schemas/*.capnp`
|
//! - **v1 (legacy)**: Cap'n Proto generated types from `schemas/*.capnp`
|
||||||
//! - **v2**: Protobuf generated types from `proto/qpq/v1/*.proto`
|
//! - **v2**: Protobuf generated types from `proto/qpc/v1/*.proto`
|
||||||
//!
|
//!
|
||||||
//! # Design constraints
|
//! # Design constraints
|
||||||
//!
|
//!
|
||||||
@@ -65,9 +65,9 @@ pub fn from_bytes_with_options(
|
|||||||
// ════════════════════════════════════════════════════════════════════════════
|
// ════════════════════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
/// Protobuf types for the v2 RPC protocol.
|
/// Protobuf types for the v2 RPC protocol.
|
||||||
pub mod qpq {
|
pub mod qpc {
|
||||||
pub mod v1 {
|
pub mod v1 {
|
||||||
include!(concat!(env!("OUT_DIR"), "/qpq.v1.rs"));
|
include!(concat!(env!("OUT_DIR"), "/qpc.v1.rs"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "quicproquo-rpc"
|
name = "quicprochat-rpc"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition.workspace = true
|
||||||
description = "QUIC RPC framework for quicproquo v2 — framing, dispatch, tower middleware"
|
description = "QUIC RPC framework for quicprochat v2 — framing, dispatch, tower middleware"
|
||||||
|
license = "Apache-2.0 OR MIT"
|
||||||
|
repository.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
quicproquo-proto = { path = "../quicproquo-proto" }
|
quicprochat-proto = { path = "../quicprochat-proto" }
|
||||||
prost = { workspace = true }
|
prost = { workspace = true }
|
||||||
bytes = { workspace = true }
|
bytes = { workspace = true }
|
||||||
quinn = { workspace = true }
|
quinn = { workspace = true }
|
||||||
@@ -18,6 +20,7 @@ tracing = { workspace = true }
|
|||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
dashmap = { workspace = true }
|
dashmap = { workspace = true }
|
||||||
sha2 = { workspace = true }
|
sha2 = { workspace = true }
|
||||||
|
rand = { workspace = true }
|
||||||
uuid = { version = "1", features = ["v7"] }
|
uuid = { version = "1", features = ["v7"] }
|
||||||
metrics = "0.22"
|
metrics = "0.22"
|
||||||
|
|
||||||
393
crates/quicprochat-rpc/src/client.rs
Normal file
393
crates/quicprochat-rpc/src/client.rs
Normal file
@@ -0,0 +1,393 @@
|
|||||||
|
//! QUIC RPC client — connect to server, send requests, receive push events.
|
||||||
|
//!
|
||||||
|
//! Supports auto-reconnect with exponential backoff, keepalive pings, and
|
||||||
|
//! push subscription recovery.
|
||||||
|
|
||||||
|
use std::sync::atomic::{AtomicU32, Ordering};
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use bytes::{Bytes, BytesMut};
|
||||||
|
use quinn::{Connection, Endpoint};
|
||||||
|
use tokio::sync::{mpsc, Mutex};
|
||||||
|
use tracing::{debug, info, warn};
|
||||||
|
|
||||||
|
use crate::auth_handshake;
|
||||||
|
use crate::error::{RpcError, RpcStatus};
|
||||||
|
use crate::framing::{PushFrame, RequestFrame, ResponseFrame};
|
||||||
|
|
||||||
|
/// Default maximum retries for auto-reconnect (including first attempt).
|
||||||
|
pub const DEFAULT_MAX_RETRIES: u32 = 3;
|
||||||
|
/// Default base delay for exponential backoff (milliseconds).
|
||||||
|
pub const DEFAULT_BASE_DELAY_MS: u64 = 500;
|
||||||
|
/// Default maximum backoff cap (milliseconds).
|
||||||
|
pub const DEFAULT_MAX_BACKOFF_MS: u64 = 30_000;
|
||||||
|
/// Default keepalive interval (seconds).
|
||||||
|
pub const DEFAULT_KEEPALIVE_SECS: u64 = 30;
|
||||||
|
|
||||||
|
/// Configuration for the RPC client.
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct RpcClientConfig {
|
||||||
|
/// Server address to connect to.
|
||||||
|
pub server_addr: std::net::SocketAddr,
|
||||||
|
/// Server name for TLS verification.
|
||||||
|
pub server_name: String,
|
||||||
|
/// TLS client config (rustls).
|
||||||
|
pub tls_config: Arc<rustls::ClientConfig>,
|
||||||
|
/// ALPN protocol.
|
||||||
|
pub alpn: Vec<u8>,
|
||||||
|
/// Session token to send during auth handshake.
|
||||||
|
pub session_token: Option<Vec<u8>>,
|
||||||
|
/// Max retries on connection failure (default 3).
|
||||||
|
pub max_retries: u32,
|
||||||
|
/// Base delay for backoff in milliseconds (default 500).
|
||||||
|
pub base_delay_ms: u64,
|
||||||
|
/// Maximum backoff cap in milliseconds (default 30000).
|
||||||
|
pub max_backoff_ms: u64,
|
||||||
|
/// Keepalive interval in seconds (default 30). Set to 0 to disable.
|
||||||
|
pub keepalive_secs: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RpcClientConfig {
|
||||||
|
/// Fill in default values for zero/unset fields.
|
||||||
|
fn with_defaults(mut self) -> Self {
|
||||||
|
if self.max_retries == 0 {
|
||||||
|
self.max_retries = DEFAULT_MAX_RETRIES;
|
||||||
|
}
|
||||||
|
if self.base_delay_ms == 0 {
|
||||||
|
self.base_delay_ms = DEFAULT_BASE_DELAY_MS;
|
||||||
|
}
|
||||||
|
if self.max_backoff_ms == 0 {
|
||||||
|
self.max_backoff_ms = DEFAULT_MAX_BACKOFF_MS;
|
||||||
|
}
|
||||||
|
if self.keepalive_secs == 0 {
|
||||||
|
self.keepalive_secs = DEFAULT_KEEPALIVE_SECS;
|
||||||
|
}
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Connection state for the RPC client.
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub enum ConnectionState {
|
||||||
|
/// Connected and ready to send/receive.
|
||||||
|
Connected,
|
||||||
|
/// Connection lost, attempting to reconnect.
|
||||||
|
Reconnecting { attempt: u32 },
|
||||||
|
/// Disconnected (intentional or exhausted retries).
|
||||||
|
Disconnected,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for ConnectionState {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::Connected => write!(f, "Connected"),
|
||||||
|
Self::Reconnecting { attempt } => write!(f, "Reconnecting (attempt {attempt})"),
|
||||||
|
Self::Disconnected => write!(f, "Disconnected"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A QUIC RPC client connection with auto-reconnect support.
|
||||||
|
pub struct RpcClient {
|
||||||
|
connection: Mutex<Connection>,
|
||||||
|
endpoint: Endpoint,
|
||||||
|
config: RpcClientConfig,
|
||||||
|
next_request_id: AtomicU32,
|
||||||
|
state: std::sync::Mutex<ConnectionState>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RpcClient {
|
||||||
|
/// Connect to the RPC server.
|
||||||
|
pub async fn connect(config: RpcClientConfig) -> Result<Self, RpcError> {
|
||||||
|
let config = config.with_defaults();
|
||||||
|
let (endpoint, connection) = Self::establish(&config).await?;
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
|
connection: Mutex::new(connection),
|
||||||
|
endpoint,
|
||||||
|
config,
|
||||||
|
next_request_id: AtomicU32::new(1),
|
||||||
|
state: std::sync::Mutex::new(ConnectionState::Connected),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Establish a new QUIC connection + optional auth handshake.
|
||||||
|
async fn establish(config: &RpcClientConfig) -> Result<(Endpoint, Connection), RpcError> {
|
||||||
|
let mut tls = (*config.tls_config).clone();
|
||||||
|
tls.alpn_protocols = vec![config.alpn.clone()];
|
||||||
|
let quic_tls = quinn::crypto::rustls::QuicClientConfig::try_from(tls)
|
||||||
|
.map_err(|e| RpcError::Connection(format!("TLS config: {e}")))?;
|
||||||
|
|
||||||
|
let bind_addr = std::net::SocketAddr::new(
|
||||||
|
std::net::IpAddr::V4(std::net::Ipv4Addr::UNSPECIFIED),
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
let mut endpoint = Endpoint::client(bind_addr)
|
||||||
|
.map_err(|e| RpcError::Connection(e.to_string()))?;
|
||||||
|
|
||||||
|
let mut quinn_config = quinn::ClientConfig::new(Arc::new(quic_tls));
|
||||||
|
// Enable QUIC-level keepalive.
|
||||||
|
let mut transport = quinn::TransportConfig::default();
|
||||||
|
transport.keep_alive_interval(Some(Duration::from_secs(config.keepalive_secs)));
|
||||||
|
quinn_config.transport_config(Arc::new(transport));
|
||||||
|
endpoint.set_default_client_config(quinn_config);
|
||||||
|
|
||||||
|
let connection = endpoint
|
||||||
|
.connect(config.server_addr, &config.server_name)
|
||||||
|
.map_err(|e| RpcError::Connection(e.to_string()))?
|
||||||
|
.await
|
||||||
|
.map_err(|e| RpcError::Connection(e.to_string()))?;
|
||||||
|
|
||||||
|
debug!(remote = %connection.remote_address(), "connected to RPC server");
|
||||||
|
|
||||||
|
// Perform auth handshake if a session token was provided.
|
||||||
|
if let Some(ref token) = config.session_token {
|
||||||
|
Self::do_auth_handshake(&connection, token).await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok((endpoint, connection))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Perform the auth handshake on a connection.
|
||||||
|
async fn do_auth_handshake(connection: &Connection, token: &[u8]) -> Result<(), RpcError> {
|
||||||
|
let (mut send, mut recv) = connection
|
||||||
|
.open_bi()
|
||||||
|
.await
|
||||||
|
.map_err(|e| RpcError::Connection(format!("open auth stream: {e}")))?;
|
||||||
|
|
||||||
|
auth_handshake::send_auth_init(&mut send, token).await?;
|
||||||
|
send.finish()
|
||||||
|
.map_err(|e| RpcError::Connection(format!("finish auth send: {e}")))?;
|
||||||
|
auth_handshake::recv_auth_ack(&mut recv).await?;
|
||||||
|
debug!("auth handshake complete");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Attempt to reconnect to the server with exponential backoff.
|
||||||
|
/// Returns `Ok(())` on success, `Err` if all retries exhausted.
|
||||||
|
async fn reconnect(&self) -> Result<(), RpcError> {
|
||||||
|
let max = self.config.max_retries;
|
||||||
|
let base = self.config.base_delay_ms;
|
||||||
|
let cap = self.config.max_backoff_ms;
|
||||||
|
|
||||||
|
for attempt in 1..=max {
|
||||||
|
self.set_state(ConnectionState::Reconnecting { attempt });
|
||||||
|
info!(attempt, max, "attempting reconnect");
|
||||||
|
|
||||||
|
// Exponential backoff with jitter, capped.
|
||||||
|
let delay_ms = (base * 2u64.saturating_pow(attempt.saturating_sub(1))).min(cap);
|
||||||
|
let jitter_ms = rand::Rng::gen_range(&mut rand::thread_rng(), 0..=delay_ms / 2);
|
||||||
|
tokio::time::sleep(Duration::from_millis(delay_ms + jitter_ms)).await;
|
||||||
|
|
||||||
|
match self.try_connect_once().await {
|
||||||
|
Ok(new_conn) => {
|
||||||
|
// Auth handshake on the new connection.
|
||||||
|
if let Some(ref token) = self.config.session_token {
|
||||||
|
if let Err(e) = Self::do_auth_handshake(&new_conn, token).await {
|
||||||
|
warn!(attempt, "reconnect auth handshake failed: {e}");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Swap the connection under the lock.
|
||||||
|
*self.connection.lock().await = new_conn;
|
||||||
|
self.set_state(ConnectionState::Connected);
|
||||||
|
info!("reconnected successfully");
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
warn!(attempt, max, "reconnect attempt failed: {e}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.set_state(ConnectionState::Disconnected);
|
||||||
|
Err(RpcError::Connection(format!(
|
||||||
|
"reconnect failed after {max} attempts"
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Single connection attempt (no retry).
|
||||||
|
async fn try_connect_once(&self) -> Result<Connection, RpcError> {
|
||||||
|
let conn = self
|
||||||
|
.endpoint
|
||||||
|
.connect(self.config.server_addr, &self.config.server_name)
|
||||||
|
.map_err(|e| RpcError::Connection(e.to_string()))?
|
||||||
|
.await
|
||||||
|
.map_err(|e| RpcError::Connection(e.to_string()))?;
|
||||||
|
Ok(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Send an RPC request and wait for the response.
|
||||||
|
///
|
||||||
|
/// On retriable connection errors, automatically reconnects and retries.
|
||||||
|
pub async fn call(
|
||||||
|
&self,
|
||||||
|
method_id: u16,
|
||||||
|
payload: Bytes,
|
||||||
|
) -> Result<Bytes, RpcError> {
|
||||||
|
let conn = self.connection.lock().await.clone();
|
||||||
|
match Self::call_on(&conn, &self.next_request_id, method_id, payload.clone()).await {
|
||||||
|
Ok(resp) => Ok(resp),
|
||||||
|
Err(e) if e.is_retriable() && conn.close_reason().is_some() => {
|
||||||
|
// Connection is dead — try reconnect then retry once.
|
||||||
|
warn!("connection lost during RPC call, attempting reconnect");
|
||||||
|
drop(conn);
|
||||||
|
self.reconnect().await?;
|
||||||
|
let conn = self.connection.lock().await.clone();
|
||||||
|
Self::call_on(&conn, &self.next_request_id, method_id, payload).await
|
||||||
|
}
|
||||||
|
Err(e) => Err(e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Inner call implementation on a specific connection.
|
||||||
|
async fn call_on(
|
||||||
|
connection: &Connection,
|
||||||
|
next_request_id: &AtomicU32,
|
||||||
|
method_id: u16,
|
||||||
|
payload: Bytes,
|
||||||
|
) -> Result<Bytes, RpcError> {
|
||||||
|
let request_id = next_request_id.fetch_add(1, Ordering::Relaxed);
|
||||||
|
|
||||||
|
let (mut send, mut recv) = connection
|
||||||
|
.open_bi()
|
||||||
|
.await
|
||||||
|
.map_err(|e| RpcError::Connection(e.to_string()))?;
|
||||||
|
|
||||||
|
// Send request.
|
||||||
|
let frame = RequestFrame {
|
||||||
|
method_id,
|
||||||
|
request_id,
|
||||||
|
payload,
|
||||||
|
};
|
||||||
|
let encoded = frame.encode();
|
||||||
|
send.write_all(&encoded)
|
||||||
|
.await
|
||||||
|
.map_err(|e| RpcError::Connection(e.to_string()))?;
|
||||||
|
send.finish().map_err(|e| RpcError::Connection(e.to_string()))?;
|
||||||
|
|
||||||
|
// Read response.
|
||||||
|
let mut buf = BytesMut::new();
|
||||||
|
while let Some(chunk) = recv
|
||||||
|
.read_chunk(65536, true)
|
||||||
|
.await
|
||||||
|
.map_err(|e| RpcError::Connection(e.to_string()))?
|
||||||
|
{
|
||||||
|
buf.extend_from_slice(&chunk.bytes);
|
||||||
|
if buf.len() > crate::framing::MAX_PAYLOAD_SIZE + crate::framing::RESPONSE_HEADER_SIZE {
|
||||||
|
return Err(RpcError::PayloadTooLarge {
|
||||||
|
size: buf.len(),
|
||||||
|
max: crate::framing::MAX_PAYLOAD_SIZE,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let response = ResponseFrame::decode(&mut buf)?
|
||||||
|
.ok_or_else(|| RpcError::Decode("incomplete response frame".into()))?;
|
||||||
|
|
||||||
|
if response.request_id != request_id {
|
||||||
|
return Err(RpcError::Decode(format!(
|
||||||
|
"request_id mismatch: sent {request_id}, got {}",
|
||||||
|
response.request_id
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
match RpcStatus::from_u8(response.status) {
|
||||||
|
Some(RpcStatus::Ok) => Ok(response.payload),
|
||||||
|
Some(status) => Err(RpcError::Server {
|
||||||
|
status,
|
||||||
|
message: String::from_utf8_lossy(&response.payload).into_owned(),
|
||||||
|
}),
|
||||||
|
None => Err(RpcError::Decode(format!(
|
||||||
|
"unknown status byte: {}",
|
||||||
|
response.status
|
||||||
|
))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Subscribe to server-push events. Returns a receiver channel.
|
||||||
|
///
|
||||||
|
/// Spawns a background task that reads uni-streams. When the push stream
|
||||||
|
/// breaks (connection error, EOF), a `None` sentinel is sent so the
|
||||||
|
/// caller can detect the break and resubscribe after reconnection.
|
||||||
|
///
|
||||||
|
/// This is an async method because it needs to clone the current connection.
|
||||||
|
pub async fn subscribe_push(&self) -> mpsc::UnboundedReceiver<Option<PushFrame>> {
|
||||||
|
let (tx, rx) = mpsc::unbounded_channel();
|
||||||
|
let conn = self.connection.lock().await.clone();
|
||||||
|
tokio::spawn(Self::push_loop(conn, tx));
|
||||||
|
rx
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn push_loop(conn: Connection, tx: mpsc::UnboundedSender<Option<PushFrame>>) {
|
||||||
|
loop {
|
||||||
|
match conn.accept_uni().await {
|
||||||
|
Ok(mut recv) => {
|
||||||
|
let mut buf = BytesMut::new();
|
||||||
|
loop {
|
||||||
|
match recv.read_chunk(65536, true).await {
|
||||||
|
Ok(Some(chunk)) => buf.extend_from_slice(&chunk.bytes),
|
||||||
|
Ok(None) => break,
|
||||||
|
Err(e) => {
|
||||||
|
debug!("push stream read error: {e}");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match PushFrame::decode(&mut buf) {
|
||||||
|
Ok(Some(frame)) => {
|
||||||
|
if tx.send(Some(frame)).is_err() {
|
||||||
|
return; // receiver dropped
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(None) => debug!("incomplete push frame"),
|
||||||
|
Err(e) => debug!("push decode error: {e}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(quinn::ConnectionError::ApplicationClosed(_)) => {
|
||||||
|
let _ = tx.send(None);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
warn!("accept_uni error: {e}");
|
||||||
|
let _ = tx.send(None);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Close the connection gracefully.
|
||||||
|
pub fn close(&self) {
|
||||||
|
self.set_state(ConnectionState::Disconnected);
|
||||||
|
if let Ok(conn) = self.connection.try_lock() {
|
||||||
|
conn.close(0u32.into(), b"bye");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the underlying QUIC connection (for advanced use).
|
||||||
|
pub async fn connection(&self) -> Connection {
|
||||||
|
self.connection.lock().await.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the current connection state.
|
||||||
|
pub fn connection_state(&self) -> ConnectionState {
|
||||||
|
*self.state.lock().unwrap_or_else(|e| e.into_inner())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check if the connection appears alive (no close reason set).
|
||||||
|
pub fn is_alive(&self) -> bool {
|
||||||
|
match self.connection.try_lock() {
|
||||||
|
Ok(conn) => conn.close_reason().is_none(),
|
||||||
|
Err(_) => true, // locked = likely in use = alive
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_state(&self, new_state: ConnectionState) {
|
||||||
|
if let Ok(mut s) = self.state.lock() {
|
||||||
|
*s = new_state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
163
crates/quicprochat-rpc/src/error.rs
Normal file
163
crates/quicprochat-rpc/src/error.rs
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
//! RPC error types.
|
||||||
|
|
||||||
|
/// Status codes for RPC responses.
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
#[repr(u8)]
|
||||||
|
pub enum RpcStatus {
|
||||||
|
/// Request succeeded.
|
||||||
|
Ok = 0,
|
||||||
|
/// Client sent a malformed request.
|
||||||
|
BadRequest = 1,
|
||||||
|
/// Authentication required or token invalid.
|
||||||
|
Unauthorized = 2,
|
||||||
|
/// Caller lacks permission for this operation.
|
||||||
|
Forbidden = 3,
|
||||||
|
/// Requested resource not found.
|
||||||
|
NotFound = 4,
|
||||||
|
/// Rate limit exceeded.
|
||||||
|
RateLimited = 5,
|
||||||
|
/// Request deadline exceeded (server-side timeout).
|
||||||
|
DeadlineExceeded = 8,
|
||||||
|
/// Server is shutting down (draining).
|
||||||
|
Unavailable = 9,
|
||||||
|
/// Internal server error.
|
||||||
|
Internal = 10,
|
||||||
|
/// Method not recognized.
|
||||||
|
UnknownMethod = 11,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RpcStatus {
|
||||||
|
/// Decode a status byte. Returns `None` for unknown values.
|
||||||
|
pub fn from_u8(v: u8) -> Option<Self> {
|
||||||
|
match v {
|
||||||
|
0 => Some(Self::Ok),
|
||||||
|
1 => Some(Self::BadRequest),
|
||||||
|
2 => Some(Self::Unauthorized),
|
||||||
|
3 => Some(Self::Forbidden),
|
||||||
|
4 => Some(Self::NotFound),
|
||||||
|
5 => Some(Self::RateLimited),
|
||||||
|
8 => Some(Self::DeadlineExceeded),
|
||||||
|
9 => Some(Self::Unavailable),
|
||||||
|
10 => Some(Self::Internal),
|
||||||
|
11 => Some(Self::UnknownMethod),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Errors that can occur in the RPC layer.
|
||||||
|
#[derive(Debug, thiserror::Error)]
|
||||||
|
pub enum RpcError {
|
||||||
|
#[error("connection error: {0}")]
|
||||||
|
Connection(String),
|
||||||
|
|
||||||
|
#[error("encoding error: {0}")]
|
||||||
|
Encode(String),
|
||||||
|
|
||||||
|
#[error("decoding error: {0}")]
|
||||||
|
Decode(String),
|
||||||
|
|
||||||
|
#[error("server returned error status {status:?}: {message}")]
|
||||||
|
Server {
|
||||||
|
status: RpcStatus,
|
||||||
|
message: String,
|
||||||
|
},
|
||||||
|
|
||||||
|
#[error("request timed out")]
|
||||||
|
Timeout,
|
||||||
|
|
||||||
|
#[error("stream closed unexpectedly")]
|
||||||
|
StreamClosed,
|
||||||
|
|
||||||
|
#[error("payload too large: {size} bytes (max {max})")]
|
||||||
|
PayloadTooLarge { size: usize, max: usize },
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RpcError {
|
||||||
|
/// Returns `true` if this error is transient and the operation may succeed
|
||||||
|
/// on retry (e.g. connection reset, timeout, server 5xx). Returns `false`
|
||||||
|
/// for permanent failures (auth, bad request, payload limits).
|
||||||
|
pub fn is_retriable(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
Self::Connection(_) | Self::Timeout | Self::StreamClosed => true,
|
||||||
|
Self::Server { status, .. } => matches!(
|
||||||
|
status,
|
||||||
|
RpcStatus::Unavailable
|
||||||
|
| RpcStatus::DeadlineExceeded
|
||||||
|
| RpcStatus::Internal
|
||||||
|
| RpcStatus::RateLimited
|
||||||
|
),
|
||||||
|
Self::Encode(_) | Self::Decode(_) | Self::PayloadTooLarge { .. } => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn retriable_errors() {
|
||||||
|
assert!(RpcError::Connection("reset".into()).is_retriable());
|
||||||
|
assert!(RpcError::Timeout.is_retriable());
|
||||||
|
assert!(RpcError::StreamClosed.is_retriable());
|
||||||
|
assert!(RpcError::Server {
|
||||||
|
status: RpcStatus::Unavailable,
|
||||||
|
message: String::new(),
|
||||||
|
}
|
||||||
|
.is_retriable());
|
||||||
|
assert!(RpcError::Server {
|
||||||
|
status: RpcStatus::Internal,
|
||||||
|
message: String::new(),
|
||||||
|
}
|
||||||
|
.is_retriable());
|
||||||
|
assert!(RpcError::Server {
|
||||||
|
status: RpcStatus::DeadlineExceeded,
|
||||||
|
message: String::new(),
|
||||||
|
}
|
||||||
|
.is_retriable());
|
||||||
|
assert!(RpcError::Server {
|
||||||
|
status: RpcStatus::RateLimited,
|
||||||
|
message: String::new(),
|
||||||
|
}
|
||||||
|
.is_retriable());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn non_retriable_errors() {
|
||||||
|
assert!(!RpcError::Encode("bad".into()).is_retriable());
|
||||||
|
assert!(!RpcError::Decode("bad".into()).is_retriable());
|
||||||
|
assert!(!RpcError::PayloadTooLarge { size: 100, max: 50 }.is_retriable());
|
||||||
|
assert!(!RpcError::Server {
|
||||||
|
status: RpcStatus::Unauthorized,
|
||||||
|
message: String::new(),
|
||||||
|
}
|
||||||
|
.is_retriable());
|
||||||
|
assert!(!RpcError::Server {
|
||||||
|
status: RpcStatus::BadRequest,
|
||||||
|
message: String::new(),
|
||||||
|
}
|
||||||
|
.is_retriable());
|
||||||
|
assert!(!RpcError::Server {
|
||||||
|
status: RpcStatus::Forbidden,
|
||||||
|
message: String::new(),
|
||||||
|
}
|
||||||
|
.is_retriable());
|
||||||
|
assert!(!RpcError::Server {
|
||||||
|
status: RpcStatus::NotFound,
|
||||||
|
message: String::new(),
|
||||||
|
}
|
||||||
|
.is_retriable());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn connection_state_display() {
|
||||||
|
use crate::client::ConnectionState;
|
||||||
|
assert_eq!(ConnectionState::Connected.to_string(), "Connected");
|
||||||
|
assert_eq!(ConnectionState::Disconnected.to_string(), "Disconnected");
|
||||||
|
assert_eq!(
|
||||||
|
ConnectionState::Reconnecting { attempt: 2 }.to_string(),
|
||||||
|
"Reconnecting (attempt 2)"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
//! Wire format encoding and decoding for the quicproquo v2 RPC protocol.
|
//! Wire format encoding and decoding for the quicprochat v2 RPC protocol.
|
||||||
//!
|
//!
|
||||||
//! ## Request frame
|
//! ## Request frame
|
||||||
//! ```text
|
//! ```text
|
||||||
@@ -277,4 +277,241 @@ mod tests {
|
|||||||
let decoded = RequestFrame::decode(&mut buf).expect("decode").expect("complete");
|
let decoded = RequestFrame::decode(&mut buf).expect("decode").expect("complete");
|
||||||
assert!(decoded.payload.is_empty());
|
assert!(decoded.payload.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Additional framing tests ────────────────────────────────────────────
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn empty_payload_response() {
|
||||||
|
let frame = ResponseFrame {
|
||||||
|
status: RpcStatus::NotFound as u8,
|
||||||
|
request_id: 999,
|
||||||
|
payload: Bytes::new(),
|
||||||
|
};
|
||||||
|
let encoded = frame.encode();
|
||||||
|
assert_eq!(encoded.len(), RESPONSE_HEADER_SIZE);
|
||||||
|
let mut buf = BytesMut::from(encoded.as_ref());
|
||||||
|
let decoded = ResponseFrame::decode(&mut buf).expect("decode").expect("complete");
|
||||||
|
assert!(decoded.payload.is_empty());
|
||||||
|
assert_eq!(decoded.status, RpcStatus::NotFound as u8);
|
||||||
|
assert_eq!(decoded.request_id, 999);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn empty_payload_push() {
|
||||||
|
let frame = PushFrame {
|
||||||
|
event_type: 0,
|
||||||
|
payload: Bytes::new(),
|
||||||
|
};
|
||||||
|
let encoded = frame.encode();
|
||||||
|
assert_eq!(encoded.len(), PUSH_HEADER_SIZE);
|
||||||
|
let mut buf = BytesMut::from(encoded.as_ref());
|
||||||
|
let decoded = PushFrame::decode(&mut buf).expect("decode").expect("complete");
|
||||||
|
assert!(decoded.payload.is_empty());
|
||||||
|
assert_eq!(decoded.event_type, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn max_boundary_payload_request() {
|
||||||
|
// Exactly MAX_PAYLOAD_SIZE should succeed (not exceed limit).
|
||||||
|
let payload = vec![0xABu8; MAX_PAYLOAD_SIZE];
|
||||||
|
let frame = RequestFrame {
|
||||||
|
method_id: 1,
|
||||||
|
request_id: 1,
|
||||||
|
payload: Bytes::from(payload.clone()),
|
||||||
|
};
|
||||||
|
let encoded = frame.encode();
|
||||||
|
assert_eq!(encoded.len(), REQUEST_HEADER_SIZE + MAX_PAYLOAD_SIZE);
|
||||||
|
let mut buf = BytesMut::from(encoded.as_ref());
|
||||||
|
let decoded = RequestFrame::decode(&mut buf).expect("decode").expect("complete");
|
||||||
|
assert_eq!(decoded.payload.len(), MAX_PAYLOAD_SIZE);
|
||||||
|
assert_eq!(decoded.payload[0], 0xAB);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn response_payload_too_large_rejected() {
|
||||||
|
let mut buf = BytesMut::new();
|
||||||
|
buf.put_u8(0); // status OK
|
||||||
|
buf.put_u32(1); // request_id
|
||||||
|
buf.put_u32((MAX_PAYLOAD_SIZE + 1) as u32);
|
||||||
|
let result = ResponseFrame::decode(&mut buf);
|
||||||
|
assert!(matches!(result, Err(RpcError::PayloadTooLarge { .. })));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn push_payload_too_large_rejected() {
|
||||||
|
let mut buf = BytesMut::new();
|
||||||
|
buf.put_u16(1); // event_type
|
||||||
|
buf.put_u32((MAX_PAYLOAD_SIZE + 1) as u32);
|
||||||
|
let result = PushFrame::decode(&mut buf);
|
||||||
|
assert!(matches!(result, Err(RpcError::PayloadTooLarge { .. })));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn incomplete_response_returns_none() {
|
||||||
|
// Less than RESPONSE_HEADER_SIZE bytes
|
||||||
|
let mut buf = BytesMut::from(&[0u8; 4][..]);
|
||||||
|
assert!(ResponseFrame::decode(&mut buf).expect("no error").is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn incomplete_push_returns_none() {
|
||||||
|
// Less than PUSH_HEADER_SIZE bytes
|
||||||
|
let mut buf = BytesMut::from(&[0u8; 3][..]);
|
||||||
|
assert!(PushFrame::decode(&mut buf).expect("no error").is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn request_header_present_but_payload_incomplete() {
|
||||||
|
// Full header but payload not yet received
|
||||||
|
let frame = RequestFrame {
|
||||||
|
method_id: 10,
|
||||||
|
request_id: 20,
|
||||||
|
payload: Bytes::from_static(b"abcdefgh"),
|
||||||
|
};
|
||||||
|
let encoded = frame.encode();
|
||||||
|
// Truncate to header + 3 bytes of payload (need 8)
|
||||||
|
let mut buf = BytesMut::from(&encoded[..REQUEST_HEADER_SIZE + 3]);
|
||||||
|
assert!(RequestFrame::decode(&mut buf).expect("no error").is_none());
|
||||||
|
// Buffer should be untouched (not consumed)
|
||||||
|
assert_eq!(buf.len(), REQUEST_HEADER_SIZE + 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn response_header_present_but_payload_incomplete() {
|
||||||
|
let frame = ResponseFrame {
|
||||||
|
status: 0,
|
||||||
|
request_id: 1,
|
||||||
|
payload: Bytes::from_static(b"abcdefgh"),
|
||||||
|
};
|
||||||
|
let encoded = frame.encode();
|
||||||
|
let mut buf = BytesMut::from(&encoded[..RESPONSE_HEADER_SIZE + 2]);
|
||||||
|
assert!(ResponseFrame::decode(&mut buf).expect("no error").is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn push_header_present_but_payload_incomplete() {
|
||||||
|
let frame = PushFrame {
|
||||||
|
event_type: 1,
|
||||||
|
payload: Bytes::from_static(b"abcdefgh"),
|
||||||
|
};
|
||||||
|
let encoded = frame.encode();
|
||||||
|
let mut buf = BytesMut::from(&encoded[..PUSH_HEADER_SIZE + 2]);
|
||||||
|
assert!(PushFrame::decode(&mut buf).expect("no error").is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn request_zero_length_prefix() {
|
||||||
|
// Zero-length payload in the header is valid (empty payload)
|
||||||
|
let mut buf = BytesMut::new();
|
||||||
|
buf.put_u16(5); // method_id
|
||||||
|
buf.put_u32(10); // request_id
|
||||||
|
buf.put_u32(0); // payload_len = 0
|
||||||
|
let decoded = RequestFrame::decode(&mut buf).expect("decode").expect("complete");
|
||||||
|
assert_eq!(decoded.method_id, 5);
|
||||||
|
assert_eq!(decoded.request_id, 10);
|
||||||
|
assert!(decoded.payload.is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn response_rpc_status_conversion() {
|
||||||
|
let frame = ResponseFrame {
|
||||||
|
status: RpcStatus::Unauthorized as u8,
|
||||||
|
request_id: 1,
|
||||||
|
payload: Bytes::new(),
|
||||||
|
};
|
||||||
|
assert_eq!(frame.rpc_status(), Some(RpcStatus::Unauthorized));
|
||||||
|
|
||||||
|
let unknown = ResponseFrame {
|
||||||
|
status: 255,
|
||||||
|
request_id: 1,
|
||||||
|
payload: Bytes::new(),
|
||||||
|
};
|
||||||
|
assert_eq!(unknown.rpc_status(), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn all_method_ids_roundtrip() {
|
||||||
|
// Test a selection of method IDs spanning the full u16 range
|
||||||
|
let method_ids: &[u16] = &[0, 1, 100, 200, 300, 400, 500, 1000, u16::MAX];
|
||||||
|
for &mid in method_ids {
|
||||||
|
let frame = RequestFrame {
|
||||||
|
method_id: mid,
|
||||||
|
request_id: mid as u32,
|
||||||
|
payload: Bytes::from_static(b"x"),
|
||||||
|
};
|
||||||
|
let encoded = frame.encode();
|
||||||
|
let mut buf = BytesMut::from(encoded.as_ref());
|
||||||
|
let decoded = RequestFrame::decode(&mut buf).unwrap().unwrap();
|
||||||
|
assert_eq!(decoded.method_id, mid);
|
||||||
|
assert_eq!(decoded.request_id, mid as u32);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn all_rpc_status_values_roundtrip() {
|
||||||
|
let statuses = [
|
||||||
|
RpcStatus::Ok,
|
||||||
|
RpcStatus::BadRequest,
|
||||||
|
RpcStatus::Unauthorized,
|
||||||
|
RpcStatus::Forbidden,
|
||||||
|
RpcStatus::NotFound,
|
||||||
|
RpcStatus::RateLimited,
|
||||||
|
RpcStatus::DeadlineExceeded,
|
||||||
|
RpcStatus::Unavailable,
|
||||||
|
RpcStatus::Internal,
|
||||||
|
RpcStatus::UnknownMethod,
|
||||||
|
];
|
||||||
|
for status in statuses {
|
||||||
|
let frame = ResponseFrame {
|
||||||
|
status: status as u8,
|
||||||
|
request_id: 1,
|
||||||
|
payload: Bytes::new(),
|
||||||
|
};
|
||||||
|
let encoded = frame.encode();
|
||||||
|
let mut buf = BytesMut::from(encoded.as_ref());
|
||||||
|
let decoded = ResponseFrame::decode(&mut buf).unwrap().unwrap();
|
||||||
|
assert_eq!(decoded.rpc_status(), Some(status));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn request_max_request_id() {
|
||||||
|
let frame = RequestFrame {
|
||||||
|
method_id: 1,
|
||||||
|
request_id: u32::MAX,
|
||||||
|
payload: Bytes::from_static(b"max-id"),
|
||||||
|
};
|
||||||
|
let encoded = frame.encode();
|
||||||
|
let mut buf = BytesMut::from(encoded.as_ref());
|
||||||
|
let decoded = RequestFrame::decode(&mut buf).unwrap().unwrap();
|
||||||
|
assert_eq!(decoded.request_id, u32::MAX);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn multiple_frames_in_buffer() {
|
||||||
|
// Two request frames concatenated in one buffer
|
||||||
|
let f1 = RequestFrame {
|
||||||
|
method_id: 1,
|
||||||
|
request_id: 10,
|
||||||
|
payload: Bytes::from_static(b"first"),
|
||||||
|
};
|
||||||
|
let f2 = RequestFrame {
|
||||||
|
method_id: 2,
|
||||||
|
request_id: 20,
|
||||||
|
payload: Bytes::from_static(b"second"),
|
||||||
|
};
|
||||||
|
let mut buf = BytesMut::new();
|
||||||
|
buf.extend_from_slice(&f1.encode());
|
||||||
|
buf.extend_from_slice(&f2.encode());
|
||||||
|
|
||||||
|
let d1 = RequestFrame::decode(&mut buf).unwrap().unwrap();
|
||||||
|
assert_eq!(d1.method_id, 1);
|
||||||
|
assert_eq!(d1.payload, Bytes::from_static(b"first"));
|
||||||
|
|
||||||
|
let d2 = RequestFrame::decode(&mut buf).unwrap().unwrap();
|
||||||
|
assert_eq!(d2.method_id, 2);
|
||||||
|
assert_eq!(d2.payload, Bytes::from_static(b"second"));
|
||||||
|
|
||||||
|
assert!(buf.is_empty());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
49
crates/quicprochat-rpc/src/lib.rs
Normal file
49
crates/quicprochat-rpc/src/lib.rs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
//! QUIC RPC framework for quicprochat v2.
|
||||||
|
//!
|
||||||
|
//! This crate implements a lightweight, binary-framed RPC protocol over QUIC.
|
||||||
|
//! Each RPC call opens a new QUIC bi-directional stream, sends a request frame,
|
||||||
|
//! and reads a response frame. Server-initiated push events use uni-streams.
|
||||||
|
//!
|
||||||
|
//! # Wire format
|
||||||
|
//!
|
||||||
|
//! All integers are big-endian.
|
||||||
|
//!
|
||||||
|
//! **Request** (client → server, bi-stream):
|
||||||
|
//! ```text
|
||||||
|
//! [method_id: u16][request_id: u32][payload_len: u32][protobuf bytes]
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
|
//! **Response** (server → client, same bi-stream):
|
||||||
|
//! ```text
|
||||||
|
//! [status: u8][request_id: u32][payload_len: u32][protobuf bytes]
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
|
//! **Push** (server → client, uni-stream):
|
||||||
|
//! ```text
|
||||||
|
//! [event_type: u16][payload_len: u32][protobuf bytes]
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
|
//! # Architecture
|
||||||
|
//!
|
||||||
|
//! - [`framing`] — frame types ([`framing::RequestFrame`], [`framing::ResponseFrame`],
|
||||||
|
//! [`framing::PushFrame`]) and encode/decode logic.
|
||||||
|
//! - [`method`] — [`method::MethodRegistry`] maps `u16` method IDs to async handler
|
||||||
|
//! functions with optional per-method timeouts.
|
||||||
|
//! - [`server`] — [`server::RpcServer`] binds a QUIC endpoint, performs an auth
|
||||||
|
//! handshake on each connection, then dispatches RPC streams to registered handlers.
|
||||||
|
//! - [`client`] — [`client::RpcClient`] connects to the server with TLS, supports
|
||||||
|
//! auto-reconnect with exponential backoff, and multiplexes concurrent RPCs.
|
||||||
|
//! - [`push`] — [`push::PushBroker`] manages per-identity push connections and
|
||||||
|
//! fan-out to channel members.
|
||||||
|
//! - [`middleware`] — session validation, rate limiting, and structured audit logging.
|
||||||
|
//! - [`auth_handshake`] — initial session-token exchange on the first bi-stream.
|
||||||
|
//! - [`error`] — [`error::RpcError`] and [`error::RpcStatus`] types.
|
||||||
|
|
||||||
|
pub mod auth_handshake;
|
||||||
|
pub mod framing;
|
||||||
|
pub mod method;
|
||||||
|
pub mod server;
|
||||||
|
pub mod client;
|
||||||
|
pub mod middleware;
|
||||||
|
pub mod push;
|
||||||
|
pub mod error;
|
||||||
@@ -1,13 +1,15 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "quicproquo-sdk"
|
name = "quicprochat-sdk"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition.workspace = true
|
||||||
description = "Client SDK for quicproquo v2 — connect, auth, send, receive, subscribe"
|
description = "Client SDK for quicprochat v2 — connect, auth, send, receive, subscribe"
|
||||||
|
license = "Apache-2.0 OR MIT"
|
||||||
|
repository.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
quicproquo-core = { path = "../quicproquo-core" }
|
quicprochat-core = { path = "../quicprochat-core" }
|
||||||
quicproquo-proto = { path = "../quicproquo-proto" }
|
quicprochat-proto = { path = "../quicprochat-proto" }
|
||||||
quicproquo-rpc = { path = "../quicproquo-rpc" }
|
quicprochat-rpc = { path = "../quicprochat-rpc" }
|
||||||
tokio = { workspace = true }
|
tokio = { workspace = true }
|
||||||
futures = { workspace = true }
|
futures = { workspace = true }
|
||||||
tracing = { workspace = true }
|
tracing = { workspace = true }
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
//! OPAQUE authentication — register and login via the v2 RPC protocol.
|
//! OPAQUE authentication — register and login via the v2 RPC protocol.
|
||||||
//!
|
//!
|
||||||
//! Wraps the `opaque-ke` crate to perform the OPAQUE 3-message flow against
|
//! Wraps the `opaque-ke` crate to perform the OPAQUE 3-message flow against
|
||||||
//! the quicproquo server using prost-encoded protobuf messages over `RpcClient::call`.
|
//! the quicprochat server using prost-encoded protobuf messages over `RpcClient::call`.
|
||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use opaque_ke::{
|
use opaque_ke::{
|
||||||
@@ -9,9 +9,9 @@ use opaque_ke::{
|
|||||||
ClientRegistrationFinishParameters, CredentialResponse, RegistrationResponse,
|
ClientRegistrationFinishParameters, CredentialResponse, RegistrationResponse,
|
||||||
};
|
};
|
||||||
use prost::Message;
|
use prost::Message;
|
||||||
use quicproquo_core::{opaque_auth::OpaqueSuite, IdentityKeypair};
|
use quicprochat_core::{opaque_auth::OpaqueSuite, IdentityKeypair};
|
||||||
use quicproquo_proto::{method_ids, qpq::v1};
|
use quicprochat_proto::{method_ids, qpc::v1};
|
||||||
use quicproquo_rpc::client::RpcClient;
|
use quicprochat_rpc::client::RpcClient;
|
||||||
|
|
||||||
use crate::error::SdkError;
|
use crate::error::SdkError;
|
||||||
|
|
||||||
@@ -1,19 +1,28 @@
|
|||||||
//! `QpqClient` — the main entry point for the quicproquo SDK.
|
//! `QpqClient` — the main entry point for the quicprochat SDK.
|
||||||
|
//!
|
||||||
|
//! Provides connection lifecycle management with auto-reconnect, heartbeat
|
||||||
|
//! monitoring, push subscription recovery, and a connection state machine.
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use tokio::sync::broadcast;
|
use tokio::sync::broadcast;
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
|
pub use quicprochat_rpc::client::ConnectionState;
|
||||||
|
|
||||||
use crate::config::ClientConfig;
|
use crate::config::ClientConfig;
|
||||||
use crate::conversation::ConversationStore;
|
use crate::conversation::ConversationStore;
|
||||||
use crate::error::SdkError;
|
use crate::error::SdkError;
|
||||||
use crate::events::ClientEvent;
|
use crate::events::ClientEvent;
|
||||||
|
|
||||||
|
/// Default heartbeat interval for proactive dead-connection detection.
|
||||||
|
const HEARTBEAT_INTERVAL_SECS: u64 = 30;
|
||||||
|
|
||||||
/// The main SDK client. All state is contained within this struct — no globals.
|
/// The main SDK client. All state is contained within this struct — no globals.
|
||||||
pub struct QpqClient {
|
pub struct QpqClient {
|
||||||
config: ClientConfig,
|
config: ClientConfig,
|
||||||
rpc: Option<quicproquo_rpc::client::RpcClient>,
|
rpc: Option<Arc<quicprochat_rpc::client::RpcClient>>,
|
||||||
event_tx: broadcast::Sender<ClientEvent>,
|
event_tx: broadcast::Sender<ClientEvent>,
|
||||||
/// The authenticated username, if logged in.
|
/// The authenticated username, if logged in.
|
||||||
username: Option<String>,
|
username: Option<String>,
|
||||||
@@ -24,9 +33,9 @@ pub struct QpqClient {
|
|||||||
/// Local conversation store (SQLCipher).
|
/// Local conversation store (SQLCipher).
|
||||||
conv_store: Option<ConversationStore>,
|
conv_store: Option<ConversationStore>,
|
||||||
/// Device ID for multi-device support.
|
/// Device ID for multi-device support.
|
||||||
/// When set, fetch/peek/ack requests include this device_id so the server
|
|
||||||
/// scopes them to the correct per-device queue.
|
|
||||||
device_id: Option<Vec<u8>>,
|
device_id: Option<Vec<u8>>,
|
||||||
|
/// Handle to the heartbeat background task (if running).
|
||||||
|
heartbeat_handle: Option<tokio::task::JoinHandle<()>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl QpqClient {
|
impl QpqClient {
|
||||||
@@ -42,6 +51,7 @@ impl QpqClient {
|
|||||||
session_token: None,
|
session_token: None,
|
||||||
conv_store: None,
|
conv_store: None,
|
||||||
device_id: None,
|
device_id: None,
|
||||||
|
heartbeat_handle: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,16 +59,20 @@ impl QpqClient {
|
|||||||
pub async fn connect(&mut self) -> Result<(), SdkError> {
|
pub async fn connect(&mut self) -> Result<(), SdkError> {
|
||||||
let tls_config = build_tls_config(self.config.accept_invalid_certs)?;
|
let tls_config = build_tls_config(self.config.accept_invalid_certs)?;
|
||||||
|
|
||||||
let rpc_config = quicproquo_rpc::client::RpcClientConfig {
|
let rpc_config = quicprochat_rpc::client::RpcClientConfig {
|
||||||
server_addr: self.config.server_addr,
|
server_addr: self.config.server_addr,
|
||||||
server_name: self.config.server_name.clone(),
|
server_name: self.config.server_name.clone(),
|
||||||
tls_config: Arc::new(tls_config),
|
tls_config: Arc::new(tls_config),
|
||||||
alpn: self.config.alpn.clone(),
|
alpn: self.config.alpn.clone(),
|
||||||
session_token: self.session_token.clone(),
|
session_token: self.session_token.clone(),
|
||||||
|
max_retries: 0, // use defaults
|
||||||
|
base_delay_ms: 0,
|
||||||
|
max_backoff_ms: 0,
|
||||||
|
keepalive_secs: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
let client = quicproquo_rpc::client::RpcClient::connect(rpc_config).await?;
|
let client = quicprochat_rpc::client::RpcClient::connect(rpc_config).await?;
|
||||||
self.rpc = Some(client);
|
self.rpc = Some(Arc::new(client));
|
||||||
|
|
||||||
// Open local conversation store.
|
// Open local conversation store.
|
||||||
let store = ConversationStore::open(
|
let store = ConversationStore::open(
|
||||||
@@ -108,8 +122,8 @@ impl QpqClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get a reference to the RPC client (for direct calls).
|
/// Get a reference to the RPC client (for direct calls).
|
||||||
pub fn rpc(&self) -> Result<&quicproquo_rpc::client::RpcClient, SdkError> {
|
pub fn rpc(&self) -> Result<&quicprochat_rpc::client::RpcClient, SdkError> {
|
||||||
self.rpc.as_ref().ok_or(SdkError::NotConnected)
|
self.rpc.as_deref().ok_or(SdkError::NotConnected)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a reference to the conversation store.
|
/// Get a reference to the conversation store.
|
||||||
@@ -119,12 +133,70 @@ impl QpqClient {
|
|||||||
.ok_or(SdkError::NotConnected)
|
.ok_or(SdkError::NotConnected)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Register a new user account via OPAQUE.
|
/// Get the current connection state from the RPC layer.
|
||||||
|
pub fn connection_state(&self) -> ConnectionState {
|
||||||
|
match &self.rpc {
|
||||||
|
Some(rpc) => rpc.connection_state(),
|
||||||
|
None => ConnectionState::Disconnected,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Start a background heartbeat task that monitors the connection and
|
||||||
|
/// emits events on state changes. Checks QUIC connection liveness every
|
||||||
|
/// 30 seconds. If a dead connection is detected, emits a `Disconnected`
|
||||||
|
/// event.
|
||||||
///
|
///
|
||||||
/// Generates a fresh identity keypair, registers it with the server, and
|
/// Call this after `connect()` to enable proactive dead-connection detection.
|
||||||
/// stores the identity key locally.
|
pub fn start_heartbeat(&mut self) {
|
||||||
|
// Cancel any existing heartbeat.
|
||||||
|
if let Some(h) = self.heartbeat_handle.take() {
|
||||||
|
h.abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
let rpc = match self.rpc.clone() {
|
||||||
|
Some(rpc) => rpc,
|
||||||
|
None => return,
|
||||||
|
};
|
||||||
|
|
||||||
|
let event_tx = self.event_tx.clone();
|
||||||
|
|
||||||
|
self.heartbeat_handle = Some(tokio::spawn(async move {
|
||||||
|
let mut last_state = ConnectionState::Connected;
|
||||||
|
loop {
|
||||||
|
tokio::time::sleep(Duration::from_secs(HEARTBEAT_INTERVAL_SECS)).await;
|
||||||
|
|
||||||
|
let alive = rpc.is_alive();
|
||||||
|
let current_state = rpc.connection_state();
|
||||||
|
|
||||||
|
if current_state != last_state {
|
||||||
|
match current_state {
|
||||||
|
ConnectionState::Connected => {
|
||||||
|
let _ = event_tx.send(ClientEvent::Connected);
|
||||||
|
}
|
||||||
|
ConnectionState::Reconnecting { attempt } => {
|
||||||
|
let _ = event_tx.send(ClientEvent::Reconnecting { attempt });
|
||||||
|
}
|
||||||
|
ConnectionState::Disconnected => {
|
||||||
|
let _ = event_tx.send(ClientEvent::Disconnected {
|
||||||
|
reason: "connection lost".into(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
last_state = current_state;
|
||||||
|
} else if !alive && last_state == ConnectionState::Connected {
|
||||||
|
// Connection died but RPC layer hasn't noticed yet.
|
||||||
|
let _ = event_tx.send(ClientEvent::Disconnected {
|
||||||
|
reason: "heartbeat: connection dead".into(),
|
||||||
|
});
|
||||||
|
last_state = ConnectionState::Disconnected;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Register a new user account via OPAQUE.
|
||||||
pub async fn register(&mut self, username: &str, password: &str) -> Result<(), SdkError> {
|
pub async fn register(&mut self, username: &str, password: &str) -> Result<(), SdkError> {
|
||||||
let rpc = self.rpc.as_ref().ok_or(SdkError::NotConnected)?;
|
let rpc = self.rpc.as_deref().ok_or(SdkError::NotConnected)?;
|
||||||
let keypair = crate::auth::opaque_register(rpc, username, password, None).await?;
|
let keypair = crate::auth::opaque_register(rpc, username, password, None).await?;
|
||||||
self.identity_key = Some(keypair.public_key_bytes().to_vec());
|
self.identity_key = Some(keypair.public_key_bytes().to_vec());
|
||||||
self.emit(ClientEvent::Registered {
|
self.emit(ClientEvent::Registered {
|
||||||
@@ -135,10 +207,6 @@ impl QpqClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Log in via OPAQUE and store the session token.
|
/// Log in via OPAQUE and store the session token.
|
||||||
///
|
|
||||||
/// Requires an identity key to be set (either from a previous `register()`
|
|
||||||
/// call or loaded from state). After login, the client is authenticated
|
|
||||||
/// and subsequent RPC calls include the session token.
|
|
||||||
pub async fn login(&mut self, username: &str, password: &str) -> Result<(), SdkError> {
|
pub async fn login(&mut self, username: &str, password: &str) -> Result<(), SdkError> {
|
||||||
let identity_key = self
|
let identity_key = self
|
||||||
.identity_key
|
.identity_key
|
||||||
@@ -146,7 +214,7 @@ impl QpqClient {
|
|||||||
.ok_or_else(|| SdkError::AuthFailed("no identity key — register or load state first".into()))?
|
.ok_or_else(|| SdkError::AuthFailed("no identity key — register or load state first".into()))?
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
let rpc = self.rpc.as_ref().ok_or(SdkError::NotConnected)?;
|
let rpc = self.rpc.as_deref().ok_or(SdkError::NotConnected)?;
|
||||||
let session_token = crate::auth::opaque_login(rpc, username, password, &identity_key).await?;
|
let session_token = crate::auth::opaque_login(rpc, username, password, &identity_key).await?;
|
||||||
|
|
||||||
self.session_token = Some(session_token);
|
self.session_token = Some(session_token);
|
||||||
@@ -181,8 +249,7 @@ impl QpqClient {
|
|||||||
|
|
||||||
// ── Multi-device ─────────────────────────────────────────────────────────
|
// ── Multi-device ─────────────────────────────────────────────────────────
|
||||||
|
|
||||||
/// Set the device ID for this client. Subsequent fetch/peek/ack calls
|
/// Set the device ID for this client.
|
||||||
/// will include this ID so the server scopes them to the correct queue.
|
|
||||||
pub fn set_device_id(&mut self, device_id: Vec<u8>) {
|
pub fn set_device_id(&mut self, device_id: Vec<u8>) {
|
||||||
self.device_id = Some(device_id);
|
self.device_id = Some(device_id);
|
||||||
}
|
}
|
||||||
@@ -193,13 +260,12 @@ impl QpqClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Register this device with the server.
|
/// Register this device with the server.
|
||||||
/// Sets the local device_id on success.
|
|
||||||
pub async fn register_device(
|
pub async fn register_device(
|
||||||
&mut self,
|
&mut self,
|
||||||
device_id: &[u8],
|
device_id: &[u8],
|
||||||
device_name: &str,
|
device_name: &str,
|
||||||
) -> Result<bool, SdkError> {
|
) -> Result<bool, SdkError> {
|
||||||
let rpc = self.rpc.as_ref().ok_or(SdkError::NotConnected)?;
|
let rpc = self.rpc.as_deref().ok_or(SdkError::NotConnected)?;
|
||||||
let newly_registered =
|
let newly_registered =
|
||||||
crate::devices::register_device(rpc, device_id, device_name).await?;
|
crate::devices::register_device(rpc, device_id, device_name).await?;
|
||||||
self.device_id = Some(device_id.to_vec());
|
self.device_id = Some(device_id.to_vec());
|
||||||
@@ -208,13 +274,13 @@ impl QpqClient {
|
|||||||
|
|
||||||
/// List all registered devices for this identity.
|
/// List all registered devices for this identity.
|
||||||
pub async fn list_devices(&self) -> Result<Vec<crate::devices::DeviceInfo>, SdkError> {
|
pub async fn list_devices(&self) -> Result<Vec<crate::devices::DeviceInfo>, SdkError> {
|
||||||
let rpc = self.rpc.as_ref().ok_or(SdkError::NotConnected)?;
|
let rpc = self.rpc.as_deref().ok_or(SdkError::NotConnected)?;
|
||||||
crate::devices::list_devices(rpc).await
|
crate::devices::list_devices(rpc).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Revoke (remove) a registered device.
|
/// Revoke (remove) a registered device.
|
||||||
pub async fn revoke_device(&self, device_id: &[u8]) -> Result<bool, SdkError> {
|
pub async fn revoke_device(&self, device_id: &[u8]) -> Result<bool, SdkError> {
|
||||||
let rpc = self.rpc.as_ref().ok_or(SdkError::NotConnected)?;
|
let rpc = self.rpc.as_deref().ok_or(SdkError::NotConnected)?;
|
||||||
crate::devices::revoke_device(rpc, device_id).await
|
crate::devices::revoke_device(rpc, device_id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,8 +324,15 @@ impl QpqClient {
|
|||||||
.map_err(|e| SdkError::Storage(e.to_string()))
|
.map_err(|e| SdkError::Storage(e.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Disconnect from the server.
|
/// Disconnect from the server gracefully.
|
||||||
|
///
|
||||||
|
/// Stops the heartbeat task and closes the QUIC connection. Emits a
|
||||||
|
/// `Disconnected` event.
|
||||||
pub fn disconnect(&mut self) {
|
pub fn disconnect(&mut self) {
|
||||||
|
// Stop heartbeat first.
|
||||||
|
if let Some(h) = self.heartbeat_handle.take() {
|
||||||
|
h.abort();
|
||||||
|
}
|
||||||
if let Some(rpc) = self.rpc.take() {
|
if let Some(rpc) = self.rpc.take() {
|
||||||
rpc.close();
|
rpc.close();
|
||||||
self.emit(ClientEvent::Disconnected {
|
self.emit(ClientEvent::Disconnected {
|
||||||
@@ -41,7 +41,7 @@ impl Default for ClientConfig {
|
|||||||
db_password: None,
|
db_password: None,
|
||||||
state_path: PathBuf::from("client-state.bin"),
|
state_path: PathBuf::from("client-state.bin"),
|
||||||
accept_invalid_certs: false,
|
accept_invalid_certs: false,
|
||||||
alpn: b"qpq/2".to_vec(),
|
alpn: b"qpc/2".to_vec(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1038,4 +1038,83 @@ mod tests {
|
|||||||
// Returns 0 for unknown conversations.
|
// Returns 0 for unknown conversations.
|
||||||
assert_eq!(store.get_last_seen_seq(&missing).unwrap(), 0);
|
assert_eq!(store.get_last_seen_seq(&missing).unwrap(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn upsert_conversation_updates_fields() {
|
||||||
|
let (_dir, store) = open_test_store();
|
||||||
|
let mut conv = make_group_conv("updatable", 1000);
|
||||||
|
store.save_conversation(&conv).unwrap();
|
||||||
|
|
||||||
|
// Update display name and activity
|
||||||
|
conv.display_name = "#updated".to_string();
|
||||||
|
conv.last_activity_ms = 9000;
|
||||||
|
conv.unread_count = 5;
|
||||||
|
conv.is_hybrid = true;
|
||||||
|
store.save_conversation(&conv).unwrap();
|
||||||
|
|
||||||
|
let loaded = store.load_conversation(&conv.id).unwrap().unwrap();
|
||||||
|
assert_eq!(loaded.display_name, "#updated");
|
||||||
|
assert_eq!(loaded.last_activity_ms, 9000);
|
||||||
|
assert_eq!(loaded.unread_count, 5);
|
||||||
|
assert!(loaded.is_hybrid);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn load_missing_conversation_returns_none() {
|
||||||
|
let (_dir, store) = open_test_store();
|
||||||
|
let missing = ConversationId([0xFFu8; 16]);
|
||||||
|
assert!(store.load_conversation(&missing).unwrap().is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn conversation_id_hex_encoding() {
|
||||||
|
let id = ConversationId([0xAB; 16]);
|
||||||
|
assert_eq!(id.hex(), "abababababababababababababababab");
|
||||||
|
assert_eq!(id.hex().len(), 32);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn save_message_with_message_id_and_ref() {
|
||||||
|
let (_dir, store) = open_test_store();
|
||||||
|
let conv = make_group_conv("msg-ids", 1000);
|
||||||
|
store.save_conversation(&conv).unwrap();
|
||||||
|
|
||||||
|
let msg_id = [42u8; 16];
|
||||||
|
let ref_id = [99u8; 16];
|
||||||
|
store.save_message(&StoredMessage {
|
||||||
|
conversation_id: conv.id.clone(),
|
||||||
|
message_id: Some(msg_id),
|
||||||
|
sender_key: vec![1, 2, 3],
|
||||||
|
sender_name: Some("alice".to_string()),
|
||||||
|
body: "reply".to_string(),
|
||||||
|
msg_type: "chat".to_string(),
|
||||||
|
ref_msg_id: Some(ref_id),
|
||||||
|
timestamp_ms: 5000,
|
||||||
|
is_outgoing: true,
|
||||||
|
}).unwrap();
|
||||||
|
|
||||||
|
let msgs = store.load_recent_messages(&conv.id, 10).unwrap();
|
||||||
|
assert_eq!(msgs.len(), 1);
|
||||||
|
assert_eq!(msgs[0].message_id, Some(msg_id));
|
||||||
|
assert_eq!(msgs[0].ref_msg_id, Some(ref_id));
|
||||||
|
assert!(msgs[0].is_outgoing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn member_keys_serialization_roundtrip() {
|
||||||
|
let (_dir, store) = open_test_store();
|
||||||
|
let mut conv = make_group_conv("member-keys", 1000);
|
||||||
|
conv.member_keys = vec![
|
||||||
|
vec![1u8; 32],
|
||||||
|
vec![2u8; 32],
|
||||||
|
vec![3u8; 32],
|
||||||
|
];
|
||||||
|
store.save_conversation(&conv).unwrap();
|
||||||
|
|
||||||
|
let loaded = store.load_conversation(&conv.id).unwrap().unwrap();
|
||||||
|
assert_eq!(loaded.member_keys.len(), 3);
|
||||||
|
assert_eq!(loaded.member_keys[0], vec![1u8; 32]);
|
||||||
|
assert_eq!(loaded.member_keys[1], vec![2u8; 32]);
|
||||||
|
assert_eq!(loaded.member_keys[2], vec![3u8; 32]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
//! Device management — register, list, and revoke devices.
|
//! Device management — register, list, and revoke devices.
|
||||||
|
|
||||||
use quicproquo_proto::bytes::Bytes;
|
use quicprochat_proto::bytes::Bytes;
|
||||||
use quicproquo_proto::prost::Message;
|
use quicprochat_proto::prost::Message;
|
||||||
use quicproquo_proto::{method_ids, qpq::v1};
|
use quicprochat_proto::{method_ids, qpc::v1};
|
||||||
use quicproquo_rpc::client::RpcClient;
|
use quicprochat_rpc::client::RpcClient;
|
||||||
|
|
||||||
use crate::error::SdkError;
|
use crate::error::SdkError;
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ pub enum SdkError {
|
|||||||
Crypto(String),
|
Crypto(String),
|
||||||
|
|
||||||
#[error("RPC error: {0}")]
|
#[error("RPC error: {0}")]
|
||||||
Rpc(#[from] quicproquo_rpc::error::RpcError),
|
Rpc(#[from] quicprochat_rpc::error::RpcError),
|
||||||
|
|
||||||
#[error("storage error: {0}")]
|
#[error("storage error: {0}")]
|
||||||
Storage(String),
|
Storage(String),
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user