
Legion è un fabric di autenticazione Zero-Knowledge progettato per la privacy.
Autenticazione Zero-Knowledge reale con firme ad anello dei dispositivi legate all'hardware
Legion è un sistema di autenticazione zero-knowledge senza password che dimostra che sei autorizzato senza rivelare chi sei.
Autenticati usando solo la tua impronta digitale + frase di recupero di 24 parole (come MetaMask). Niente nomi utente, niente password, niente segreti lato server.
git clone https://github.com/deadends/legion.git cd legion
chmod +x scripts/install.sh && ./scripts/install.sh
scripts\install.bat
**Tutto qui!** Apri http://localhost nel tuo browser.
### Cosa viene installato
- ✅ Redis (archiviazione sessioni)
- ✅ Legion Server (verificatore di prove ZK)
- ✅ Frontend (client WASM)
- ✅ Nginx (reverse proxy)
**Prestazioni**: Registrazione ~5s, Autenticazione ~2min (generazione della prova k=14)
---
### Configurazione manuale (senza Docker)
<details>
<summary>Clicca per espandere l'installazione manuale</summary>```bash
# 1. Install Redis
# macOS: brew install redis && redis-server
# Ubuntu: sudo apt install redis && redis-server
# Windows: https://redis.io/docs/install/install-redis/install-redis-on-windows/
# 2. Run server (terminal 1)
cd legion-server
cargo run --release --features redis
# 3. Build frontend (terminal 2)
cd wasm-client
wasm-pack build --target web --release
python3 -m http.server 8000
# 4. Open http://localhost:8000
Per il deployment in produzione, vedi DEPLOYMENT.md
Hardware di Test: Lenovo IdeaPad 3 - Intel Core i3 11th Gen
Nota: Le prestazioni possono variare in base alle specifiche hardware.
Dettaglio:
Dettaglio:
Importante: La generazione dei parametri e il keygen sono costi una tantum che possono essere memorizzati nella cache. Una volta in cache, la verifica richiede solo ~108-967ms a seconda del valore di k. L'implementazione attuale non memorizza ancora i parametri nella cache.
Perché più lento dei vecchi benchmark? Il circuito passwordless ora verifica DUE Merkle tree (utente + dispositivo) invece di uno, fornendo un vero anonimato a livello di dispositivo (1 dispositivo su 1024 per utente).
📖 Per un flusso di autenticazione dettagliato passo-passo con dettagli crittografici, vedi ARCHITECTURE_FLOW.md
┌─────────────────────────────────────────────────────────────────────────┐ │ CLIENT (Browser + WASM) │ ├─────────────────────────────────────────────────────────────────────────┤ │ ┌────────────────┐ ┌─────────────────┐ ┌──────────────────────────┐ │ │ │ UI Layer │ │ WASM Prover │ │ Local Storage │ │ │ │ (Vanilla JS) │ │ (Rust→WASM) │ │ (IndexedDB) │ │ │ ├────────────────┤ ├─────────────────┤ ├──────────────────────────┤ │ │ │ • Registration │ │ • Blake3 Hash │ │ • Full Merkle Tree │ │ │ │ • Login Form │ │ • BIP-39 Derive │ │ • Device Trees │ │ │ │ • Session UI │ │ • Halo2 Prover │ │ • WebAuthn Credentials │ │ │ │ • Tree Sync │ │ • Merkle Proof │ │ • Tree Version Cache │ │ │ └────────────────┘ │ • Ring Sigs │ └──────────────────────────┘ │ │ └─────────────────┘ │ │ ┌──────────────────────────────────────────────────────────────────┐ │ │ │ Hardware Security (WebAuthn Level 2) │ │ │ ├──────────────────────────────────────────────────────────────────┤ │ │ │ • TPM 2.0 / Secure Enclave • FIDO2 Authenticator │ │ │ │ • Device Private Key (ECDSA) • Biometric/Touch Required │ │ │ └──────────────────────────────────────────────────────────────────┘ │ └────────────────────────────────┬────────────────────────────────────────┘ │ HTTPS/TLS 1.3 │ (Encrypted Channel) ▼ ┌──────────────────────────────────────────────────────────────────────────┐ │ LEGION SERVER (Rust/Axum) │ ├──────────────────────────────────────────────────────────────────────────┤ │ ┌─────────────────────────────────────────────────────────────────┐ │ │ │ API Layer (Axum) │ │ │ ├─────────────────────────────────────────────────────────────────┤ │ │ │ POST /api/register-blind │ Blind registration │ │ │ │ GET /api/download-tree │ Download full Merkle tree │ │ │ │ POST /api/verify-anonymous-proof │ Verify ZK proof │ │ │ │ POST /api/verify-session │ Session validation │ │ │ │ POST /api/webauthn/* │ WebAuthn endpoints │ │ │ │ GET /health │ Health check │ │ │ └─────────────────────────────────────────────────────────────────┘ │ │ │ │ │ ┌─────────────────────────────────────────────────────────────────┐ │ │ │ Business Logic Layer │ │ │ ├─────────────────────────────────────────────────────────────────┤ │ │ │ • Blind Registration │ • Tree Synchronization │ │ │ │ • ZK Proof Verifier │ • Nullifier Tracker (replay) │ │ │ │ • Session Manager │ • Linkability Tag Validator │ │ │ │ • WebAuthn Service │ • Timestamp Validator (±10min) │ │ │ │ • Device Revocation │ • Rate Limiter (5/hour) │ │ │ └─────────────────────────────────────────────────────────────────┘ │ │ │ │ │ ┌─────────────────────────────────────────────────────────────────┐ │ │ │ Cryptographic Layer │ │ │ ├─────────────────────────────────────────────────────────────────┤ │ │ │ • Halo2 Verifier (PLONK) │ • Poseidon Hash (ZK-friendly) │ │ │ │ • Blake3 (credential) │ • BIP-39 (recovery phrase) │ │ │ │ • Merkle Tree (2^20) │ • Device Trees (2^10 per user) │ │ │ │ • Ring Signature Verify │ • WebAuthn Signature Verify │ │ │ └─────────────────────────────────────────────────────────────────┘ │ └────────────────────────┬──────────────────────┬──────────────────────────┘ │ │ ▼ ▼ ┌────────────────────────┐ ┌───────────────────────────┐ │ Redis (In-Memory) │ │ RocksDB (Persistent) │ ├────────────────────────┤ ├───────────────────────────┤ │ • Session Tokens │ │ • Merkle Tree Leaves │ │ • Linkability Tags │ │ • Device Trees │ │ • Spent Nullifiers │ │ • Nullifier History │ │ • Rate Limit Counters │ │ • WebAuthn Credentials │ │ TTL: 1 hour │ │ • Revoked Devices │ └────────────────────────┘ └───────────────────────────┘
### Flusso di autenticazione (semplificato)```
┌─────────────┐ ┌──────────────┐
│ Client │ │ Server │
│ (Browser) │ │ (Verifier) │
└──────┬──────┘ └──────┬───────┘
│ │
│ 1. Generate 24-word recovery phrase (BIP-39) │
│ → 256-bit entropy (like MetaMask) │
│ → User writes down on paper │
│ │
│ 2. Derive account_id from phrase (Blake3) │
│ account_id = Blake3("LEGION_ACCOUNT_V2" || bip39_seed) │
│ → Deterministic, no server interaction │
│ │
│ 3. Hash account_id for tree leaf (Poseidon) │
│ credential_hash = Poseidon(account_id) │
│ │
│ 4. Blind registration (TRUE zero-knowledge) ────►│
│ → Sends ONLY credential_hash (no phrase/identity) │
│ → Server adds to tree, returns tree_index │
│ ◄────│ {tree_index: 114}
│ │
│ 5. Download full Merkle tree (one-time sync) ────►│
│ → Client stores entire tree in IndexedDB │
│ → Enables TRUE zero-knowledge (no server queries) │
│ ◄────│ {tree_data: [all leaves],
│ │ merkle_root, version}
│ │
│ 6. Generate WebAuthn key (TPM/Secure Enclave) │
│ → Fingerprint prompt creates hardware-bound key │
│ → device_pubkey (ECDSA P-256, non-exportable) │
│ → Stored in TPM 2.0 / Secure Enclave │
│ │
│ 7. Register device in device tree ────►│
│ → device_commitment = Blake3(credential_id) │
│ → Server converts to valid field element if needed │
│ → Server adds to user's device tree (1 of 1024 slots) │
│ ◄────│ {device_position: 0,
│ │ device_tree_root}
│ │
│ 8. LOGIN: Touch fingerprint to authenticate │
│ → WebAuthn verifies hardware-bound key │
│ → Decrypts recovery phrase from local storage │
│ → Re-derives account_id from phrase │
│ │
│ 9. Fetch device Merkle proof ────►│
│ → Sends account_id (derived from phrase) │
│ → Server returns device tree path │
│ ◄────│ {device_path: [siblings],
│ │ device_root}
│ │
│ 10. Compute user Merkle proof CLIENT-SIDE │
│ → Uses local tree from IndexedDB │
│ → Computes path for tree_index │
│ → Server NEVER learns which user! │
│ │
│ 11. Compute nullifier (replay protection) │
│ nullifier = Poseidon(account_id || challenge) │
│ → ONE-TIME USE: Different every login │
│ → Prevents proof replay attacks │
│ │
│ 12. Compute linkability tag (session binding) │
│ linkability_tag = Blake3(device_pubkey || nullifier) │
│ ⚠️ Binds session to specific device+user │
│ │
│ 13. Generate ZK proof (Halo2 PLONK, ~2min for k=14) │
│ Proves in zero-knowledge: │
│ ✓ User exists in Merkle tree (1 of 2^20) │
│ ✓ Device exists in device tree (1 of 2^10) │
│ ✓ account_id hashes to credential_hash │
│ ✓ Nullifier computed correctly │
│ ✓ Timestamp is fresh │
│ WITHOUT revealing which user or device │
│ │
│ 14. Submit proof ────►│
│ {proof, public_inputs, linkability_tag, k=14} │
│ │ • Check device not revoked
│ │ • Verify timestamp (±10min)
│ │ • Rate limit check (5/hour)
│ │ • Check nullifier (replay?)
│ │ • Verify ZK proof (~115s)
│ │ • Mark nullifier as used
│ │
│ ◄────│ {session_token, expires_at}
│ │
│ 15. Verify session (every request) ────►│
│ {session_token, linkability_tag} │
│ │ • Lookup in Redis
│ │ • Verify linkability_tag
│ │ (prevents session theft)
│ │ • Check not spent
│ ◄────│ {valid: true}
│ │
🔍 Vuoi maggiori dettagli? Vedi ARCHITECTURE_FLOW.md per:
┌─────────────────────────────────────────────────────────────────────────┐ │ SESSION SECURITY MECHANISMS │ ├─────────────────────────────────────────────────────────────────────────┤ │ │ │ 1. LINKABILITY TAG (Zero-Knowledge Device Binding) │ │ ═══════════════════════════════════════════════════════ │ │ │ │ linkability_tag = Blake3(device_pubkey || nullifier) │ │ │ │ • Computed client-side using hardware-bound device key │ │ • Sent with every session validation request │ │ • Server verifies: stored_tag == provided_tag │ │ │ │ ✅ PREVENTS: Session token theft/replay on different device │ │ ✅ ENSURES: Same user + same device for entire session │ │ ✅ MAINTAINS: Zero-knowledge (server doesn't learn identity) │ │ │ │ ───────────────────────────────────────────────────────────────── │ │ │ │ 2. SESSION TOKEN (Cryptographic Binding) │ │ ═══════════════════════════════════════════════════════ │ │ │ │ session_token = Poseidon(nullifier || timestamp || linkability_tag) │ │ │ │ • Generated server-side after proof verification │ │ • Stored in Redis with linkability_tag as value │ │ • Cannot be forged without knowing nullifier │ │ │ │ ✅ PREVENTS: Token forgery │ │ ✅ ENSURES: Cryptographic binding to proof │ │ │ │ ───────────────────────────────────────────────────────────────── │ │ │ │ 3. NULLIFIER (Replay Protection) │ │ ═══════════════════════════════════════════════════════ │ │ │ │ nullifier = Poseidon(credential_hash || challenge) │ │ │ │ • Unique per authentication attempt │ │ • Tracked in RocksDB (permanent) and Redis (cache) │ │ • Server rejects if nullifier seen before │ │ │ │ ✅ PREVENTS: Proof replay attacks │ │ ✅ ENSURES: One-time use per challenge │ │ │ │ ───────────────────────────────────────────────────────────────── │ │ │ │ 4. TIMESTAMP VALIDATION (Time-Bound Security) │ │ ═══════════════════════════════════════════════════════ │ │ │ │ • Proof includes timestamp (Unix epoch) │ │ • Server validates: |proof_time - server_time| < 5 minutes │ │ • Session TTL: 1 hour (sliding window) │ │ │ │ ✅ PREVENTS: Old proof replay │ │ ✅ ENSURES: Fresh authentication │ │ │ │ ───────────────────────────────────────────────────────────────── │ │ │ │ 5. CHALLENGE-RESPONSE (Freshness Guarantee) │ │ ═══════════════════════════════════════════════════════ │ │ │ │ • Server generates random 32-byte challenge │ │ • Stored in Redis with 5-minute TTL │ │ • Client must include in proof │ │ • Server verifies challenge matches and deletes │ │ │ │ ✅ PREVENTS: Pre-computed proof attacks │ │ ✅ ENSURES: Proof generated for this specific session │ │ │ └─────────────────────────────────────────────────────────────────────────┘
## 🔐 Proprietà Zero-Knowledge
### Cosa sa il server
- ✅ Qualcuno nel set di anonimato si è autenticato
- ✅ La prova è crittograficamente valida
- ✅ Stesso utente+dispositivo tramite tag di collegabilità
- ✅ Stato del rate limit (tentativi rimanenti)
- ✅ Stato di revoca del dispositivo
- ✅ Numero totale di utenti registrati
- ✅ Radice dell'albero di Merkle (pubblica)
### Cosa il server NON può sapere
- ❌ Quale utente specifico (1 su 1M)
- ❌ Quale dispositivo specifico (1 su 1K per utente)
- ❌ Frase di recupero (seed BIP-39)
- ❌ account_id (derivato dalla frase)
- ❌ Chiave privata del dispositivo (in TPM/Secure Enclave)
- ❌ Quale foglia dell'albero appartiene a quale utente
- ❌ Percorso Merkle dell'utente (calcolato lato client)
- ❌ Posizione tree_index dell'utente
## 📦 Distribuzione
Vedi [DEPLOYMENT.md](https://github.com/deadends/legion/blob/HEAD/docs/DEPLOYMENT.md) per la guida dettagliata alla distribuzione in produzione.
### Distribuzione rapida con Docker```bash
# Production build
docker-compose -f deployment/docker-compose.yml up -d
# Check logs
docker-compose -f deployment/docker-compose.yml logs -f legion-server
# Check health
curl http://localhost/health
RUST_LOG=info LEGION_DATA_PATH=/var/lib/legion/data REDIS_URL=redis://127.0.0.1:6379
## 🧪 Test```bash
# Run all tests
cargo test --workspace
# Run with Redis features
cargo test --workspace --features redis
# Benchmark
cargo bench
Contributi benvenuti! Leggi prima CONTRIBUTING.md.
git checkout -b feature/amazing)git commit -m 'Add amazing feature')git push origin feature/amazing)Hai trovato un problema di sicurezza? Consulta SECURITY.md per la divulgazione responsabile.
NON aprire issue pubbliche per le vulnerabilità.
Licenza MIT - consulta il file LICENSE per i dettagli.
Modifiche principali:
Architettura:
Modifiche principali:
Aggiunte:
Correzioni di sicurezza:
Realizzato con ❤️ per privacy e sicurezza
| Proprietà | Garanzia |
|---|
| Autenticazione | Senza password (BIP-39 + impronta digitale) |
| Anonimato dell'utente | 1 su 2^20 (1.048.576) |
| Anonimato del dispositivo | 1 su 2^10 (1.024) per utente |
| Errore di solidità | 2^-128 |
| Sistema di prova | Halo2 PLONK (setup trasparente) |
| Derivazione delle credenziali | Blake3 (seed BIP-39) |
| Binding hardware | WebAuthn Level 2 (TPM/Secure Enclave) |
| Multi-dispositivo | Massimo 2 dispositivi per account |
| Limitazione delle richieste | 5 tentativi/ora |
| Revoca dei dispositivi | Blacklist istantanea |
| Livello di Sicurezza | k | Tempo di Prova | Dimensione della Prova | Caso d'Uso |
|---|
| Sviluppo | 12 | ~30s | 3.2 KB | Test |
| Produzione | 14 | ~2min | 3.4 KB | Consigliato |
| Metrica | Valore | Note |
|---|
| Dimensione della Prova | 3.264 byte | 3,19 KB compressi |
| Input Pubblici | 10 | Radice User tree, radice Device tree, nullifier, ecc. |
| Generazione dei Parametri | 7.03s | Configurazione una tantum per valore di k |
| Creazione del Circuito | 2.3µs | Overhead trascurabile |
| Generazione della Chiave di Verifica | 1.29s | Keygen una tantum |
| Verifica della Prova | 107.7ms | Controllo effettivo della prova ZK |
| Verifica Totale | 8.43s | End-to-end (senza caching) |
| Metrica | Valore | Note |
|---|
| Dimensione della Prova | 3.392 byte | 3,31 KB compressi |
| Input Pubblici | 10 | Radice User tree, radice Device tree, nullifier, ecc. |
| Generazione dei Parametri | 100.78s | Configurazione una tantum per valore di k |
| Creazione del Circuito | 5µs | Overhead trascurabile |
| Generazione della Chiave di Verifica | 12.89s | Keygen una tantum |
| Verifica della Prova | 967.2ms | Controllo effettivo della prova ZK |
| Verifica Totale | 114.65s | End-to-end (senza caching) |