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
58 lines
2.3 KiB
Python
58 lines
2.3 KiB
Python
from utils.utils import _print_status
|
|
from tools.c2.utils.constant import _color
|
|
|
|
def add_to_group(c2, group_name, client_address):
|
|
if group_name not in c2.groups:
|
|
c2.groups[group_name] = []
|
|
|
|
ip_address = client_address[0]
|
|
|
|
if ip_address not in c2.groups[group_name]:
|
|
c2.groups[group_name].append(ip_address)
|
|
_print_status(f"Client {ip_address} ajouté au groupe {group_name}", "GREEN")
|
|
else:
|
|
_print_status(f"Client {ip_address} est déjà dans le groupe {group_name}", "YELLOW", "!")
|
|
|
|
def list_groups(c2):
|
|
if c2.groups:
|
|
print(f"\n{_color('CYAN')}Groupes disponibles :{_color('RESET')}")
|
|
for group_name, members in c2.groups.items():
|
|
print(f"{group_name}: {', '.join(members)}")
|
|
else:
|
|
_print_status("Aucun groupe disponible", "RED", "⚠")
|
|
|
|
def remove_group(c2, group_name):
|
|
if group_name in c2.groups:
|
|
del c2.groups[group_name]
|
|
_print_status(f"Groupe {group_name} supprimé", "GREEN")
|
|
else:
|
|
_print_status(f"Groupe {group_name} non trouvé", "RED", "⚠")
|
|
|
|
def remove_esp_from_group(c2, group_name, esp_list):
|
|
if group_name not in c2.groups:
|
|
_print_status(f"Groupe {group_name} non trouvé", "RED", "⚠")
|
|
return
|
|
|
|
for esp in esp_list:
|
|
try:
|
|
index = int(esp) - 1
|
|
if 0 <= index < len(c2.clients):
|
|
client_ip = list(c2.clients.keys())[index][0]
|
|
if client_ip in c2.groups[group_name]:
|
|
c2.groups[group_name].remove(client_ip)
|
|
_print_status(f"Client {client_ip} retiré du groupe {group_name}", "GREEN")
|
|
else:
|
|
_print_status(f"Client {client_ip} n'est pas dans le groupe {group_name}", "RED", "⚠")
|
|
else:
|
|
_print_status(f"Index client {esp} invalide", "RED", "⚠")
|
|
except ValueError:
|
|
if esp in c2.groups[group_name]:
|
|
c2.groups[group_name].remove(esp)
|
|
_print_status(f"Client {esp} retiré du groupe {group_name}", "GREEN")
|
|
else:
|
|
_print_status(f"Client {esp} n'est pas dans le groupe {group_name}", "RED", "⚠")
|
|
|
|
if group_name in c2.groups and not c2.groups[group_name]:
|
|
del c2.groups[group_name]
|
|
_print_status(f"Groupe {group_name} supprimé car vide", "YELLOW", "!")
|