Merge phase4/identity-store: voelin-identity key store on SQLite (Phase 4 step 2)
CI / Linux checks (push) Failing after 40s
CI / Linux checks (push) Failing after 40s
voelin-identity from VoelinProtocol as a git dependency pinned by rev; the identity migrations as schema versions 6 and 7 (kind column, account binding columns); voelin_identity::KeyStore on the identities table with bindings and the account sign-out rules; notices regenerated; the sibling checkout recipe in docs/building.md. Opus gate accepted with three minors (damaged binding columns block sign-out, secure_delete off, one commit red on the notices job) left as follow-ups. Building now needs read access to the private VoelinProtocol repository (docs/building.md, docs/ci.md). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
commit
7c6d149f78
15 files changed
+2029
-15
No files matched your search
@@ -2,6 +2,10 @@
|
||||
# the sources only. Builds keep target/ in cache mounts, never in the context.
|
||||
.git
|
||||
.claude
|
||||
# The per-developer .cargo/config.toml (docs/building.md, a [patch] to a sibling
|
||||
# VoelinProtocol checkout): never part of a build. Only the root one; the
|
||||
# committed third_party/dimpl/.cargo stays.
|
||||
.cargo
|
||||
target
|
||||
dist
|
||||
fuzz/target
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/target/
|
||||
/dev/.state/
|
||||
/dist/
|
||||
/.cargo/
|
||||
@@ -69,6 +69,14 @@ User-visible changes of the apps and the `tsgw` gateway. The format follows
|
||||
|
||||
### Changed
|
||||
|
||||
- The identity store keeps identities of more than one kind (TeamSpeak, a Voelin
|
||||
key, the signed-in account) with the account each belongs to, as a
|
||||
`voelin-identity` key store, in two database migrations. Existing
|
||||
databases migrate on first start and every identity stays what it was (kind
|
||||
TeamSpeak, no account, same key, name, origin and default); nothing changes
|
||||
on screen yet. The build now fetches `voelin-identity` from the private
|
||||
VoelinProtocol repository, so a fresh checkout needs read access to it
|
||||
(see docs/building.md).
|
||||
- Selecting a server observes it through its gateway at once; the Observe
|
||||
button is gone. The server dialog asks only for the address, password,
|
||||
name and nickname: the gateway is found from the address.
|
||||
|
||||
Generated
+55
-2
@@ -1996,7 +1996,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb"
|
||||
dependencies = [
|
||||
"const-oid 0.9.6",
|
||||
"der_derive",
|
||||
"der_derive 0.7.3",
|
||||
"flagset",
|
||||
"pem-rfc7468 0.7.0",
|
||||
"zeroize",
|
||||
@@ -2009,6 +2009,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a878c850e9e421b20262e9b41f9c860e4785fa07541c266b62ff9d1ef998a80a"
|
||||
dependencies = [
|
||||
"const-oid 0.10.2",
|
||||
"der_derive 0.8.0",
|
||||
"flagset",
|
||||
"pem-rfc7468 1.0.0",
|
||||
"zeroize",
|
||||
]
|
||||
@@ -2038,6 +2040,17 @@ dependencies = [
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "der_derive"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "59600e2c2d636fde9b65e99cc6445ac770c63d3628195ff39932b8d6d7409903"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "deranged"
|
||||
version = "0.5.8"
|
||||
@@ -2134,7 +2147,7 @@ dependencies = [
|
||||
"spki 0.7.3",
|
||||
"subtle",
|
||||
"time",
|
||||
"x509-cert",
|
||||
"x509-cert 0.2.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -9560,6 +9573,23 @@ dependencies = [
|
||||
"voelin-model",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "voelin-identity"
|
||||
version = "0.2.0"
|
||||
source = "git+ssh://gitea@git.faumaray.com/Voelin/VoelinProtocol.git?rev=64808ccbb1e3aa10213392724f2f436bc25fd36f#64808ccbb1e3aa10213392724f2f436bc25fd36f"
|
||||
dependencies = [
|
||||
"aws-lc-rs",
|
||||
"base64 0.23.1",
|
||||
"prost",
|
||||
"rcgen",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror 2.0.21",
|
||||
"voelin-proto",
|
||||
"x509-cert 0.3.0",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "voelin-media"
|
||||
version = "0.1.0"
|
||||
@@ -9639,6 +9669,17 @@ dependencies = [
|
||||
"zbus",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "voelin-proto"
|
||||
version = "0.2.0"
|
||||
source = "git+ssh://gitea@git.faumaray.com/Voelin/VoelinProtocol.git?rev=64808ccbb1e3aa10213392724f2f436bc25fd36f#64808ccbb1e3aa10213392724f2f436bc25fd36f"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"prost",
|
||||
"thiserror 2.0.21",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "voelin-query"
|
||||
version = "0.1.0"
|
||||
@@ -9663,6 +9704,7 @@ dependencies = [
|
||||
"serde_json",
|
||||
"thiserror 2.0.21",
|
||||
"tsclientlib",
|
||||
"voelin-identity",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -10850,6 +10892,17 @@ dependencies = [
|
||||
"spki 0.7.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "x509-cert"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "105ef4642d9cb137ef83d623d0e4bf08b8adf69e9918ca904a174adb6d3d038b"
|
||||
dependencies = [
|
||||
"const-oid 0.10.2",
|
||||
"der 0.8.2",
|
||||
"spki 0.8.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "x509-parser"
|
||||
version = "0.18.1"
|
||||
|
||||
@@ -53,6 +53,14 @@ license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/Faumaray/Voelin"
|
||||
publish = false
|
||||
|
||||
[workspace.dependencies]
|
||||
# The protocol repository is private (VoelinProtocol). This is the SSH URL its
|
||||
# docs/development.md names, so that a per-developer .cargo/config.toml [patch]
|
||||
# can point it at a sibling checkout (docs/building.md, "Working with a sibling
|
||||
# VoelinProtocol checkout"). Pinned by commit until the protocol tags a release
|
||||
# that has the account-bound KeyStore (its Phase 2 task 28).
|
||||
voelin-identity = { git = "ssh://gitea@git.faumaray.com/Voelin/VoelinProtocol.git", rev = "64808ccbb1e3aa10213392724f2f436bc25fd36f" }
|
||||
|
||||
[workspace.lints.rust]
|
||||
# deny, not forbid: generated code (Slint) needs a local allow.
|
||||
unsafe_code = "deny"
|
||||
|
||||
@@ -175,7 +175,7 @@ the crate's authors are listed as its copyright holders.
|
||||
|
||||
| License | Crates |
|
||||
|---|---|
|
||||
| MIT License | 658 |
|
||||
| MIT License | 660 |
|
||||
| Apache License 2.0 | 31 |
|
||||
| Unicode License v3 | 26 |
|
||||
| BSD 3-Clause "New" or "Revised" License | 22 |
|
||||
@@ -6994,7 +6994,7 @@ DEALINGS IN THE SOFTWARE.
|
||||
|
||||
````
|
||||
|
||||
Used by: cpufeatures 0.2.17
|
||||
Used by: cpufeatures 0.2.17, der_derive 0.8.0
|
||||
|
||||
````text
|
||||
Copyright (c) 2020-2025 The RustCrypto Project Developers
|
||||
@@ -7246,7 +7246,7 @@ DEALINGS IN THE SOFTWARE.
|
||||
|
||||
````
|
||||
|
||||
Used by: pem-rfc7468 1.0.0, pkcs1 0.8.0-rc.4
|
||||
Used by: pem-rfc7468 1.0.0, pkcs1 0.8.0-rc.4, x509-cert 0.3.0
|
||||
|
||||
````text
|
||||
Copyright (c) 2021-2025 The RustCrypto Project Developers
|
||||
|
||||
@@ -20,6 +20,7 @@ serde = { version = "1.0.229", features = ["derive"] }
|
||||
serde_json = "1.0.151"
|
||||
thiserror = "2.0.21"
|
||||
tsclientlib = { path = "../proto/tsclientlib" }
|
||||
voelin-identity = { workspace = true }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
@@ -0,0 +1,292 @@
|
||||
//! The `identities` table as a [`voelin_identity::KeyStore`].
|
||||
//!
|
||||
//! The table holds identities of more than one kind: the TeamSpeak identities
|
||||
//! the client has always had (`kind` `teamspeak`, `data` the JSON of a
|
||||
//! `tsproto::Identity`), a Voelin key (`voelin`), the record of the account the
|
||||
//! installation is signed in to (`account`) and whatever kind a later version
|
||||
//! adds, which passes through untouched. A row is addressed by its
|
||||
//! `(kind, uid)`, and `uid` stays `UNIQUE` across kinds: the uid forms of the
|
||||
//! kinds do not overlap (a TeamSpeak uid is base64, a Voelin uid 52 characters
|
||||
//! of `a-z2-7`, an account uid is written `account:<uid>`).
|
||||
//!
|
||||
//! Besides the blob a row carries the columns of the TeamSpeak-only world,
|
||||
//! which a [`KeyStore`] does not see and keeps when it replaces a row: `name`,
|
||||
//! `origin`, `is_default` and `created`. A blob of a new `(kind, uid)` becomes a
|
||||
//! row named after its uid, of origin `user` and not the default.
|
||||
//!
|
||||
//! The TeamSpeak security level is not stored: it is computed from the key and
|
||||
//! counter in `data`, as [`Store::identities`] always did, and the level of a
|
||||
//! blob a caller puts is ignored. A TeamSpeak row whose JSON cannot be read
|
||||
//! (it could only have been damaged outside this crate) lists and reads with
|
||||
//! level 0 instead of failing the whole list, and a [`KeyStore::put`] that only
|
||||
//! changes the binding of a row (the row of that `(kind, uid)` already holds
|
||||
//! exactly that `data`) writes the four binding columns and does not look at
|
||||
//! `data` again. That is how [`KeyStore::sign_out`] unbinds a device-only
|
||||
//! secret, so a damaged row never blocks it.
|
||||
//!
|
||||
//! A TeamSpeak blob that is refused says why in words that carry none of its
|
||||
//! input: its `data` is the identity's private key, and an error reaches log
|
||||
//! lines.
|
||||
|
||||
use std::path::Path;
|
||||
use std::sync::{Mutex, MutexGuard, PoisonError};
|
||||
|
||||
use rusqlite::params;
|
||||
use tsclientlib::Identity;
|
||||
use voelin_identity::migrate::SELECT_ACCOUNT_COLUMNS;
|
||||
use voelin_identity::{
|
||||
AccountBinding, BlobError, IdentityBlob, IdentityInfo, KIND_TEAMSPEAK, KeyStore, KeyStoreError,
|
||||
};
|
||||
|
||||
use crate::{Error, Result, Store};
|
||||
|
||||
/// A result of the key store seam.
|
||||
type KsResult<T> = std::result::Result<T, KeyStoreError>;
|
||||
|
||||
/// The rows of [`KeyStore::list`]. The secret of a kind this crate does not
|
||||
/// interpret is never read; a TeamSpeak row's `data` is, for its level.
|
||||
const LIST: &str = "SELECT kind, uid, CASE WHEN kind = 'teamspeak' THEN data END,
|
||||
account, integration, integration_rev, synced
|
||||
FROM identities ORDER BY kind, uid";
|
||||
|
||||
/// Replace the binding of the row of this `(kind, uid)` if its `data` is
|
||||
/// exactly the blob's: nothing else of the row is written.
|
||||
const REBIND: &str = "UPDATE identities
|
||||
SET account = ?4, integration = ?5, integration_rev = ?6, synced = ?7
|
||||
WHERE kind = ?1 AND uid = ?2 AND data = ?3";
|
||||
|
||||
/// Insert the blob, or replace the row of the same uid if it is of the same
|
||||
/// kind. A row of another kind is left alone: the statement then changes
|
||||
/// nothing, which `put` reports.
|
||||
const PUT: &str = "INSERT INTO identities
|
||||
(name, uid, data, kind, account, integration, integration_rev, synced)
|
||||
VALUES (?1, ?1, ?2, ?3, ?4, ?5, ?6, ?7)
|
||||
ON CONFLICT (uid) DO UPDATE SET
|
||||
data = excluded.data, account = excluded.account,
|
||||
integration = excluded.integration, integration_rev = excluded.integration_rev,
|
||||
synced = excluded.synced
|
||||
WHERE identities.kind = excluded.kind";
|
||||
|
||||
/// The identities of a client database as a [`KeyStore`]: every kind, with its
|
||||
/// account binding.
|
||||
///
|
||||
/// It owns a [`Store`] behind a mutex, because a [`KeyStore`] is `Sync` and a
|
||||
/// SQLite connection is not. Open it on the database file next to the
|
||||
/// other connections of the app (the settings writer and the chat history do
|
||||
/// the same): SQLite lets them share the file. [`Self::with_store`] gives
|
||||
/// access to the TeamSpeak methods of the same connection.
|
||||
///
|
||||
/// [`KeyStore::sign_out`] and the rest of the trait's provided methods work as
|
||||
/// `voelin-identity` defines them, on top of the five methods here.
|
||||
pub struct SqliteKeyStore {
|
||||
store: Mutex<Store>,
|
||||
}
|
||||
|
||||
impl SqliteKeyStore {
|
||||
/// The identities of an open [`Store`].
|
||||
pub fn new(store: Store) -> Self {
|
||||
Self { store: Mutex::new(store) }
|
||||
}
|
||||
|
||||
/// Open or create the database at `path`, migrating it.
|
||||
pub fn open(path: &Path) -> Result<Self> {
|
||||
Ok(Self::new(Store::open(path)?))
|
||||
}
|
||||
|
||||
/// A key store in memory: for tests.
|
||||
pub fn open_in_memory() -> Result<Self> {
|
||||
Ok(Self::new(Store::open_in_memory()?))
|
||||
}
|
||||
|
||||
/// Run `f` on the [`Store`] behind this key store, holding its lock: the
|
||||
/// TeamSpeak identity methods (`identities`, `default_identity`, ...) see
|
||||
/// the same rows on the same connection.
|
||||
pub fn with_store<R>(&self, f: impl FnOnce(&Store) -> R) -> R {
|
||||
f(&self.lock())
|
||||
}
|
||||
|
||||
fn lock(&self) -> MutexGuard<'_, Store> {
|
||||
// A panic in another thread cannot leave the table half-updated: every
|
||||
// write here is one statement, and `put` tries a second one only when
|
||||
// the first changed nothing.
|
||||
self.store.lock().unwrap_or_else(PoisonError::into_inner)
|
||||
}
|
||||
}
|
||||
|
||||
impl KeyStore for SqliteKeyStore {
|
||||
fn list(&self) -> KsResult<Vec<IdentityInfo>> {
|
||||
let store = self.lock();
|
||||
let mut statement = store.db.prepare_cached(LIST).map_err(backend)?;
|
||||
let rows = statement.query_map([], Columns::read).map_err(backend)?;
|
||||
rows.map(|row| row.map_err(backend)?.into_info()).collect()
|
||||
}
|
||||
|
||||
fn get(&self, kind: &str, uid: &str) -> KsResult<Option<IdentityBlob>> {
|
||||
let store = self.lock();
|
||||
let sql =
|
||||
format!("SELECT {SELECT_ACCOUNT_COLUMNS} FROM identities WHERE kind = ?1 AND uid = ?2");
|
||||
let mut statement = store.db.prepare_cached(&sql).map_err(backend)?;
|
||||
let mut rows = statement.query_map(params![kind, uid], Columns::read).map_err(backend)?;
|
||||
rows.next().transpose().map_err(backend)?.map(Columns::into_blob).transpose()
|
||||
}
|
||||
|
||||
fn put(&self, blob: &IdentityBlob) -> KsResult<()> {
|
||||
let columns = blob.binding_columns()?;
|
||||
let store = self.lock();
|
||||
// A row that already holds this data changes its binding and nothing
|
||||
// else, and is not checked again: it may have been damaged outside this
|
||||
// crate, and a sign-out still has to unbind it.
|
||||
let rebound = store
|
||||
.db
|
||||
.prepare_cached(REBIND)
|
||||
.map_err(backend)?
|
||||
.execute(params![
|
||||
blob.kind,
|
||||
blob.uid,
|
||||
blob.json,
|
||||
columns.account,
|
||||
columns.integration,
|
||||
columns.rev,
|
||||
columns.synced,
|
||||
])
|
||||
.map_err(backend)?;
|
||||
if rebound > 0 {
|
||||
return Ok(());
|
||||
}
|
||||
if blob.kind == KIND_TEAMSPEAK {
|
||||
check_teamspeak(blob)?;
|
||||
}
|
||||
let changed = store
|
||||
.db
|
||||
.prepare_cached(PUT)
|
||||
.map_err(backend)?
|
||||
.execute(params![
|
||||
blob.uid,
|
||||
blob.json,
|
||||
blob.kind,
|
||||
columns.account,
|
||||
columns.integration,
|
||||
columns.rev,
|
||||
columns.synced,
|
||||
])
|
||||
.map_err(backend)?;
|
||||
if changed == 0 {
|
||||
let held_by: String = store
|
||||
.db
|
||||
.query_row("SELECT kind FROM identities WHERE uid = ?1", [&blob.uid], |r| r.get(0))
|
||||
.map_err(backend)?;
|
||||
return Err(KeyStoreError::backend(Refused::UidHeld {
|
||||
uid: blob.uid.clone(),
|
||||
kind: held_by,
|
||||
}));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn remove(&self, kind: &str, uid: &str) -> KsResult<bool> {
|
||||
let store = self.lock();
|
||||
let removed = store
|
||||
.db
|
||||
.prepare_cached("DELETE FROM identities WHERE kind = ?1 AND uid = ?2")
|
||||
.map_err(backend)?
|
||||
.execute(params![kind, uid])
|
||||
.map_err(backend)?;
|
||||
Ok(removed > 0)
|
||||
}
|
||||
}
|
||||
|
||||
/// A TeamSpeak blob is stored only if it is what its kind says: the JSON of a
|
||||
/// `tsproto::Identity` whose key has the uid the blob names.
|
||||
///
|
||||
/// The first keeps one bad row, which a service or a damaged file could hand
|
||||
/// over, from failing the list of TeamSpeak identities for everyone. The
|
||||
/// second keeps a blob from overwriting, by its uid, the key of a different
|
||||
/// identity that is stored under that uid.
|
||||
///
|
||||
/// The parse error of serde is dropped, not forwarded: it can quote the text
|
||||
/// it choked on, which is a private key, into a log line.
|
||||
fn check_teamspeak(blob: &IdentityBlob) -> KsResult<()> {
|
||||
let Ok(identity) = serde_json::from_str::<Identity>(&blob.json) else {
|
||||
return Err(KeyStoreError::backend(Refused::NotATeamSpeakIdentity));
|
||||
};
|
||||
if identity.key().to_pub().get_uid() != blob.uid {
|
||||
return Err(KeyStoreError::Blob(BlobError::UidMismatch));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A database error as the store's backend error.
|
||||
fn backend(error: impl Into<Error>) -> KeyStoreError {
|
||||
KeyStoreError::backend(error.into())
|
||||
}
|
||||
|
||||
/// A [`KeyStore::put`] this store refuses.
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
enum Refused {
|
||||
/// The JSON is not that of a `tsproto::Identity`. The text is a private
|
||||
/// key, so the error does not repeat it, nor serde's account of it.
|
||||
#[error("the TeamSpeak identity JSON is not that of an identity")]
|
||||
NotATeamSpeakIdentity,
|
||||
/// `uid` is unique across kinds in this table.
|
||||
#[error("the uid {uid:?} is already stored as an identity of kind {kind:?}")]
|
||||
UidHeld { uid: String, kind: String },
|
||||
}
|
||||
|
||||
/// One row of the table as `LIST` and `SELECT_ACCOUNT_COLUMNS` select it.
|
||||
struct Columns {
|
||||
kind: String,
|
||||
uid: String,
|
||||
/// The identity itself. `LIST` leaves it out for kinds with no level.
|
||||
data: Option<String>,
|
||||
account: Option<String>,
|
||||
integration: Option<String>,
|
||||
rev: i64,
|
||||
synced: i64,
|
||||
}
|
||||
|
||||
impl Columns {
|
||||
fn read(row: &rusqlite::Row<'_>) -> rusqlite::Result<Self> {
|
||||
Ok(Self {
|
||||
kind: row.get(0)?,
|
||||
uid: row.get(1)?,
|
||||
data: row.get(2)?,
|
||||
account: row.get(3)?,
|
||||
integration: row.get(4)?,
|
||||
rev: row.get(5)?,
|
||||
synced: row.get(6)?,
|
||||
})
|
||||
}
|
||||
|
||||
fn binding(&self) -> KsResult<Option<AccountBinding>> {
|
||||
Ok(AccountBinding::from_columns(
|
||||
self.account.as_deref(),
|
||||
self.integration.as_deref(),
|
||||
self.rev,
|
||||
self.synced,
|
||||
)?)
|
||||
}
|
||||
|
||||
/// The security level of a TeamSpeak row, 0 for any other kind and for JSON
|
||||
/// that is no identity.
|
||||
fn level(&self) -> u8 {
|
||||
match &self.data {
|
||||
Some(json) if self.kind == KIND_TEAMSPEAK => {
|
||||
serde_json::from_str::<Identity>(json).map_or(0, |identity| identity.level())
|
||||
}
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn into_info(self) -> KsResult<IdentityInfo> {
|
||||
let binding = self.binding()?;
|
||||
let level = self.level();
|
||||
Ok(IdentityInfo { kind: self.kind, uid: self.uid, level, binding })
|
||||
}
|
||||
|
||||
fn into_blob(self) -> KsResult<IdentityBlob> {
|
||||
let binding = self.binding()?;
|
||||
let level = self.level();
|
||||
let data = self.data.unwrap_or_default();
|
||||
Ok(IdentityBlob::from_row(&self.kind, self.uid, level, data).with_binding(binding))
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,16 @@
|
||||
//!
|
||||
//! The schema is versioned (`PRAGMA user_version`): opening a database runs
|
||||
//! the migrations it has not seen, each in one transaction, keeping the data.
|
||||
//!
|
||||
//! The `identities` table keeps identities of more than one kind. [`Store`]
|
||||
//! has the TeamSpeak identities the client has always had; [`SqliteKeyStore`]
|
||||
//! is the table as a `voelin_identity::KeyStore`: every kind (TeamSpeak, a
|
||||
//! Voelin key, the record of the signed-in account), each with the binding that
|
||||
//! says whether it belongs to an account, and the sign-out of that account.
|
||||
|
||||
pub mod chat;
|
||||
pub mod contacts;
|
||||
mod keystore;
|
||||
mod secrets;
|
||||
mod store;
|
||||
|
||||
@@ -18,6 +25,7 @@ pub use chat::{
|
||||
StoredMessage, SyncState, WriteOutcome, Written,
|
||||
};
|
||||
pub use contacts::{Contact, ContactSeen, Relation};
|
||||
pub use keystore::SqliteKeyStore;
|
||||
#[cfg(feature = "keyring")]
|
||||
pub use secrets::KeyringSecrets;
|
||||
pub use secrets::{MemorySecrets, Secrets};
|
||||
|
||||
@@ -18,12 +18,21 @@ enum Migration {
|
||||
/// Schema migrations; entry `i` upgrades from version `i` to `i + 1`
|
||||
/// (`PRAGMA user_version`). Add new ones at the end; never change one that
|
||||
/// shipped.
|
||||
///
|
||||
/// Versions 6 and 7 are the identity migrations of `voelin-identity` (the
|
||||
/// protocol's Phase 2 tasks 7 and 28), run in this order: a `kind` column
|
||||
/// (every row that exists is a `teamspeak` identity) and then the four
|
||||
/// account-binding columns (every row that exists is unbound). Their SQL is
|
||||
/// the protocol's; `the_identity_migrations_are_pinned` keeps it from changing
|
||||
/// under a shipped version.
|
||||
const MIGRATIONS: &[Migration] = &[
|
||||
Migration::Sql(SCHEMA_1),
|
||||
Migration::Code(crate::chat::migrate_2),
|
||||
Migration::Sql(crate::contacts::SCHEMA_3),
|
||||
Migration::Sql(SCHEMA_4),
|
||||
Migration::Sql(crate::chat::SCHEMA_5),
|
||||
Migration::Sql(voelin_identity::migrate::ADD_KIND_COLUMN),
|
||||
Migration::Sql(voelin_identity::migrate::ADD_ACCOUNT_COLUMNS),
|
||||
];
|
||||
|
||||
/// Version 4: where each identity came from ([`IdentityOrigin`]) and which
|
||||
@@ -287,6 +296,10 @@ impl Store {
|
||||
pub const SCHEMA_VERSION: i64 = MIGRATIONS.len() as i64;
|
||||
|
||||
// Identities
|
||||
//
|
||||
// These methods are the TeamSpeak identities (kind `teamspeak`) the client
|
||||
// has always had, and act on those rows only: the other kinds of the
|
||||
// `identities` table (a Voelin key, the signed-in account) are not theirs.
|
||||
|
||||
/// Store an identity; it is the default when no other one is.
|
||||
pub fn add_identity(
|
||||
@@ -306,7 +319,8 @@ impl Store {
|
||||
|
||||
pub fn identities(&self) -> Result<Vec<IdentityEntry>> {
|
||||
let mut stmt = self.db.prepare(
|
||||
"SELECT id, name, uid, data, origin, is_default FROM identities ORDER BY id",
|
||||
"SELECT id, name, uid, data, origin, is_default FROM identities
|
||||
WHERE kind = 'teamspeak' ORDER BY id",
|
||||
)?;
|
||||
let rows = stmt.query_map([], |r| {
|
||||
Ok((
|
||||
@@ -339,7 +353,11 @@ impl Store {
|
||||
/// and is never replaced by an import again.
|
||||
pub fn set_default_identity(&self, id: i64, by_user: bool) -> Result<()> {
|
||||
let tx = self.db.unchecked_transaction()?;
|
||||
if tx.execute("UPDATE identities SET is_default = 1 WHERE id = ?1", [id])? == 0 {
|
||||
if tx.execute(
|
||||
"UPDATE identities SET is_default = 1 WHERE id = ?1 AND kind = 'teamspeak'",
|
||||
[id],
|
||||
)? == 0
|
||||
{
|
||||
return Err(Error::NotFound("identity", id));
|
||||
}
|
||||
tx.execute("UPDATE identities SET is_default = 0 WHERE id <> ?1", [id])?;
|
||||
@@ -356,7 +374,11 @@ impl Store {
|
||||
pub fn identity(&self, id: i64) -> Result<Identity> {
|
||||
let data: Option<String> = self
|
||||
.db
|
||||
.query_row("SELECT data FROM identities WHERE id = ?1", [id], |r| r.get(0))
|
||||
.query_row(
|
||||
"SELECT data FROM identities WHERE id = ?1 AND kind = 'teamspeak'",
|
||||
[id],
|
||||
|r| r.get(0),
|
||||
)
|
||||
.optional()?;
|
||||
let data = data.ok_or(Error::NotFound("identity", id))?;
|
||||
Ok(serde_json::from_str(&data)?)
|
||||
@@ -365,20 +387,22 @@ impl Store {
|
||||
/// Store an identity again, e.g. after its security level was improved.
|
||||
pub fn update_identity(&self, id: i64, identity: &Identity) -> Result<()> {
|
||||
let n = self.db.execute(
|
||||
"UPDATE identities SET data = ?2 WHERE id = ?1",
|
||||
"UPDATE identities SET data = ?2 WHERE id = ?1 AND kind = 'teamspeak'",
|
||||
params![id, serde_json::to_string(identity)?],
|
||||
)?;
|
||||
if n == 0 { Err(Error::NotFound("identity", id)) } else { Ok(()) }
|
||||
}
|
||||
|
||||
pub fn rename_identity(&self, id: i64, name: &str) -> Result<()> {
|
||||
let n =
|
||||
self.db.execute("UPDATE identities SET name = ?2 WHERE id = ?1", params![id, name])?;
|
||||
let n = self.db.execute(
|
||||
"UPDATE identities SET name = ?2 WHERE id = ?1 AND kind = 'teamspeak'",
|
||||
params![id, name],
|
||||
)?;
|
||||
if n == 0 { Err(Error::NotFound("identity", id)) } else { Ok(()) }
|
||||
}
|
||||
|
||||
pub fn delete_identity(&self, id: i64) -> Result<()> {
|
||||
self.db.execute("DELETE FROM identities WHERE id = ?1", [id])?;
|
||||
self.db.execute("DELETE FROM identities WHERE id = ?1 AND kind = 'teamspeak'", [id])?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -595,7 +619,7 @@ mod tests {
|
||||
.unwrap();
|
||||
}
|
||||
let store = Store::open(&path).unwrap();
|
||||
assert_eq!(Store::SCHEMA_VERSION, 5);
|
||||
assert_eq!(Store::SCHEMA_VERSION, 7);
|
||||
assert_eq!(store.schema_version().unwrap(), Store::SCHEMA_VERSION);
|
||||
let channel = ChatTarget::Channel(1);
|
||||
let rows = store.messages("srv", &channel, PageQuery::default()).unwrap();
|
||||
@@ -611,6 +635,350 @@ mod tests {
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
/// What `serde_json::to_string(&tsproto::Identity)` writes for the test
|
||||
/// identity of tsproto's own `identity_tests` (the fixture row of
|
||||
/// `voelin-identity`'s `tests/storage.rs`): its unique id and security
|
||||
/// level are checked against the real tsproto below.
|
||||
const TEAMSPEAK_JSON: &str = r#"{"key":"YTyJofmztcTBjq3KZcDdxu+G4RPVwE5vg8VaN2jbQao=","counter":2792354,"max_counter":2792354}"#;
|
||||
const TEAMSPEAK_UID: &str = "test/9PZ9vww/Bpf5vJxtJhpz80=";
|
||||
const TEAMSPEAK_LEVEL: u8 = 21;
|
||||
|
||||
/// A `client.db` as it was at schema `version`: the migrations below
|
||||
/// `version` applied by the code that runs them, nothing else.
|
||||
fn database_at(path: &Path, version: usize) {
|
||||
let mut db = rusqlite::Connection::open(path).unwrap();
|
||||
for migration in &MIGRATIONS[..version] {
|
||||
match migration {
|
||||
Migration::Sql(sql) => db.execute_batch(sql).unwrap(),
|
||||
Migration::Code(migrate) => {
|
||||
let tx = db.transaction().unwrap();
|
||||
migrate(&tx).unwrap();
|
||||
tx.commit().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
db.pragma_update(None, "user_version", version as i64).unwrap();
|
||||
}
|
||||
|
||||
fn scratch_dir(name: &str) -> std::path::PathBuf {
|
||||
let dir = std::env::temp_dir().join(format!("voelin-store-{name}-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
dir
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_teamspeak_fixture_is_what_tsproto_writes() {
|
||||
let identity: Identity = serde_json::from_str(TEAMSPEAK_JSON).unwrap();
|
||||
assert_eq!(identity.key().to_pub().get_uid(), TEAMSPEAK_UID);
|
||||
assert_eq!(identity.level(), TEAMSPEAK_LEVEL);
|
||||
assert_eq!(serde_json::to_string(&identity).unwrap(), TEAMSPEAK_JSON);
|
||||
}
|
||||
|
||||
/// The identity migrations are `voelin-identity`'s SQL, and a shipped
|
||||
/// version never changes: a newer revision of the protocol repository
|
||||
/// that touched either string would fail here instead of changing what
|
||||
/// version 6 or 7 does to an installed database.
|
||||
#[test]
|
||||
fn the_identity_migrations_are_pinned() {
|
||||
let sql = |index: usize| match &MIGRATIONS[index] {
|
||||
Migration::Sql(sql) => *sql,
|
||||
Migration::Code(_) => panic!("migration {index} is code"),
|
||||
};
|
||||
assert_eq!(MIGRATIONS.len(), 7);
|
||||
assert_eq!(
|
||||
sql(5),
|
||||
"ALTER TABLE identities ADD COLUMN kind TEXT NOT NULL DEFAULT 'teamspeak';"
|
||||
);
|
||||
assert_eq!(
|
||||
sql(6),
|
||||
"ALTER TABLE identities ADD COLUMN account TEXT;\n\
|
||||
ALTER TABLE identities ADD COLUMN integration TEXT;\n\
|
||||
ALTER TABLE identities ADD COLUMN integration_rev INTEGER NOT NULL DEFAULT 0;\n\
|
||||
ALTER TABLE identities ADD COLUMN synced INTEGER NOT NULL DEFAULT 0;"
|
||||
);
|
||||
}
|
||||
|
||||
/// A database of version 5 (what 0.1 ships) gets the `kind` column and
|
||||
/// then the account columns in one open; every identity stays as it was:
|
||||
/// kind `teamspeak`, unbound, its JSON byte for byte, its origin and
|
||||
/// default flag, and the level computed from the key as before.
|
||||
#[test]
|
||||
fn migrates_version_5_identities_through_both_steps() {
|
||||
use voelin_identity::migrate::SELECT_ACCOUNT_COLUMNS;
|
||||
use voelin_identity::{AccountBinding, IdentityBlob, KIND_TEAMSPEAK};
|
||||
|
||||
let dir = scratch_dir("v5");
|
||||
let path = dir.join("client.db");
|
||||
let other = Identity::create();
|
||||
let other_json = serde_json::to_string(&other).unwrap();
|
||||
let other_uid = other.key().to_pub().get_uid();
|
||||
database_at(&path, 5);
|
||||
{
|
||||
let db = rusqlite::Connection::open(&path).unwrap();
|
||||
assert_eq!(
|
||||
db.pragma_query_value(None, "user_version", |r| r.get::<_, i64>(0)).unwrap(),
|
||||
5
|
||||
);
|
||||
for (name, uid, json, origin, default) in [
|
||||
("Main", TEAMSPEAK_UID, TEAMSPEAK_JSON, "imported", 1),
|
||||
("Other", other_uid.as_str(), other_json.as_str(), "user", 0),
|
||||
] {
|
||||
db.execute(
|
||||
"INSERT INTO identities (name, uid, data, origin, is_default)
|
||||
VALUES (?1, ?2, ?3, ?4, ?5)",
|
||||
params![name, uid, json, origin, default],
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
let store = Store::open(&path).unwrap();
|
||||
assert_eq!(Store::SCHEMA_VERSION, 7);
|
||||
assert_eq!(store.schema_version().unwrap(), 7);
|
||||
|
||||
// Read as the key store reads a row of the migrated table.
|
||||
let rows: Vec<_> = store
|
||||
.db
|
||||
.prepare(&format!("SELECT {SELECT_ACCOUNT_COLUMNS} FROM identities ORDER BY id"))
|
||||
.unwrap()
|
||||
.query_map([], |r| {
|
||||
Ok((
|
||||
r.get::<_, String>(0)?,
|
||||
r.get::<_, String>(1)?,
|
||||
r.get::<_, String>(2)?,
|
||||
r.get::<_, Option<String>>(3)?,
|
||||
r.get::<_, Option<String>>(4)?,
|
||||
r.get::<_, i64>(5)?,
|
||||
r.get::<_, i64>(6)?,
|
||||
))
|
||||
})
|
||||
.unwrap()
|
||||
.collect::<rusqlite::Result<_>>()
|
||||
.unwrap();
|
||||
assert_eq!(rows.len(), 2);
|
||||
for ((kind, uid, data, account, integration, rev, synced), (want_uid, want_json)) in
|
||||
rows.into_iter().zip([(TEAMSPEAK_UID, TEAMSPEAK_JSON), (&*other_uid, &*other_json)])
|
||||
{
|
||||
assert_eq!(kind, KIND_TEAMSPEAK);
|
||||
let binding = AccountBinding::from_columns(
|
||||
account.as_deref(),
|
||||
integration.as_deref(),
|
||||
rev,
|
||||
synced,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(binding, None, "an old row is unbound");
|
||||
assert_eq!((uid.as_str(), data.as_str()), (want_uid, want_json), "byte for byte");
|
||||
let blob = IdentityBlob::from_row(&kind, uid, 0, data);
|
||||
assert!(blob.is_teamspeak());
|
||||
}
|
||||
|
||||
// The old API sees what it saw before, origin and default included.
|
||||
let list = store.identities().unwrap();
|
||||
assert_eq!(list.len(), 2);
|
||||
assert_eq!((list[0].name.as_str(), list[0].uid.as_str()), ("Main", TEAMSPEAK_UID));
|
||||
assert_eq!(
|
||||
(list[0].level, list[0].origin, list[0].is_default),
|
||||
(21, IdentityOrigin::Imported, true)
|
||||
);
|
||||
assert_eq!((list[1].name.as_str(), list[1].uid.as_str()), ("Other", &*other_uid));
|
||||
assert_eq!(
|
||||
(list[1].level, list[1].origin, list[1].is_default),
|
||||
(other.level(), IdentityOrigin::User, false)
|
||||
);
|
||||
assert_eq!(store.default_identity().unwrap().unwrap().id, list[0].id);
|
||||
assert_eq!(store.identity(list[1].id).unwrap().counter(), other.counter());
|
||||
drop(store);
|
||||
|
||||
// Opened again, nothing runs twice.
|
||||
let store = Store::open(&path).unwrap();
|
||||
assert_eq!(store.schema_version().unwrap(), 7);
|
||||
assert_eq!(store.identities().unwrap(), list);
|
||||
drop(store);
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
/// The acceptance of the migration for the key store: a `client.db` at the
|
||||
/// version before the identity migrations (5), and at the one between them
|
||||
/// (6), opens, and every identity loads through the key store unchanged:
|
||||
/// kind `teamspeak`, no binding, its JSON byte for byte, the level computed
|
||||
/// as before, and the origin and default flag the old API reports kept.
|
||||
#[test]
|
||||
fn a_migrated_database_loads_every_identity_unchanged_through_the_key_store() {
|
||||
use crate::SqliteKeyStore;
|
||||
use voelin_identity::{IdentityBlob, IdentityInfo, KIND_TEAMSPEAK, KeyStore};
|
||||
|
||||
for version in [5, 6] {
|
||||
let dir = scratch_dir(&format!("keys-v{version}"));
|
||||
let path = dir.join("client.db");
|
||||
let other = Identity::create();
|
||||
let other_json = serde_json::to_string(&other).unwrap();
|
||||
let other_uid = other.key().to_pub().get_uid();
|
||||
database_at(&path, version);
|
||||
{
|
||||
let db = rusqlite::Connection::open(&path).unwrap();
|
||||
for (name, uid, json, origin, default) in [
|
||||
("Main", TEAMSPEAK_UID, TEAMSPEAK_JSON, "imported", 1),
|
||||
("Other", other_uid.as_str(), other_json.as_str(), "created", 0),
|
||||
] {
|
||||
db.execute(
|
||||
"INSERT INTO identities (name, uid, data, origin, is_default)
|
||||
VALUES (?1, ?2, ?3, ?4, ?5)",
|
||||
params![name, uid, json, origin, default],
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
let keys = SqliteKeyStore::open(&path).unwrap();
|
||||
assert_eq!(keys.with_store(|s| s.schema_version().unwrap()), 7);
|
||||
let want = [
|
||||
(TEAMSPEAK_UID.to_owned(), TEAMSPEAK_JSON.to_owned(), TEAMSPEAK_LEVEL),
|
||||
(other_uid.clone(), other_json.clone(), other.level()),
|
||||
];
|
||||
let mut infos: Vec<_> = want
|
||||
.iter()
|
||||
.map(|(uid, _, level)| IdentityInfo {
|
||||
kind: KIND_TEAMSPEAK.into(),
|
||||
uid: uid.clone(),
|
||||
level: *level,
|
||||
binding: None,
|
||||
})
|
||||
.collect();
|
||||
infos.sort_by(|a, b| a.uid.cmp(&b.uid));
|
||||
assert_eq!(keys.list().unwrap(), infos, "version {version}");
|
||||
for (uid, json, level) in want {
|
||||
let blob = keys.get(KIND_TEAMSPEAK, &uid).unwrap().unwrap();
|
||||
assert_eq!(blob, IdentityBlob::teamspeak(&uid, level, &json), "version {version}");
|
||||
assert_eq!(blob.json, json, "byte for byte");
|
||||
assert_eq!(blob.binding, None);
|
||||
}
|
||||
|
||||
// What the TeamSpeak methods report is kept as well.
|
||||
let entries = keys.with_store(|s| s.identities().unwrap());
|
||||
let origin = |uid: &str| entries.iter().find(|e| e.uid == uid).unwrap();
|
||||
assert_eq!(
|
||||
(origin(TEAMSPEAK_UID).origin, origin(TEAMSPEAK_UID).is_default),
|
||||
(IdentityOrigin::Imported, true)
|
||||
);
|
||||
assert_eq!(
|
||||
(origin(&other_uid).origin, origin(&other_uid).is_default),
|
||||
(IdentityOrigin::Created, false)
|
||||
);
|
||||
drop(keys);
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
/// A database of version 6 (the `kind` column, no account columns yet) takes
|
||||
/// the second step alone, and its rows of other kinds stay what they are.
|
||||
#[test]
|
||||
fn migrates_version_6_identities_to_accounts() {
|
||||
let dir = scratch_dir("v6");
|
||||
let path = dir.join("client.db");
|
||||
database_at(&path, 6);
|
||||
{
|
||||
let db = rusqlite::Connection::open(&path).unwrap();
|
||||
db.execute(
|
||||
"INSERT INTO identities (name, uid, data, origin, is_default)
|
||||
VALUES ('Main', ?1, ?2, 'created', 1)",
|
||||
params![TEAMSPEAK_UID, TEAMSPEAK_JSON],
|
||||
)
|
||||
.unwrap();
|
||||
db.execute(
|
||||
"INSERT INTO identities (name, uid, data, kind)
|
||||
VALUES ('key', 'abc', '{\"v\":1}', 'voelin')",
|
||||
[],
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
let store = Store::open(&path).unwrap();
|
||||
assert_eq!(store.schema_version().unwrap(), 7);
|
||||
let (kind, account, integration, rev, synced): (
|
||||
String,
|
||||
Option<String>,
|
||||
Option<String>,
|
||||
i64,
|
||||
i64,
|
||||
) = store
|
||||
.db
|
||||
.query_row(
|
||||
"SELECT kind, account, integration, integration_rev, synced FROM identities
|
||||
WHERE uid = 'abc'",
|
||||
[],
|
||||
|r| Ok((r.get(0)?, r.get(1)?, r.get(2)?, r.get(3)?, r.get(4)?)),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
(kind.as_str(), account, integration, rev, synced),
|
||||
("voelin", None, None, 0, 0)
|
||||
);
|
||||
let list = store.identities().unwrap();
|
||||
assert_eq!(list.len(), 1, "the Voelin row is not a TeamSpeak identity");
|
||||
assert_eq!(
|
||||
(list[0].origin, list[0].is_default, list[0].level),
|
||||
(IdentityOrigin::Created, true, 21)
|
||||
);
|
||||
drop(store);
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
/// Rows of other kinds share the table with the TeamSpeak identities and
|
||||
/// are none of the TeamSpeak methods' business: they are not listed, not
|
||||
/// read as an identity, not renamed, changed, made the default or deleted
|
||||
/// (the JSON of a Voelin key is not a `tsproto::Identity`, and listing
|
||||
/// would fail on it).
|
||||
#[test]
|
||||
fn the_teamspeak_methods_leave_other_kinds_alone() {
|
||||
let store = Store::open_in_memory().unwrap();
|
||||
let mine = Identity::create();
|
||||
let id = store.add_identity("mine", &mine, IdentityOrigin::User).unwrap();
|
||||
let other_id = |kind: &str, uid: &str| {
|
||||
store
|
||||
.db
|
||||
.execute(
|
||||
"INSERT INTO identities (name, uid, data, kind) VALUES (?1, ?2, '{\"v\":1}', ?1)",
|
||||
params![kind, uid],
|
||||
)
|
||||
.unwrap();
|
||||
store.db.last_insert_rowid()
|
||||
};
|
||||
let voelin = other_id("voelin", "v1");
|
||||
let account = other_id("account", "account:a1");
|
||||
|
||||
let list = store.identities().unwrap();
|
||||
assert_eq!(list.iter().map(|e| e.id).collect::<Vec<_>>(), [id]);
|
||||
assert_eq!(store.default_identity().unwrap().unwrap().id, id);
|
||||
for other in [voelin, account] {
|
||||
assert!(matches!(store.identity(other), Err(Error::NotFound(..))));
|
||||
assert!(matches!(store.rename_identity(other, "x"), Err(Error::NotFound(..))));
|
||||
assert!(matches!(store.update_identity(other, &mine), Err(Error::NotFound(..))));
|
||||
assert!(matches!(store.set_default_identity(other, true), Err(Error::NotFound(..))));
|
||||
store.delete_identity(other).unwrap();
|
||||
}
|
||||
let rows: i64 =
|
||||
store.db.query_row("SELECT count(*) FROM identities", [], |r| r.get(0)).unwrap();
|
||||
assert_eq!(rows, 3, "nothing of another kind was deleted");
|
||||
let names: Vec<String> = store
|
||||
.db
|
||||
.prepare("SELECT name FROM identities ORDER BY id")
|
||||
.unwrap()
|
||||
.query_map([], |r| r.get(0))
|
||||
.unwrap()
|
||||
.collect::<rusqlite::Result<_>>()
|
||||
.unwrap();
|
||||
assert_eq!(names, ["mine", "voelin", "account"]);
|
||||
let defaults: i64 = store
|
||||
.db
|
||||
.query_row("SELECT count(*) FROM identities WHERE is_default", [], |r| r.get(0))
|
||||
.unwrap();
|
||||
assert_eq!(defaults, 1);
|
||||
// A TeamSpeak identity is deleted as before.
|
||||
store.delete_identity(id).unwrap();
|
||||
assert!(store.identities().unwrap().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bookmarks_keep_order_and_fields() {
|
||||
let store = Store::open_in_memory().unwrap();
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -48,3 +48,6 @@ allow-wildcard-paths = true
|
||||
[sources]
|
||||
unknown-registry = "deny"
|
||||
unknown-git = "deny"
|
||||
# The private protocol repository (voelin-identity and its voelin-proto);
|
||||
# docs/building.md, "Depending on VoelinProtocol".
|
||||
allow-git = ["ssh://gitea@git.faumaray.com/Voelin/VoelinProtocol.git"]
|
||||
+37
-1
@@ -69,7 +69,7 @@ fuzz/ cargo-fuzz targets
|
||||
| `voelin-query` | ServerQuery codec and transports: raw TCP, SSH (russh), HTTP WebQuery | done |
|
||||
| `voelin-observer` | Presence tracker + chat relay pool over `voelin-query` | done |
|
||||
| `voelin-gateway-proto`, `voelin-gateway` (`tsgw`) | Companion service for server admins: identity-challenge auth, permission-mirroring authorization, presence stream, chat relay, SQLite history, WebSocket + JSON (`tsgw.v1+json`) | done |
|
||||
| `voelin-store` | Identities, bookmarks, settings, chat history (dedupe, paging, sync cursors, where each chat was read), contacts, secrets (keyring / Android Keystore); versioned schema | done |
|
||||
| `voelin-store` | Identities (TeamSpeak, a Voelin key, the signed-in account, each with its account binding, as a `voelin-identity` `KeyStore`; see Identities), bookmarks, settings, chat history (dedupe, paging, sync cursors, where each chat was read), contacts, secrets (keyring / Android Keystore); versioned schema | done |
|
||||
| `voelin-audio` | Capture/playback, Opus, echo cancellation, resampling, jitter buffer, mixer, VAD/push-to-talk; the voice packet types (`TalkerId`, `VoicePacket`, `EncodedVoice`), so it depends on no voice transport | v0 (no AEC yet) |
|
||||
| `voelin-stream` | TS6 stream commands, JSON signalling, str0m peer connections, host/STUN candidates, streamer/viewer sessions, frame-source seam; its frame and simulcast layer types are `voelin-media`'s | sessions + transport |
|
||||
| `voelin-core` | Engine: runtime, per-server sessions, merge of voice/gateway/query sources, the `ServerLink` seam the voice source sits behind (`link.rs`; `TsLink` is the TeamSpeak implementation, for now in this crate), event bus, command API, chat history, the gateway's features, audio settings and volumes, streams on TS6, files, avatar and icon cache, pokes, offline messages, contacts; `media` module (capture → encoder → stream, stream → decoder); the stream types of its API are its own (`stream_types`, see Streams) | done |
|
||||
@@ -323,6 +323,42 @@ their private messages and pokes are dropped or flagged per
|
||||
`stream.permissions = friends` lets friends watch our
|
||||
stream without asking and asks for everyone else.
|
||||
|
||||
## Identities
|
||||
|
||||
The `identities` table of `voelin-store` holds identities of more than one kind.
|
||||
A row is a `voelin_identity::IdentityBlob` { `kind`, `uid`, `level`, `json` }
|
||||
with an optional account binding: a `teamspeak` row is the JSON of a
|
||||
`tsproto::Identity`, exactly as the client has always stored it; a `voelin` row
|
||||
is an Ed25519 key; the `account` row (`account:<account uid>`) says which
|
||||
account the installation is signed in to and which key is its device key; a
|
||||
kind this version does not know passes through untouched. `uid` is unique
|
||||
across kinds, and the uid forms of the kinds do not overlap. The table got its
|
||||
new columns from two schema versions, 6 (`kind`, defaulting to `teamspeak`) and
|
||||
7 (`account`, `integration`, `integration_rev`, `synced`), the SQL of which is
|
||||
`voelin-identity`'s (`migrate::ADD_KIND_COLUMN` and `ADD_ACCOUNT_COLUMNS`);
|
||||
every identity that existed stays what it was: kind `teamspeak`, unbound, its
|
||||
JSON untouched, its origin and default flag kept.
|
||||
|
||||
`Store` keeps the TeamSpeak identity methods (`identities`, `identity`,
|
||||
`add_identity`, ...), which act on `teamspeak` rows only, so nothing above the
|
||||
store changed. `SqliteKeyStore` is the same table as a `KeyStore`, with the
|
||||
binding: `put` replaces a row of the same `(kind, uid)` and keeps its name,
|
||||
origin and default flag, a uid another kind holds is refused, a TeamSpeak blob
|
||||
is stored only when its JSON is a tsproto identity whose key has the uid it
|
||||
names (the error says only that, never the JSON: it is a private key), and
|
||||
the TeamSpeak security level is still computed from the key, never stored. A
|
||||
`put` that changes only the binding of a row does not read its JSON again, so a
|
||||
row damaged outside the client cannot keep a sign-out from unbinding it.
|
||||
Signing out of an account is the trait's `sign_out`, run on this table: it
|
||||
removes the account record and the synced copies, unbinds the identities only
|
||||
this device holds, keeps the device key (unbound, byte for byte) when the
|
||||
record says it predates the account, and deletes it when it does not or when
|
||||
the caller asks to forget it. The engine and the UI do not use the key store
|
||||
yet; accounts, sign-in and the integrations page are later steps.
|
||||
|
||||
`voelin-identity` comes from the private VoelinProtocol repository as a git
|
||||
dependency pinned by commit ([building.md](building.md#depending-on-voelinprotocol)).
|
||||
|
||||
## Streams
|
||||
|
||||
`voelin-stream::Streams` holds the stream state of one TS6 connection without
|
||||
|
||||
@@ -124,3 +124,60 @@ the proxy is on localhost. If the proxy inspects TLS, set
|
||||
`scripts/flatpak-build.sh` writes `dist/flatpak/voelin.flatpak` using the
|
||||
release builder image. It requires a privileged container for Flatpak's
|
||||
nested sandbox; do not use it on an untrusted build host.
|
||||
|
||||
## Depending on VoelinProtocol
|
||||
|
||||
`voelin-store` uses `voelin-identity` (the identity blobs, the account-bound
|
||||
`KeyStore` and the sign-out rules) from the **private** VoelinProtocol
|
||||
repository, as a Cargo git dependency in the workspace `Cargo.toml`:
|
||||
|
||||
```toml
|
||||
[workspace.dependencies]
|
||||
voelin-identity = { git = "ssh://gitea@git.faumaray.com/Voelin/VoelinProtocol.git", rev = "…" }
|
||||
```
|
||||
|
||||
It is pinned by commit until the protocol tags a release that has it; moving
|
||||
to a newer protocol means changing the `rev` (later a `tag`) and committing
|
||||
the resulting `Cargo.lock` together with `THIRD_PARTY_NOTICES.md`, which
|
||||
`scripts/notices.sh` regenerates (the CI notices job fails on a stale one).
|
||||
Cargo fetches it over SSH, so the machine needs an SSH key that can read
|
||||
VoelinProtocol (an `ssh-agent` or a `~/.ssh/config` entry for
|
||||
`git.faumaray.com`); if Cargo's built-in git client cannot use your SSH setup,
|
||||
set `net.git-fetch-with-cli = true` in `~/.cargo/config.toml`.
|
||||
`voelin-identity` builds AWS-LC from source (`aws-lc-sys`), which needs a C
|
||||
compiler (gcc or clang) and cmake.
|
||||
`deny.toml` allows this one git source.
|
||||
|
||||
**CI and the Docker builds need read access to that repository too**: an SSH
|
||||
deploy key (a repository secret written to `~/.ssh`, with the server's host key
|
||||
in `known_hosts`) or an access token (rewrite the SSH URL to HTTPS with
|
||||
`git config --global url."https://<token>@git.faumaray.com/".insteadOf ssh://gitea@git.faumaray.com/`
|
||||
and set `CARGO_NET_GIT_FETCH_WITH_CLI=true`). Without it `cargo` cannot fetch
|
||||
the dependency and a fresh checkout does not build; the details are in
|
||||
VoelinProtocol's `docs/development.md` ("Depending on VoelinProtocol").
|
||||
|
||||
### Working with a sibling VoelinProtocol checkout
|
||||
|
||||
To change the protocol and this client together, check VoelinProtocol out next
|
||||
to this repository (`Projects/Voelin/VoelinProtocol` beside
|
||||
`Projects/Voelin/VoelinClient`) and redirect the git dependency to it with a
|
||||
per-developer `.cargo/config.toml` in the root of this repository:
|
||||
|
||||
```toml
|
||||
# VoelinClient/.cargo/config.toml (per developer, never committed)
|
||||
[patch."ssh://gitea@git.faumaray.com/Voelin/VoelinProtocol.git"]
|
||||
voelin-identity = { path = "../VoelinProtocol/crates/voelin-identity" }
|
||||
# voelin-proto is a dependency of voelin-identity from the same repository:
|
||||
voelin-proto = { path = "../VoelinProtocol/crates/voelin-proto" }
|
||||
```
|
||||
|
||||
- Relative paths in a Cargo config file resolve from the directory that
|
||||
contains `.cargo`, so `../VoelinProtocol` is the sibling checkout. (A git
|
||||
worktree of this repository, such as `.wt/<name>`, uses the matching number
|
||||
of `../` or an absolute path.)
|
||||
- The URL must be spelled exactly as in the workspace `Cargo.toml`.
|
||||
- `/.cargo/` is in `.gitignore`: the file is yours and is never committed.
|
||||
- With the patch active Cargo rewrites `Cargo.lock` (the patched crates lose
|
||||
their git `source`). Do not commit that: run `git checkout Cargo.lock` before
|
||||
committing, or remove the file and run `cargo update -p voelin-identity`
|
||||
after changing the `rev`. CI builds with `--locked` and has no patch.
|
||||
+6
-1
@@ -55,7 +55,12 @@ the separate `release.yml` workflow below.
|
||||
3. Allow network access from the runner and job container to the Gitea
|
||||
instance, GitHub (checkout action, dependencies and RustSec advisories),
|
||||
GHCR (runner image), Ubuntu apt mirrors, rustup distribution servers,
|
||||
crates.io and dependency/license sources used by cargo-about.
|
||||
crates.io and dependency/license sources used by cargo-about. The
|
||||
workspace also depends on the **private** VoelinProtocol repository
|
||||
(`voelin-identity`, over SSH), so the job needs read access to it: an SSH
|
||||
deploy key or an access token, set up as in
|
||||
[building.md](building.md#depending-on-voelinprotocol). Until a runner has
|
||||
it, a fresh checkout does not build there.
|
||||
4. Provision enough RAM, swap and free disk for a full Slint workspace build
|
||||
plus cargo-deny/cargo-about compilation. These are large builds; monitor
|
||||
the first run and size the runner accordingly. The workflow limits Cargo
|
||||
|
||||
Reference in new issue
Block a user