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
35 lines
1023 B
Python
35 lines
1023 B
Python
import threading
|
|
|
|
|
|
class GroupRegistry:
|
|
def __init__(self):
|
|
self._groups: dict[str, set[str]] = {}
|
|
self._lock = threading.Lock()
|
|
|
|
def add_group(self, name: str):
|
|
with self._lock:
|
|
self._groups.setdefault(name, set())
|
|
|
|
def delete_group(self, name: str):
|
|
with self._lock:
|
|
self._groups.pop(name, None)
|
|
|
|
def add_device(self, group: str, esp_id: str):
|
|
with self._lock:
|
|
self._groups.setdefault(group, set()).add(esp_id)
|
|
|
|
def remove_device(self, group: str, esp_id: str):
|
|
with self._lock:
|
|
if group in self._groups:
|
|
self._groups[group].discard(esp_id)
|
|
if not self._groups[group]:
|
|
del self._groups[group]
|
|
|
|
def get(self, group: str) -> set[str]:
|
|
with self._lock:
|
|
return set(self._groups.get(group, []))
|
|
|
|
def all_groups(self) -> dict[str, set[str]]:
|
|
with self._lock:
|
|
return {k: set(v) for k, v in self._groups.items()}
|