v0.0.21: TUI overhaul, WZP call infrastructure, security hardening, federation

TUI:
- Split 1,756-line app.rs monolith into 7 modules (types, draw, commands, input, file_transfer, network, mod)
- Message timestamps [HH:MM], scrolling (PageUp/Down/arrows), connection status dot, unread badge
- /help command, terminal bell on incoming DM, /devices + /kick commands
- 44 unit tests (types, input, draw with TestBackend)

Server — WZP Call Infrastructure (FC-2/3/5/6/7/10):
- Call state management (CallState, CallStatus, active_calls, calls + missed_calls sled trees)
- WS call signal awareness (Offer/Answer/Hangup update state, missed call on offline)
- Group call endpoint (POST /groups/:name/call with SHA-256 room ID, fan-out)
- Presence API (GET /presence/:fp, POST /presence/batch)
- Missed call flush on WS reconnect
- WZP relay config + CORS

Server — Security (FC-P1):
- Auth enforcement middleware (AuthFingerprint extractor on 13 write handlers)
- Session auto-recovery (delete corrupted ratchet, show [session reset])
- WS connection cap (5/fingerprint) + global concurrency limit (200)
- Device management (GET /devices, POST /devices/:id/kick, POST /devices/revoke-all)

Server — Federation:
- Two-server federation via JSON config (--federation flag)
- Periodic presence sync (every 5s, full-state, self-healing)
- Message forwarding via HTTP POST with SHA-256(secret||body) auth
- Graceful degradation (peer down = queue locally)
- deliver_or_queue() replaces push-or-queue in ws.rs + messages.rs

Client — Group Messaging:
- SenderKeyDistribution storage + GroupSenderKey decryption in TUI
- sender_keys sled tree in LocalDb

WASM:
- All 8 WireMessage variants handled (no more "unsupported")
- decrypt_group_message() + create_sender_key_from_distribution() exports
- CallSignal parsing with signal_type mapping

Docs:
- ARCHITECTURE.md rewritten with Mermaid diagrams
- README.md created
- TASK_PLAN.md with FC-P{phase}-T{task} naming
- PROGRESS.md updated to v0.0.21

WZP submodule updated to 6f4e8eb (IAX2 trunking, adaptive quality, metrics, all S-tasks done)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Siavash Sameni
2026-03-28 16:45:58 +04:00
parent 4a4fa9fab4
commit 3e0889e5dc
36 changed files with 5237 additions and 2232 deletions

View File

@@ -474,10 +474,144 @@ pub fn decrypt_wire_message(
"data": hex::encode(&data),
}).to_string())
}
_ => {
WireMessage::SenderKeyDistribution {
sender_fingerprint,
group_name,
chain_key,
generation,
} => {
// Return the distribution data so JS can store it
Ok(serde_json::json!({
"type": "unsupported",
"type": "sender_key_distribution",
"sender": sender_fingerprint,
"group": group_name,
"chain_key": hex::encode(chain_key),
"generation": generation,
}).to_string())
}
WireMessage::GroupSenderKey {
id,
sender_fingerprint,
group_name,
generation,
counter,
ciphertext,
} => {
// Return the encrypted group message data so JS can decrypt with stored sender key
// JS must call a separate decrypt function with the sender key
Ok(serde_json::json!({
"type": "group_message",
"id": id,
"sender": sender_fingerprint,
"group": group_name,
"generation": generation,
"counter": counter,
"ciphertext": hex::encode(&ciphertext),
}).to_string())
}
WireMessage::CallSignal {
id,
sender_fingerprint,
signal_type,
payload,
target,
} => {
let type_str = match signal_type {
warzone_protocol::message::CallSignalType::Offer => "offer",
warzone_protocol::message::CallSignalType::Answer => "answer",
warzone_protocol::message::CallSignalType::IceCandidate => "ice_candidate",
warzone_protocol::message::CallSignalType::Hangup => "hangup",
warzone_protocol::message::CallSignalType::Reject => "reject",
warzone_protocol::message::CallSignalType::Ringing => "ringing",
warzone_protocol::message::CallSignalType::Busy => "busy",
};
Ok(serde_json::json!({
"type": "call_signal",
"id": id,
"sender": sender_fingerprint,
"signal_type": type_str,
"payload": payload,
"target": target,
}).to_string())
}
}
}
/// Decrypt a group message using a stored sender key.
///
/// Arguments:
/// - sender_key_hex: hex-encoded bincode-serialized SenderKey (from sender_key_distribution)
/// - sender_fingerprint, group_name, generation, counter, ciphertext_hex: from the group_message JSON
///
/// Returns JSON: { "text": "...", "sender_key": "updated_hex" }
#[wasm_bindgen]
pub fn decrypt_group_message(
sender_key_hex: &str,
sender_fingerprint: &str,
group_name: &str,
generation: u32,
counter: u32,
ciphertext_hex: &str,
) -> Result<String, JsValue> {
use warzone_protocol::sender_keys::{SenderKey, SenderKeyMessage};
let key_bytes = hex::decode(sender_key_hex)
.map_err(|e| JsValue::from_str(&format!("invalid sender key hex: {}", e)))?;
let mut sender_key: SenderKey = bincode::deserialize(&key_bytes)
.map_err(|e| JsValue::from_str(&format!("deserialize sender key: {}", e)))?;
let ciphertext = hex::decode(ciphertext_hex)
.map_err(|e| JsValue::from_str(&format!("invalid ciphertext hex: {}", e)))?;
let msg = SenderKeyMessage {
sender_fingerprint: sender_fingerprint.to_string(),
group_name: group_name.to_string(),
generation,
counter,
ciphertext,
};
let plaintext = sender_key.decrypt(&msg)
.map_err(|e| JsValue::from_str(&format!("decrypt: {}", e)))?;
// Return updated sender key (counter advanced) so JS can persist it
let updated_key = bincode::serialize(&sender_key).unwrap_or_default();
Ok(serde_json::json!({
"text": String::from_utf8_lossy(&plaintext),
"sender_key": hex::encode(updated_key),
}).to_string())
}
/// Create a sender key from a distribution message.
///
/// Takes the fields from a sender_key_distribution JSON and returns
/// a hex-encoded bincode SenderKey that JS should store.
#[wasm_bindgen]
pub fn create_sender_key_from_distribution(
sender_fingerprint: &str,
group_name: &str,
chain_key_hex: &str,
generation: u32,
) -> Result<String, JsValue> {
use warzone_protocol::sender_keys::SenderKeyDistribution;
let chain_key_bytes = hex::decode(chain_key_hex)
.map_err(|e| JsValue::from_str(&format!("invalid chain key hex: {}", e)))?;
let mut chain_key = [0u8; 32];
if chain_key_bytes.len() != 32 {
return Err(JsValue::from_str("chain key must be 32 bytes"));
}
chain_key.copy_from_slice(&chain_key_bytes);
let dist = SenderKeyDistribution {
sender_fingerprint: sender_fingerprint.to_string(),
group_name: group_name.to_string(),
chain_key,
generation,
};
let sender_key = dist.into_sender_key();
let encoded = bincode::serialize(&sender_key).unwrap_or_default();
Ok(hex::encode(encoded))
}