Crypto: - Replace broken ChaCha20 (static nonce) with ChaCha20-Poly1305 AEAD - HKDF-SHA256 key derivation from per-device factory NVS master keys - Random 12-byte nonce per message (ESP32 hardware RNG) - crypto_init/encrypt/decrypt API with mbedtls legacy (ESP-IDF v5.3.2) - Custom partition table with factory NVS (fctry at 0x10000) Firmware: - crypto.c full rewrite, messages.c device_id prefix + AEAD encrypt - crypto_init() at boot with esp_restart() on failure - Fix command_t initializations across all modules (sub/help fields) - Clean CMakeLists dependencies for ESP-IDF v5.3.2 C3PO (C2): - Rename tools/c2 + tools/c3po -> tools/C3PO - Per-device CryptoContext with HKDF key derivation - KeyStore (keys.json) for master key management - Transport parses device_id:base64(...) wire format Tools: - New tools/provisioning/provision.py for factory NVS key generation - Updated flasher with mbedtls config for v5.3.2 Docs: - Update all READMEs for new crypto, C3PO paths, provisioning - Update roadmap, architecture diagrams, security sections - Update CONTRIBUTING.md project structure
60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
"""Stats API routes."""
|
|
|
|
import os
|
|
from flask import Blueprint, jsonify
|
|
|
|
|
|
def create_stats_blueprint(server_config):
|
|
"""
|
|
Create the stats API blueprint.
|
|
|
|
Args:
|
|
server_config: Dict with keys:
|
|
- image_dir: Camera images directory
|
|
- c2_root: C2 root directory path
|
|
- get_device_registry: Callable returning device registry
|
|
- get_mlat_engine: Callable returning MLAT engine
|
|
- require_api_auth: Auth decorator
|
|
"""
|
|
bp = Blueprint("api_stats", __name__, url_prefix="/api")
|
|
|
|
image_dir = server_config["image_dir"]
|
|
c2_root = server_config["c2_root"]
|
|
get_registry = server_config["get_device_registry"]
|
|
get_mlat = server_config["get_mlat_engine"]
|
|
require_api_auth = server_config["require_api_auth"]
|
|
|
|
@bp.route("/stats")
|
|
@require_api_auth
|
|
def stats():
|
|
"""Get server statistics."""
|
|
full_image_dir = os.path.join(c2_root, image_dir)
|
|
|
|
# Camera count
|
|
try:
|
|
camera_count = len([
|
|
f for f in os.listdir(full_image_dir)
|
|
if f.endswith(".jpg")
|
|
])
|
|
except FileNotFoundError:
|
|
camera_count = 0
|
|
|
|
# Device count
|
|
device_count = 0
|
|
registry = get_registry()
|
|
if registry:
|
|
device_count = len(list(registry.all()))
|
|
|
|
# MLAT state
|
|
mlat_engine = get_mlat()
|
|
mlat_state = mlat_engine.get_state()
|
|
|
|
return jsonify({
|
|
"active_cameras": camera_count,
|
|
"connected_devices": device_count,
|
|
"multilateration_scanners": mlat_state["scanners_count"],
|
|
"server_running": True
|
|
})
|
|
|
|
return bp
|