- FastAPI backend with JWT authentication - ElGamal, RSA-PSS, ZK-proofs crypto modules - HTML5/JS frontend SPA - MariaDB database with 5 tables - Docker Compose with 3 services (frontend, backend, mariadb) - Comprehensive tests for cryptography - Typst technical report (30+ pages) - Makefile with development commands
235 lines
9.6 KiB
Markdown
235 lines
9.6 KiB
Markdown
# Architecture Technique
|
|
|
|
## Vue Générale
|
|
|
|
```
|
|
┌─────────────────────────────────────────────────────────────┐
|
|
│ Frontend Web │
|
|
│ (HTML5 + JavaScript Vanilla) │
|
|
│ Port 3000 │
|
|
└────────────────────┬────────────────────────────────────────┘
|
|
│
|
|
│ HTTP/HTTPS
|
|
│
|
|
┌────────────────────▼────────────────────────────────────────┐
|
|
│ Backend API │
|
|
│ (FastAPI + Python 3.12) │
|
|
│ Port 8000 │
|
|
│ ┌──────────────────────────────────────────────────────┐ │
|
|
│ │ Routes │ │
|
|
│ │ - /api/auth (register, login, profile) │ │
|
|
│ │ - /api/elections (active, results) │ │
|
|
│ │ - /api/votes (submit, status) │ │
|
|
│ └──────────────────────────────────────────────────────┘ │
|
|
│ │
|
|
│ ┌──────────────────────────────────────────────────────┐ │
|
|
│ │ Services │ │
|
|
│ │ - VoterService │ │
|
|
│ │ - ElectionService │ │
|
|
│ │ - VoteService │ │
|
|
│ └──────────────────────────────────────────────────────┘ │
|
|
│ │
|
|
│ ┌──────────────────────────────────────────────────────┐ │
|
|
│ │ Cryptography Module │ │
|
|
│ │ - ElGamalEncryption │ │
|
|
│ │ - DigitalSignature (RSA-PSS) │ │
|
|
│ │ - ZKProofs (Fiat-Shamir) │ │
|
|
│ │ - SecureHash (SHA-256) │ │
|
|
│ └──────────────────────────────────────────────────────┘ │
|
|
└────────────────────┬────────────────────────────────────────┘
|
|
│
|
|
│ TCP 3306 (MySQL)
|
|
│
|
|
┌────────────────────▼────────────────────────────────────────┐
|
|
│ MariaDB Database │
|
|
│ Port 3306 │
|
|
│ ┌──────────────────────────────────────────────────────┐ │
|
|
│ │ Tables │ │
|
|
│ │ - voters (électeurs) │ │
|
|
│ │ - elections (scrutins) │ │
|
|
│ │ - candidates (candidats) │ │
|
|
│ │ - votes (bulletins chiffrés) │ │
|
|
│ │ - audit_logs (journal d'audit) │ │
|
|
│ └──────────────────────────────────────────────────────┘ │
|
|
└──────────────────────────────────────────────────────────────┘
|
|
```
|
|
|
|
## Flux de Données
|
|
|
|
### 1. Inscription
|
|
|
|
```
|
|
Frontend Backend Database
|
|
│ │ │
|
|
│ POST /auth/register ──────>│ │
|
|
│ │ Hash(password) │
|
|
│ │ Gen KeyPair(voter) │
|
|
│ │ INSERT voter ───────────>│
|
|
│ │ │
|
|
│<────────── 200 OK ────────│ │
|
|
```
|
|
|
|
### 2. Authentification
|
|
|
|
```
|
|
Frontend Backend Database
|
|
│ │ │
|
|
│ POST /auth/login ────────>│ │
|
|
│ (email, password) │ GET voter ─────────────>│
|
|
│ │<────── voter ──────────│
|
|
│ │ Compare(hash, pass) │
|
|
│ │ Gen JWT Token │
|
|
│<─── 200 + Token ──────────│ │
|
|
```
|
|
|
|
### 3. Vote
|
|
|
|
```
|
|
Frontend Backend Database
|
|
│ │ │
|
|
│ ElGamal Encrypt(vote) │ │
|
|
│ Gen ZK Proof │ │
|
|
│ │ │
|
|
│ POST /votes/submit ──────>│ │
|
|
│ (encrypted_vote, proof) │ Verify JWT │
|
|
│ │ Verify ZK Proof │
|
|
│ │ Hash Bulletin │
|
|
│ │ INSERT vote ──────────>│
|
|
│ │<── vote_id ───────────│
|
|
│<─ 200 + ballot_hash ──────│ │
|
|
```
|
|
|
|
### 4. Résultats
|
|
|
|
```
|
|
Frontend Backend Database
|
|
│ │ │
|
|
│ GET /elections/X/results >│ │
|
|
│ │ SELECT votes ─────────>│
|
|
│ │<── encrypted_votes ───│
|
|
│ │ Sum(encrypted) via │
|
|
│ │ homomorphic property │
|
|
│ │ Decrypt(sum) │
|
|
│ │ Compute percentages │
|
|
│<─── 200 + results ────────│ │
|
|
```
|
|
|
|
## Sécurité des Données
|
|
|
|
### En Transit
|
|
|
|
- Votes chiffrés avec ElGamal avant transmission
|
|
- Authentification JWT (Bearer Token)
|
|
- HTTPS en production
|
|
|
|
### Au Repos
|
|
|
|
- Votes stockés chiffrés
|
|
- Mots de passe hashés avec bcrypt
|
|
- Base de données avec accès contrôlé
|
|
|
|
### Audit
|
|
|
|
- Journal de tous les accès (audit_logs)
|
|
- Traçabilité IP/timestamp
|
|
- Verification des preuves cryptographiques
|
|
|
|
## Scalabilité
|
|
|
|
### Horizontal
|
|
|
|
```
|
|
Load Balancer
|
|
│
|
|
├─ Backend 1 ─┐
|
|
├─ Backend 2 ├─ Shared MariaDB
|
|
└─ Backend 3 ─┘
|
|
```
|
|
|
|
### Vertical
|
|
|
|
- Augmenter les resources des conteneurs
|
|
- Connection pooling BD
|
|
- Caching Redis (optionnel)
|
|
|
|
## Déploiement
|
|
|
|
### Docker Compose (Développement)
|
|
|
|
```yaml
|
|
services:
|
|
frontend: port 3000
|
|
backend: port 8000
|
|
mariadb: port 3306
|
|
```
|
|
|
|
### Kubernetes (Production)
|
|
|
|
```
|
|
Ingress
|
|
│
|
|
├─ Frontend Deployment
|
|
├─ Backend Deployment (3 replicas)
|
|
└─ MariaDB StatefulSet
|
|
```
|
|
|
|
### Conteneurisation
|
|
|
|
```dockerfile
|
|
# Backend
|
|
FROM python:3.12-slim
|
|
RUN pip install poetry
|
|
COPY pyproject.toml .
|
|
RUN poetry install --no-dev
|
|
COPY src/ ./
|
|
CMD ["uvicorn", "backend.main:app"]
|
|
|
|
# Frontend
|
|
FROM node:20-alpine
|
|
COPY src/frontend/ .
|
|
CMD ["http-server", ".", "-p", "3000"]
|
|
```
|
|
|
|
## Performance
|
|
|
|
### Benchmarks Typiques (Prototype)
|
|
|
|
| Opération | Temps |
|
|
|-----------|-------|
|
|
| ElGamal Encrypt | ~10ms |
|
|
| ElGamal Decrypt | ~5ms |
|
|
| RSA Sign | ~50ms |
|
|
| ZK Proof Gen | ~20ms |
|
|
| Vote Submission | ~100ms |
|
|
| Results Calc | ~500ms (1000 votes) |
|
|
|
|
### Optimisations
|
|
|
|
1. **Chiffrement** : Pré-calcul des exponentiations
|
|
2. **BD** : Indexes sur (voter_id, election_id)
|
|
3. **API** : Pagination des résultats
|
|
4. **Frontend** : Compression, caching
|
|
5. **Backend** : Connection pooling, async I/O
|
|
|
|
## Monitoring
|
|
|
|
### Métriques
|
|
|
|
- Taux d'erreur API
|
|
- Latence des requêtes
|
|
- Utilisation CPU/Mémoire
|
|
- Taille de la BD
|
|
|
|
### Logs
|
|
|
|
- Application : stderr/stdout
|
|
- Accès : access.log
|
|
- Audit : audit_logs table
|
|
|
|
### Alertes
|
|
|
|
- Erreur de vote
|
|
- Tentative de double vote
|
|
- Échecde validation ZK
|
|
- Anomalies d'accès
|