voelin-store: a damaged TeamSpeak identity row is reported by its kind of damage, never by its text
Store::identity and Store::identities read the stored JSON of a TeamSpeak
identity with `?`, so a row whose data was damaged outside the client came back
as Error::Json carrying serde_json's message, and that message quotes a value
it refuses: tsproto reports a key that does not import as an invalid value, the
key string and all. The error reaches status lines, events and logs.
identity_from_json classifies the error as voelin-core's ts::identity::from_json
does (voelin-core depends on voelin-store, so the classification is here too):
Error::Identity { damage: IdentityDamage, line, column } says malformed, cut
short, not an identity or unreadable, and where, and nothing of the text.
Error::Json stays for the bookmarks and settings, which hold no secret.
The key store was checked as the recorded leak (docs/session-seam.md 17.6)
names it, and does not leak: check_teamspeak (keystore.rs) drops the parse
error with `let Ok(..) else`, Columns::level uses `map_or`, and the warning of a
damaged binding names the row's kind and uid. A test pins that too.
tests/identity_text.rs damages a row six ways (a key that does not import, a
counter of the wrong type, syntax, a text cut inside its key, bytes that are no
UTF-8 as a BLOB and as TEXT) through a second connection, calls everything of
Store and SqliteKeyStore that reads or writes it, and looks through the errors
(text, Debug and sources) and every log line at TRACE (a capturing subscriber in
tests/support) for any 8 characters in a row of the row's data. A control shows
that serde's own message quotes the value and that the capture sees a warning.
With identity_from_json returning the old error the first test fails, naming
the quoted key; the key store test is a guard.
docs/session-seam.md 17.6: the leak bullet is closed.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
412f909d18
commit
18b280df7e
5 files changed
+415
-12
No files matched your search
@@ -33,12 +33,48 @@ pub use store::{
|
||||
Bookmark, CachedServerIcon, IdentityEntry, IdentityOrigin, QueryConfig, QueryTransport, Store,
|
||||
};
|
||||
|
||||
/// How the JSON of a stored TeamSpeak identity is wrong: the category of the
|
||||
/// reader's complaint and nothing of the text, which holds a private key.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum IdentityDamage {
|
||||
/// The text is not JSON.
|
||||
Malformed,
|
||||
/// The text ends before the JSON does.
|
||||
CutShort,
|
||||
/// The JSON is not that of an identity: a field is missing or of another
|
||||
/// type, or the key does not import.
|
||||
NotAnIdentity,
|
||||
/// The text could not be read.
|
||||
Unreadable,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for IdentityDamage {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str(match self {
|
||||
Self::Malformed => "malformed",
|
||||
Self::CutShort => "cut short",
|
||||
Self::NotAnIdentity => "not an identity",
|
||||
Self::Unreadable => "unreadable",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
#[error("database: {0}")]
|
||||
Db(#[from] rusqlite::Error),
|
||||
#[error("serialization: {0}")]
|
||||
Json(#[from] serde_json::Error),
|
||||
/// The JSON of a stored TeamSpeak identity cannot be read, which only damage
|
||||
/// outside the client can cause. It says how the text is wrong and where, and
|
||||
/// never what it holds: the text is a private key, and the message of the
|
||||
/// JSON reader quotes the value it refuses (`tsproto` reports a key that does
|
||||
/// not import as an invalid value, the key string and all), so that message is
|
||||
/// not kept, not here and not in a log line.
|
||||
#[error(
|
||||
"the stored TeamSpeak identity cannot be read: {damage} at line {line}, column {column}"
|
||||
)]
|
||||
Identity { damage: IdentityDamage, line: usize, column: usize },
|
||||
#[error("{0} {1} not found")]
|
||||
NotFound(&'static str, i64),
|
||||
#[error("secret store: {0}")]
|
||||
|
||||
@@ -8,7 +8,7 @@ use serde::de::DeserializeOwned;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tsclientlib::Identity;
|
||||
|
||||
use crate::{Error, Result};
|
||||
use crate::{Error, IdentityDamage, Result};
|
||||
|
||||
/// A schema migration: SQL, or code for what SQL alone cannot do.
|
||||
enum Migration {
|
||||
@@ -244,6 +244,28 @@ impl Bookmark {
|
||||
/// waits.
|
||||
const CHECKPOINT_WAIT: Duration = Duration::from_millis(150);
|
||||
|
||||
/// The TeamSpeak identity in the JSON of a stored row.
|
||||
///
|
||||
/// A text that does not read (it could only have been damaged outside the
|
||||
/// client: [`Store::add_identity`] writes what `serde_json` makes of an
|
||||
/// identity) is refused with [`Error::Identity`], which says how it is wrong and
|
||||
/// where and never what it holds, as `voelin-core`'s `ts::identity::from_json`
|
||||
/// does for the text it is handed. The reader's own message is dropped: it
|
||||
/// quotes a value it refuses, and `tsproto` reports a key that does not import
|
||||
/// as an invalid value, the key string and all, which would reach a status line
|
||||
/// or a log.
|
||||
fn identity_from_json(json: &str) -> Result<Identity> {
|
||||
serde_json::from_str(json).map_err(|error| {
|
||||
let damage = match error.classify() {
|
||||
serde_json::error::Category::Syntax => IdentityDamage::Malformed,
|
||||
serde_json::error::Category::Eof => IdentityDamage::CutShort,
|
||||
serde_json::error::Category::Data => IdentityDamage::NotAnIdentity,
|
||||
serde_json::error::Category::Io => IdentityDamage::Unreadable,
|
||||
};
|
||||
Error::Identity { damage, line: error.line(), column: error.column() }
|
||||
})
|
||||
}
|
||||
|
||||
pub struct Store {
|
||||
pub(crate) db: Connection,
|
||||
}
|
||||
@@ -348,7 +370,7 @@ impl Store {
|
||||
})?;
|
||||
rows.map(|row| {
|
||||
let (id, name, uid, data, origin, is_default) = row?;
|
||||
let identity: Identity = serde_json::from_str(&data)?;
|
||||
let identity = identity_from_json(&data)?;
|
||||
let origin = IdentityOrigin::parse(&origin);
|
||||
Ok(IdentityEntry { id, name, uid, level: identity.level(), origin, is_default })
|
||||
})
|
||||
@@ -395,7 +417,7 @@ impl Store {
|
||||
)
|
||||
.optional()?;
|
||||
let data = data.ok_or(Error::NotFound("identity", id))?;
|
||||
Ok(serde_json::from_str(&data)?)
|
||||
identity_from_json(&data)
|
||||
}
|
||||
|
||||
/// Store an identity again, e.g. after its security level was improved.
|
||||
|
||||
Reference in new issue
Block a user