真正的零知识认证,采用硬件绑定的设备环签名
Legion 是一个零知识认证系统,它能在不泄露你的身份的情况下证明你已获得授权。 你基于公开数据证明某些事情,而不会将你当前的操作关联回你的公开地址。
| 属性 | 保证 |
|---|---|
| 用户匿名性 | 2^20 中的 1(1,048,576) |
| 设备匿名性 | 2^10 中的 1(1,024) |
| 可靠性误差 | 2^-128 |
| 证明系统 | Halo2 PLONK |
| 密码哈希 | Argon2id |
| 硬件绑定 | WebAuthn Level 2 |
| 速率限制 | 每小时 5 次尝试 |
| 设备吊销 | 即时黑名单 |
# Clone and run
git clone https://github.com/deadends/legion.git
cd legion
# Linux/macOS
chmod +x install.sh && ./install.sh
# Windows
install.bat
就这样! 在浏览器中打开 http://localhost。
性能:注册约 10 秒,认证约 4 分钟(k=16 证明生成)
# 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
对于生产环境部署,请参阅 DEPLOYMENT.md
| 安全级别 | k | 证明时间 | 证明大小 | 使用场景 |
|---|---|---|---|---|
| 测试 | 12 | ~10秒 | 2.5 KB | 开发 |
| 标准 | 14 | ~60秒 | 3.0 KB | 预发布 |
| 生产 | 16 | ~4分钟 | 3.5 KB | 推荐 |
| 高安全 | 18 | ~15分钟 | 4.0 KB | 企业 |
📖 有关包含加密细节的详细分步身份验证流程,请参阅 ARCHITECTURE_FLOW.md
┌──────────────────────────────────────────────────────────────────────────┐
│ CLIENT (Browser) │
├──────────────────────────────────────────────────────────────────────────┤
│ ┌────────────────┐ ┌─────────────────┐ ┌──────────────────────────┐ │
│ │ UI Layer │ │ WASM Module │ │ Hardware Security │ │
│ │ (Vanilla JS) │ │ (Rust→WASM) │ │ (WebAuthn Level 2) │ │
│ ├────────────────┤ ├─────────────────┤ ├──────────────────────────┤ │
│ │ • Registration │ │ • Blake3 Hash │ │ • TPM 2.0 │ │
│ │ • Login Form │ │ • Argon2id KDF │ │ • Secure Enclave │ │
│ │ • Session UI │ │ • Halo2 Prover │ │ • FIDO2 Authenticator │ │
│ │ • Error Handle │ │ • Merkle Proof │ │ • Device Private Key │ │
│ └────────────────┘ └─────────────────┘ └──────────────────────────┘ │
└────────────────────────────────┬─────────────────────────────────────────┘
│ HTTPS/TLS 1.3
│ (Encrypted Channel)
▼
┌──────────────────────────────────────────────────────────────────────────┐
│ REVERSE PROXY (Nginx) │
├──────────────────────────────────────────────────────────────────────────┤
│ • TLS Termination • Rate Limiting (100 req/min) │
│ • Load Balancing • Request Logging │
│ • Static File Serving • Security Headers (CSP, HSTS) │
└────────────────────────────────┬─────────────────────────────────────────┘
│ HTTP (Internal Network)
▼
┌──────────────────────────────────────────────────────────────────────────┐
│ LEGION SERVER (Rust/Axum) │
├──────────────────────────────────────────────────────────────────────────┤
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ API Layer (Axum) │ │
│ ├─────────────────────────────────────────────────────────────────┤ │
│ │ POST /register │ POST /auth/challenge │ POST /auth/verify│ │
│ │ POST /auth/session │ GET /health │ POST /logout │ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ Business Logic Layer │ │
│ ├─────────────────────────────────────────────────────────────────┤ │
│ │ • Credential Manager │ • Challenge Generator (32-byte random)│ │
│ │ • Merkle Tree Builder │ • Nullifier Tracker (replay protection)│ │
│ │ • ZK Proof Verifier │ • Session Manager (linkability tags) │ │
│ │ • Device Tree Manager │ • Timestamp Validator (±5min window) │ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ Cryptographic Layer │ │
│ ├─────────────────────────────────────────────────────────────────┤ │
│ │ • Halo2 Verifier (PLONK) │ • Poseidon Hash (ZK-friendly) │ │
│ │ • Blake3 (credential hash)│ • Argon2id (password KDF) │ │
│ │ • Merkle Tree (2^20 users)│ • Device Tree (2^10 devices/user) │ │
│ └─────────────────────────────────────────────────────────────────┘ │
└────────────────────────┬──────────────────────┬──────────────────────────┘
│ │
▼ ▼
┌────────────────────────┐ ┌───────────────────────────┐
│ Redis (In-Memory) │ │ RocksDB (Persistent) │
├────────────────────────┤ ├───────────────────────────┤
│ • Session Tokens │ │ • User Credentials │
│ • Linkability Tags │ │ • Merkle Tree Nodes │
│ • Active Challenges │ │ • Device Trees │
│ • Nullifier Cache │ │ • Nullifier History │
│ TTL: 1 hour │ │ Persistent Storage │
└────────────────────────┘ └───────────────────────────┘