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
100 lines
3.1 KiB
Python
100 lines
3.1 KiB
Python
"""Camera and Recording API routes."""
|
|
|
|
import os
|
|
from flask import Blueprint, jsonify, request
|
|
|
|
|
|
def create_cameras_blueprint(server_config):
|
|
"""
|
|
Create the cameras API blueprint.
|
|
|
|
Args:
|
|
server_config: Dict with keys:
|
|
- image_dir: Camera images directory
|
|
- c2_root: C2 root directory path
|
|
- get_camera_receiver: Callable returning camera receiver
|
|
- require_api_auth: Auth decorator
|
|
"""
|
|
bp = Blueprint("api_cameras", __name__, url_prefix="/api")
|
|
|
|
image_dir = server_config["image_dir"]
|
|
c2_root = server_config["c2_root"]
|
|
get_receiver = server_config["get_camera_receiver"]
|
|
require_api_auth = server_config["require_api_auth"]
|
|
|
|
# ========== Camera List ==========
|
|
|
|
@bp.route("/cameras")
|
|
@require_api_auth
|
|
def list_cameras():
|
|
full_image_dir = os.path.join(c2_root, image_dir)
|
|
try:
|
|
cameras = [
|
|
f.replace(".jpg", "")
|
|
for f in os.listdir(full_image_dir)
|
|
if f.endswith(".jpg")
|
|
]
|
|
except FileNotFoundError:
|
|
cameras = []
|
|
|
|
receiver = get_receiver()
|
|
result = {"cameras": [], "count": len(cameras)}
|
|
|
|
for cam_id in cameras:
|
|
cam_info = {"id": cam_id, "recording": False}
|
|
if receiver:
|
|
status = receiver.get_recording_status(cam_id)
|
|
cam_info["recording"] = status.get("recording", False)
|
|
cam_info["filename"] = status.get("filename")
|
|
result["cameras"].append(cam_info)
|
|
|
|
result["count"] = len(result["cameras"])
|
|
return jsonify(result)
|
|
|
|
# ========== Recording Control ==========
|
|
|
|
@bp.route("/recording/start/<camera_id>", methods=["POST"])
|
|
@require_api_auth
|
|
def start_recording(camera_id):
|
|
receiver = get_receiver()
|
|
if not receiver:
|
|
return jsonify({"error": "Camera receiver not available"}), 503
|
|
|
|
result = receiver.start_recording(camera_id)
|
|
if "error" in result:
|
|
return jsonify(result), 400
|
|
return jsonify(result)
|
|
|
|
@bp.route("/recording/stop/<camera_id>", methods=["POST"])
|
|
@require_api_auth
|
|
def stop_recording(camera_id):
|
|
receiver = get_receiver()
|
|
if not receiver:
|
|
return jsonify({"error": "Camera receiver not available"}), 503
|
|
|
|
result = receiver.stop_recording(camera_id)
|
|
if "error" in result:
|
|
return jsonify(result), 400
|
|
return jsonify(result)
|
|
|
|
@bp.route("/recording/status")
|
|
@require_api_auth
|
|
def recording_status():
|
|
receiver = get_receiver()
|
|
if not receiver:
|
|
return jsonify({"error": "Camera receiver not available"}), 503
|
|
|
|
camera_id = request.args.get("camera_id")
|
|
return jsonify(receiver.get_recording_status(camera_id))
|
|
|
|
@bp.route("/recordings")
|
|
@require_api_auth
|
|
def list_recordings():
|
|
receiver = get_receiver()
|
|
if not receiver:
|
|
return jsonify({"recordings": []})
|
|
|
|
return jsonify({"recordings": receiver.list_recordings()})
|
|
|
|
return bp
|