Core 0.1.2 (zero-leading private key load fix); capture state in diagnostics; changelog
This commit is contained in:
1 parent
7ad5ee8572
commit
401c331aa4
11 files changed
+224
-11
No files matched your search
+2
-2
@@ -12,8 +12,8 @@
|
||||
- Voice diagnostics: the local log records the capture device and track state; with
|
||||
`TEAMSPEACH_LOG=debug` it also records push-to-talk presses with window focus and each transmission burst
|
||||
(frames, peak level). A warning appears when two seconds of transmitted audio are silent. The push-to-talk hint says when the window is not focused (the key is read only there).
|
||||
- Core: identities whose private scalar starts with a zero byte are read correctly (≈0.4 % of new identities
|
||||
were rejected after restart).
|
||||
- Fixed: ~1/256 newly created or imported identities could not be loaded again (private key with a leading
|
||||
zero byte). Storage format unchanged.
|
||||
|
||||
## 0.1.1 — 2026-10-24
|
||||
|
||||
|
||||
@@ -452,7 +452,7 @@ Object.defineProperty(window, 'teamspeachDiagnostics', {
|
||||
clients: S.snap ? S.snap.clients.map((c) => ({ id: c.id, nickname: c.nickname, channel: c.channel_id, type: c.client_type, inputMuted: c.input_muted })) : [],
|
||||
talking: Array.from(S.talking),
|
||||
audio: { ...S.audio },
|
||||
voice: { ...voice.voiceStats, sending: voice.isSending() },
|
||||
voice: { ...voice.voiceStats, sending: voice.isSending(), capturing: voice.isCapturing() },
|
||||
streams: Array.from(watch.directory.streams.values()).map((s) => ({ id: s.id, clientId: s.clientId, name: s.name })),
|
||||
watch: { ...watch.watchStats },
|
||||
videoCodecs: settings.videoCodecs(),
|
||||
|
||||
@@ -288,6 +288,10 @@ export function transmitHint() {
|
||||
return `Клавиша: ${keyLabel(S.prefs.pttCode)}`;
|
||||
}
|
||||
|
||||
export function isCapturing() {
|
||||
return Boolean(engine && engine.capturing);
|
||||
}
|
||||
|
||||
export function isSending() {
|
||||
return sending;
|
||||
}
|
||||
|
||||
Generated
+2
-1
@@ -1869,7 +1869,7 @@ checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417"
|
||||
|
||||
[[package]]
|
||||
name = "teamspeach-core"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"audiopus",
|
||||
"base64 0.22.1",
|
||||
@@ -1877,6 +1877,7 @@ dependencies = [
|
||||
"num-traits",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha-1",
|
||||
"thiserror 2.0.21",
|
||||
"tokio",
|
||||
"tracing",
|
||||
|
||||
+2
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "teamspeach-core"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
edition = "2021"
|
||||
rust-version = "1.89"
|
||||
description = "TeamsPeach native TeamSpeak protocol core (stdio JSON bridge)"
|
||||
@@ -21,6 +21,7 @@ futures = "0.3"
|
||||
num-traits = "0.2"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = { version = "1", features = ["raw_value", "preserve_order"] }
|
||||
sha-1 = "0.10"
|
||||
thiserror = "2"
|
||||
tokio = { version = "1", features = ["rt", "macros", "io-std", "io-util", "sync", "time"] }
|
||||
tracing = "0.1"
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
//! Decoding of stored TeamSpeak private keys that tolerates leading zero bytes.
|
||||
//!
|
||||
//! Upstream `tsproto_types::crypto::EccKeyPrivP256::from_tomcrypt` passes the DER integer's
|
||||
//! minimal big-endian bytes to `from_short`, which requires exactly 32 bytes. A private scalar
|
||||
//! whose top byte is 0x00 (about 1 key in 256) is therefore written fine by `to_ts` but can never
|
||||
//! be read back. This module parses the libtomcrypt DER itself and left-pads the scalar.
|
||||
|
||||
use base64::prelude::*;
|
||||
use sha1::{Digest, Sha1};
|
||||
use tsclientlib::Identity;
|
||||
use tsproto_types::crypto::EccKeyPrivP256;
|
||||
|
||||
/// XOR mask TeamSpeak applies to identities in its settings/export files (same constant as
|
||||
/// tsproto-types' `IDENTITY_OBFUSCATION`, MIT OR Apache-2.0).
|
||||
const IDENTITY_OBFUSCATION: &[u8; 128] = b"b9dfaa7bee6ac57ac7b65f1094a1c155\
|
||||
e747327bc2fe5d51c512023fe54a280201004e90ad1daaae1075d53b7d571c30e063b5a\
|
||||
62a4a017bb394833aa0983e6e";
|
||||
|
||||
fn tlv<'a>(d: &'a [u8], i: &mut usize) -> Option<(u8, &'a [u8])> {
|
||||
let tag = *d.get(*i)?;
|
||||
let first = *d.get(*i + 1)? as usize;
|
||||
*i += 2;
|
||||
let len = if first & 0x80 == 0 {
|
||||
first
|
||||
} else {
|
||||
let n = first & 0x7f;
|
||||
if n == 0 || n > 4 {
|
||||
return None;
|
||||
}
|
||||
let mut l = 0usize;
|
||||
for _ in 0..n {
|
||||
l = (l << 8) | *d.get(*i)? as usize;
|
||||
*i += 1;
|
||||
}
|
||||
l
|
||||
};
|
||||
let v = d.get(*i..i.checked_add(len)?)?;
|
||||
*i += len;
|
||||
Some((tag, v))
|
||||
}
|
||||
|
||||
/// Private key from libtomcrypt DER: `SEQUENCE { BIT STRING flags, INTEGER size, INTEGER x,
|
||||
/// INTEGER y, INTEGER priv }`, or the 2-bit variant `{ BIT STRING, INTEGER size, INTEGER priv }`.
|
||||
pub fn private_key_from_tomcrypt(der: &[u8]) -> Result<EccKeyPrivP256, String> {
|
||||
let mut i = 0;
|
||||
let (tag, seq) = tlv(der, &mut i).ok_or("truncated DER")?;
|
||||
if tag != 0x30 || i != der.len() {
|
||||
return Err("expected a single DER SEQUENCE".into());
|
||||
}
|
||||
let mut j = 0;
|
||||
let mut items = Vec::new();
|
||||
while j < seq.len() {
|
||||
items.push(tlv(seq, &mut j).ok_or("truncated DER element")?);
|
||||
}
|
||||
let (bt, bits) = *items.first().ok_or("empty sequence")?;
|
||||
if bt != 0x03 || bits.len() < 2 {
|
||||
return Err("expected BIT STRING".into());
|
||||
}
|
||||
let bit_count = (bits.len() - 1) * 8 - bits[0] as usize;
|
||||
if bits[1] & 0x80 == 0 {
|
||||
return Err("key has no private part".into());
|
||||
}
|
||||
let priv_index = match bit_count {
|
||||
1 => 4,
|
||||
2 => 2,
|
||||
_ => return Err(format!("unexpected flag bit count {bit_count}")),
|
||||
};
|
||||
let (it, int) = *items.get(priv_index).ok_or("missing private INTEGER")?;
|
||||
if it != 0x02 {
|
||||
return Err("expected INTEGER".into());
|
||||
}
|
||||
let digits: &[u8] = {
|
||||
let first_nonzero = int.iter().position(|b| *b != 0).unwrap_or(int.len());
|
||||
&int[first_nonzero..]
|
||||
};
|
||||
if digits.len() > 32 {
|
||||
return Err("private scalar longer than 32 bytes".into());
|
||||
}
|
||||
let mut short = [0u8; 32];
|
||||
short[32 - digits.len()..].copy_from_slice(digits);
|
||||
EccKeyPrivP256::from_short(&short).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
/// Base64 libtomcrypt key as stored in `identity.json` (`EccKeyPrivP256::to_ts` output).
|
||||
pub fn private_key_from_ts(b64: &str) -> Result<EccKeyPrivP256, String> {
|
||||
let der = BASE64_STANDARD.decode(b64).map_err(|e| format!("not base64: {e}"))?;
|
||||
private_key_from_tomcrypt(&der)
|
||||
}
|
||||
|
||||
/// Reverse of `EccKeyPrivP256::to_ts_obfuscated`.
|
||||
fn deobfuscate(b64: &str) -> Result<String, String> {
|
||||
let mut data = BASE64_STANDARD.decode(b64).map_err(|e| format!("not base64: {e}"))?;
|
||||
if data.len() < 20 {
|
||||
return Err("obfuscated key too short".into());
|
||||
}
|
||||
let pos = data[20..].iter().position(|b| *b == 0).unwrap_or(data.len() - 20);
|
||||
let hash = Sha1::digest(&data[20..20 + pos]);
|
||||
for (d, h) in data.iter_mut().zip(hash.iter()).take(20) {
|
||||
*d ^= h;
|
||||
}
|
||||
for (d, m) in data.iter_mut().zip(IDENTITY_OBFUSCATION.iter()).take(100) {
|
||||
*d ^= m;
|
||||
}
|
||||
String::from_utf8(data).map_err(|_| "deobfuscated key is not text".into())
|
||||
}
|
||||
|
||||
/// TeamSpeak identity string `<offset>V<key>` where `<key>` is the obfuscated form (TS client
|
||||
/// exports) or plain base64 libtomcrypt DER.
|
||||
pub fn identity_from_ts_str(value: &str) -> Result<Identity, String> {
|
||||
let (counter, key) = value.split_once('V').ok_or("missing 'V' separator")?;
|
||||
let counter: u64 = counter.parse().map_err(|_| "invalid key offset")?;
|
||||
let key = private_key_from_ts(key)
|
||||
.or_else(|plain_err| deobfuscate(key).and_then(|t| private_key_from_ts(&t)).map_err(|e| format!("{e} (as plain key: {plain_err})")))?;
|
||||
Ok(Identity::new(key, counter))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
use super::*;
|
||||
|
||||
/// A key whose private scalar starts with 0x00 (expected after ~256 draws).
|
||||
pub fn zero_leading_key() -> EccKeyPrivP256 {
|
||||
for _ in 0..100_000 {
|
||||
let k = EccKeyPrivP256::create();
|
||||
if k.to_short()[0] == 0 {
|
||||
return k;
|
||||
}
|
||||
}
|
||||
panic!("no zero-leading key found");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zero_leading_scalar_roundtrips_where_upstream_fails() {
|
||||
let k = zero_leading_key();
|
||||
let ts = k.to_ts();
|
||||
assert!(EccKeyPrivP256::from_ts(&ts).is_err(), "upstream bug fixed? then this workaround can go");
|
||||
let back = private_key_from_ts(&ts).unwrap();
|
||||
assert_eq!(back.to_short(), k.to_short());
|
||||
let id = identity_from_ts_str(&format!("42V{}", k.to_ts_obfuscated())).unwrap();
|
||||
assert_eq!(id.key().to_short(), k.to_short());
|
||||
assert_eq!(id.counter(), 42);
|
||||
let plain = identity_from_ts_str(&format!("7V{ts}")).unwrap();
|
||||
assert_eq!(plain.key().to_short(), k.to_short());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn many_random_keys_roundtrip() {
|
||||
for _ in 0..2000 {
|
||||
let k = EccKeyPrivP256::create();
|
||||
assert_eq!(private_key_from_ts(&k.to_ts()).unwrap().to_short(), k.to_short());
|
||||
let id = identity_from_ts_str(&format!("1V{}", k.to_ts_obfuscated())).unwrap();
|
||||
assert_eq!(id.key().to_short(), k.to_short());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn upstream_test_vector_and_garbage() {
|
||||
// Vector from tsproto's own tests (TS client identity), UID known.
|
||||
const KEY: &str = "MG8DAgeAAgEgAiEA6rtKxDn/o/Bo50rNtAE5Ph3h2RKLHQ0gbFkvm2yA79kCIQCrfzAZts/vHP+3MOetKLjNnpZXt4c6U3UB4gWLKR4H9AIgYTyJofmztcTBjq3KZcDdxu+G4RPVwE5vg8VaN2jbQao=";
|
||||
let k = private_key_from_ts(KEY).unwrap();
|
||||
assert_eq!(k.to_pub().get_uid(), "test/9PZ9vww/Bpf5vJxtJhpz80=");
|
||||
for bad in ["", "AAAA", "MAA=", "not base64!"] {
|
||||
assert!(private_key_from_ts(bad).is_err(), "{bad}");
|
||||
}
|
||||
assert!(identity_from_ts_str("xVabc").is_err());
|
||||
assert!(identity_from_ts_str("1Vgarbage").is_err());
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
//! Contract: `docs/bridge.md`.
|
||||
|
||||
mod audio;
|
||||
mod keyfmt;
|
||||
mod media;
|
||||
mod profile;
|
||||
mod protocol;
|
||||
|
||||
+19
-2
@@ -132,7 +132,7 @@ impl Store {
|
||||
if file.version != FORMAT_VERSION {
|
||||
return Err(self.corrupt_identity(format!("unsupported version {}", file.version)));
|
||||
}
|
||||
let key = EccKeyPrivP256::from_ts(&file.private_key)
|
||||
let key = crate::keyfmt::private_key_from_ts(&file.private_key)
|
||||
.map_err(|e| self.corrupt_identity(format!("invalid private key: {e}")))?;
|
||||
let uid = uid_of(&key);
|
||||
if uid != file.uid {
|
||||
@@ -254,7 +254,7 @@ impl Store {
|
||||
}
|
||||
}
|
||||
let value = identity_value.ok_or_else(|| StoreError::ImportInvalid("no identity= entry".into()))?;
|
||||
let identity = Identity::new_from_ts_str(&value)
|
||||
let identity = crate::keyfmt::identity_from_ts_str(&value)
|
||||
.map_err(|e| StoreError::ImportInvalid(format!("cannot decode identity: {e}")))?;
|
||||
let nickname = match nickname {
|
||||
Some(n) => Some(validate_nickname(&n)?),
|
||||
@@ -386,6 +386,23 @@ pub mod tests {
|
||||
assert!(matches!(store.load_nickname(), Err(StoreError::ProfileCorrupt { .. })));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zero_leading_private_key_loads_and_imports() {
|
||||
let dir = TempDir::new("zerolead");
|
||||
let store = Store::new(&dir.0);
|
||||
let key = crate::keyfmt::tests::zero_leading_key();
|
||||
let mut identity = Identity::new(key, 0);
|
||||
identity.upgrade_level(NEW_IDENTITY_LEVEL);
|
||||
let uid = store.write_identity(&identity).unwrap();
|
||||
store.save_nickname("ZeroLead").unwrap();
|
||||
let loaded = store.load_identity().unwrap().unwrap();
|
||||
assert_eq!(loaded.uid, uid);
|
||||
assert_eq!(loaded.identity.key().to_short(), identity.key().to_short());
|
||||
let (ini, _) = store.export_ts_ini().unwrap();
|
||||
let other = TempDir::new("zerolead-import");
|
||||
assert_eq!(Store::new(&other.0).import_ts_ini(&ini, false).unwrap(), uid);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn upgraded_key_offset_keeps_uid() {
|
||||
let dir = TempDir::new("upgrade");
|
||||
|
||||
@@ -100,3 +100,21 @@ are always off. `client_user_tag`, which carries a signed myTS token, is never l
|
||||
Hardening item, not applied: vendored `tsclientlib/src/lib.rs` `warn!(message = ?msg, "Expected
|
||||
initserver, dropping command")` would Debug-print a whole command if one arrived before
|
||||
`initserver` during connect (not observed live). Proposed fix: log only the command name.
|
||||
|
||||
## 0.1.2: private keys with a leading zero byte (bug found and fixed)
|
||||
- Found by running the unit tests concurrently (6×80): about 3% of runs failed with
|
||||
`identity_corrupt: invalid private key: Failed to parse short private key` on freshly created
|
||||
identities.
|
||||
- Cause: upstream `EccKeyPrivP256::from_tomcrypt` (tsproto-types) passes the DER integer's
|
||||
minimal bytes to `from_short`, which requires 32 bytes. A scalar starting with `0x00`
|
||||
(~1 in 256 keys) is written by `to_ts` but cannot be read back. The same applies to
|
||||
`Identity::new_from_ts_str` (ini import). Affected users would have had a permanently refused
|
||||
identity (the core never regenerates).
|
||||
- Fix (`core/src/keyfmt.rs`): the core parses the libtomcrypt DER itself and left-pads the scalar
|
||||
to 32 bytes; the import path de-obfuscates (same constant as tsproto-types) and then parses
|
||||
the same way. The stored format is unchanged, so already-written affected files now load.
|
||||
- Tests: a zero-leading key round-trips (and is asserted to still fail upstream); 2000 random keys
|
||||
round-trip as plain DER and obfuscated; profile write → load → export → import with a
|
||||
zero-leading key; upstream test vector. 37 unit + 3 smoke pass. Concurrent stress
|
||||
6×40: 0 failures. Release `0.1.2`: 8984064 bytes, SHA256
|
||||
`db045fc505db09854a4f0495340acf56cec60f1ba0f2f67212fe7f7a36b2106e`, imports only system DLLs.
|
||||
@@ -33,6 +33,8 @@ async function launch(label) {
|
||||
}
|
||||
const state = (page) => page.evaluate(() => ({
|
||||
audio: window.teamspeachDiagnostics.snapshot().audio,
|
||||
capturing: window.teamspeachDiagnostics.snapshot().voice.capturing,
|
||||
framesSent: window.teamspeachDiagnostics.snapshot().voice.framesSent,
|
||||
menu: Boolean(document.querySelector('.device-menu')),
|
||||
items: Array.from(document.querySelectorAll('.device-menu [role="menuitemradio"]')).map((i) => ({ label: i.textContent, checked: i.getAttribute('aria-checked') })),
|
||||
focused: document.activeElement?.id || document.activeElement?.className || '',
|
||||
@@ -52,7 +54,7 @@ try {
|
||||
await page.click('#btn-mute', { button: 'right' });
|
||||
await page.waitForSelector('.device-menu');
|
||||
let s = await state(page);
|
||||
step('mic right-click', { menu: s.menu, inputMuted: s.audio.input_muted, items: s.items, insideViewport: s.inside, focused: s.focused });
|
||||
step('mic right-click', { menu: s.menu, inputMuted: s.audio.input_muted, capturing: s.capturing, framesSent: s.framesSent, items: s.items, insideViewport: s.inside, focused: s.focused });
|
||||
if (s.audio.input_muted) throw new Error('right-click toggled mute');
|
||||
await page.screenshot({ path: path.join(out, '62-mic-device-menu.png') });
|
||||
const pick = s.items[Math.min(2, s.items.length - 1)].label;
|
||||
|
||||
@@ -45,7 +45,8 @@ const readSelects = (page) => page.evaluate(() => {
|
||||
inputValueIsDevice: Boolean(document.querySelector('#input-device').value),
|
||||
outputValueIsDevice: Boolean(document.querySelector('#output-device').value),
|
||||
status: document.querySelector('#device-status').textContent,
|
||||
capturing: window.teamspeachDiagnostics.snapshot().voice.framesSent,
|
||||
framesSent: window.teamspeachDiagnostics.snapshot().voice.framesSent,
|
||||
capturing: window.teamspeachDiagnostics.snapshot().voice.capturing,
|
||||
conn: window.teamspeachDiagnostics.snapshot().conn,
|
||||
toasts: Array.from(document.querySelectorAll('.toast[data-kind="error"]')).map((t) => t.textContent),
|
||||
};
|
||||
@@ -64,7 +65,7 @@ try {
|
||||
await page.click('#settings-nav .nav-item[data-panel="audio"]');
|
||||
await page.waitForFunction(() => document.querySelector('#device-status').textContent.length > 0, null, { timeout: 10000 });
|
||||
let s = await readSelects(page);
|
||||
step('listed without capture', { inputs: s.inputs.length - 1, outputs: s.outputs.length - 1, inputLabels: s.inputs.map((o) => o.label), outputLabels: s.outputs.map((o) => o.label), status: s.status, conn: s.conn, framesSent: s.capturing });
|
||||
step('listed without capture', { inputs: s.inputs.length - 1, outputs: s.outputs.length - 1, inputLabels: s.inputs.map((o) => o.label), outputLabels: s.outputs.map((o) => o.label), status: s.status, conn: s.conn, framesSent: s.framesSent, capturing: s.capturing });
|
||||
await page.screenshot({ path: path.join(out, '60-audio-devices-listed.png') });
|
||||
if (s.inputs.length < 2 || s.outputs.length < 2) throw new Error('no physical devices listed');
|
||||
|
||||
@@ -75,7 +76,7 @@ try {
|
||||
await page.selectOption('#output-device', { label: outputChoice });
|
||||
await page.waitForTimeout(1000);
|
||||
s = await readSelects(page);
|
||||
step('selected', { inputChoice, outputChoice, toasts: s.toasts, framesSent: s.capturing });
|
||||
step('selected', { inputChoice, outputChoice, toasts: s.toasts, framesSent: s.framesSent, capturing: s.capturing });
|
||||
await app.close();
|
||||
|
||||
({ app, page } = await launch('run2'));
|
||||
|
||||
Reference in new issue
Block a user