diff --git a/README.md b/README.md index c4cdd98..a9d5851 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,69 @@ # Sikrypt -Sikrypt est une API de cryptographie educative. Le backend (Rust/Axum) expose : +Sikrypt is a demonstration application focused on modern and educational cryptography. It combines a Rust backend API with a React/Vite web interface to explore encryption, hashing, signing, and secure communication algorithms. -- des endpoints modernes sous `/crypto/*` (base64 partout, rate limit, API key obligatoire) -- des endpoints pedagogiques pour apprendre les algorithmes classiques +## Overview -Un front React/Vite minimal est fourni pour tester l API. +The project has two main goals: -## Demarrage rapide +- provide a clear and testable API for learning cryptography through practice; +- offer an interactive interface to visualize operations and algorithm results. -### Pre-requis +## Main Features -- Rust stable -- Node.js 18+ (front) +### Modern API -### Lancer le backend +The API exposes routes under the /crypto prefix for more realistic and secure operations, including: + +- key generation: X25519, Ed25519, RSA; +- secure channel: X25519 + HKDF-SHA256 + AES-256-GCM; +- RSA-OAEP: encryption/decryption; +- Ed25519: signing/verification; +- RSA-PSS: signing/verification. + +### Educational Algorithms + +The backend also provides educational endpoints to discover classic algorithms and cryptography basics: + +- classic: Caesar, Vigenère, Hill, Playfair, Affine, OTP; +- symmetric: AES-CBC, DES-CBC, RC4; +- asymmetric: Diffie-Hellman, ElGamal, RSA; +- signatures: DSA, ECDSA, ElGamal, RSA PKCS#1 v1.5, RSA-PSS; +- hash: SHA-256, SHA-512, MD5, HMAC-SHA256; +- homomorphic: Paillier; +- secret sharing: Shamir; +- communications: secure channel and voting demos. + +### Web Interface + +The frontend provides a simple UI to test endpoints, inspect inputs and outputs, and try the secure WebSocket chat demo. + +## Repository Structure + +- backend/: Rust API (Axum), routes, models, algorithms, tests; +- front/: React/Vite web interface; +- docs/: architecture notes; +- docker-compose.yml: local stack orchestration; +- package.json: root-level validation scripts. + +## Prerequisites + +- Stable Rust; +- Node.js 18+; +- Docker Desktop (optional, for the full stack). + +## Quick Start + +### 1. Start the backend ```bash cd backend cargo run ``` -### Lancer le front +The backend listens by default on https://localhost:3000. + +### 2. Start the frontend ```bash cd front @@ -29,86 +71,98 @@ npm install npm run dev ``` -## Docker +The frontend is then available at http://localhost:5173. + +### 3. Start with Docker -Lance la stack complete avec: +From the project root: ```bash docker compose up --build ``` -- Backend: `https://localhost:3000` -- Front: `http://localhost:8080` -- API key: utilise `SIKRYPT_API_KEY` si tu veux remplacer la valeur par defaut `changeme` +- Backend: https://localhost:3000 +- Frontend: http://localhost:8080 -## Documentation +## Configuration -- OpenAPI JSON: `https://localhost:3000/openapi.json` -- Swagger UI: `https://localhost:3000/docs` +### Backend environment variables -## Config rapide +- SIKRYPT_HOST: listening host (default: 127.0.0.1); +- SIKRYPT_PORT: listening port (default: 3000); +- SIKRYPT_API_KEY: required key to protect /crypto routes; +- SIKRYPT_TLS_CERT_PATH and SIKRYPT_TLS_KEY_PATH: paths to a custom TLS certificate; +- SIKRYPT_REQUEST_TIMEOUT_MS: request timeout; +- SIKRYPT_CONCURRENCY_LIMIT: concurrency limit; +- SIKRYPT_CORS_ORIGINS: allowed CORS origins. -### Backend +### Frontend environment variables + +- VITE_API_BASE: API base URL used by the frontend (default: /api). -- `SIKRYPT_HOST` (defaut: `127.0.0.1`) -- `SIKRYPT_PORT` (defaut: `3000`) -- `SIKRYPT_API_KEY` (obligatoire, protege `/crypto/*`) -- `SIKRYPT_TLS_CERT_PATH` et `SIKRYPT_TLS_KEY_PATH` (optionnels, sinon un certificat auto-signe est genere) -- `SIKRYPT_REQUEST_TIMEOUT_MS` (defaut: `15000`) -- `SIKRYPT_CONCURRENCY_LIMIT` (defaut: `128`) -- `SIKRYPT_CORS_ORIGINS` (defaut: `http://localhost:5173,http://127.0.0.1:5173`) +> The SIKRYPT_API_KEY secret is not injected into the frontend bundle. It must be handled on the server or proxy side. -### Front +## API Documentation -- `VITE_API_BASE` (optionnel, defaut: `/api`) +When the backend is running, you can consult: -Le secret `SIKRYPT_API_KEY` n'est plus injecte dans le bundle front. Il est ajoute au niveau du proxy Nginx ou du proxy Vite en dev. +- OpenAPI JSON: https://localhost:3000/openapi.json +- Swagger UI: https://localhost:3000/docs + +## Quick Examples + +### Generate an X25519 key pair ```bash -VITE_API_BASE=/api +curl -k -s -X POST https://localhost:3000/crypto/keys/x25519 ``` -## Architecture rapide +### Encrypt a message with RSA-OAEP -- `backend/` : API Rust (Axum), routes, models, algorithms, tests -- `front/` : interface web minimale (React/Vite) -- `docs/` : notes d architecture +```bash +curl -k -s -X POST https://localhost:3000/crypto/rsa/oaep/encrypt \ + -H "content-type: application/json" \ + -d '{ + "public_key_pem": "", + "plaintext_base64": "", + "label_base64": "" + }' +``` -## Algorithmes (educatif) +### Test a classic algorithm -- Asymetriques: Diffie-Hellman, ECC (courbes jouets), ElGamal, RSA -- Signatures: DSA, ECDSA (courbe jouet), ElGamal, RSA-PSS, RSA-PKCS#1 v1.5 -- Hash: SHA-256, SHA-512, MD5, HMAC-SHA256 -- Symetriques: AES-CBC, DES-CBC, RC4 -- Classiques: Caesar, Vigenere, Hill, Playfair, Affine, OTP, Analyse -- Homomorphique: Paillier -- Secret sharing: Shamir -- Communications: Secure channel, Voting (demo) +```bash +curl -k -s -X POST https://localhost:3000/classic/caesar/encrypt \ + -H "content-type: application/json" \ + -d '{"text":"HELLO","shift":3}' +``` -## API moderne (/crypto) +## Tests -- Generation de cles: X25519, Ed25519, RSA -- Secure channel: X25519 + HKDF-SHA256 + AES-256-GCM -- RSA-OAEP (encrypt/decrypt) -- Ed25519 (sign/verify) -- RSA-PSS (sign/verify) +### Backend -## Tests +```bash +cargo test --manifest-path backend/Cargo.toml +``` + +### Frontend ```bash -cd backend -cargo test +npm --prefix front test ``` -## Lire les README detailles +### Global validation -- Backend: [backend/README.md](backend/README.md) -- Front: [front/README.md](front/README.md) +```bash +npm test +``` -## Limites educatives +## Important Notes -Les endpoints pedagogiques sont destines a l apprentissage et aux demonstrations. Ils ne visent pas un usage production. +- The /crypto routes require a valid API key. +- Binary data is typically transmitted as base64. +- Educational endpoints are intended for learning and demonstration, not for production use. -## Licence +## License -Voir `LICENSE`. +See the LICENSE file. diff --git a/backend/README.md b/backend/README.md deleted file mode 100644 index 1103224..0000000 --- a/backend/README.md +++ /dev/null @@ -1,206 +0,0 @@ -# Sikrypt Backend - -API de cryptographie educative ecrite en Rust (Axum). Le backend expose : - -- des endpoints modernes sous `/crypto/*` (base64 partout, rate limit, API key obligatoire) -- des endpoints pedagogiques pour apprendre les algorithmes classiques et les bases crypto - -Le front (dans `../front`) est volontairement minimal et sert de demo. -Le backend sert en HTTPS via `https://localhost:3000` par defaut, avec un certificat auto-signe genere au demarrage si aucun chemin PEM n'est fourni. - -## Objectifs - -- Offrir une base claire, testee et documentee pour l'apprentissage. -- Separer endpoints modernes et endpoints educatifs dans une meme API. - -## Organisation - -- `src/algorithms/` : implementations des algorithmes -- `src/routes/` : routes Axum par famille -- `src/models/` : schemas de requetes/reponses -- `tests/integration.rs` : tests d'integration HTTP - -## Groupes d'endpoints - -- Moderne: `/crypto/*` -- Educatif: `/asymmetric/*`, `/classic/*`, `/hash/*`, `/signature/*`, `/symmetric/*`, `/comms/*` - -## Demo de communication (WebSocket + comms) - -Le backend propose une demo de communication securisee: - -- WebSocket: `/ws/secure` -- Endpoints REST: `/comms/*` (canal securise, vote demo) - -Flux simplifie du chat securise (cote front): - -1. Echange des cles publiques RSA via WebSocket. -2. Chiffrement d'une cle AES avec la cle publique du peer. -3. Envoi de messages chiffres en AES-GCM. - -Ce flux est expose dans l'onglet "Secure Chat" du front. - -## Conventions API - -- Les donnees binaires sont en base64 (suffixe `_base64`). -- Reponses d'erreur (format commun): - -```json -{ "error": "code", "message": "message" } -``` - -## Securite et limites - -- API key obligatoire: `SIKRYPT_API_KEY` doit etre defini, et les routes `/crypto/*` exigent `x-api-key`. -- Rate limit: applique sur `/crypto/*` (par API key et par IP). -- Limite de taille du body: 64 KB (globale). - -## Demarrage rapide - -### Pre-requis - -- Rust stable - -### Lancer le serveur - -```bash -cd backend -cargo run -``` - -Le serveur ecoute par defaut sur `https://localhost:3000`. - -## Docker - -La stack Docker utilise le meme backend HTTPS avec un certificat auto-signe persisté dans un volume. - -```bash -docker compose up --build -``` - -- Backend: `https://localhost:3000` -- Front: `http://localhost:8080` -- API key: `SIKRYPT_API_KEY` est definie dans `docker-compose.yml` et peut etre surchargee via l'environnement - -### Variables d'environnement - -- `SIKRYPT_HOST` (defaut: `127.0.0.1`) -- `SIKRYPT_PORT` (defaut: `3000`) -- `SIKRYPT_API_KEY` (obligatoire, protege `/crypto/*`) -- `SIKRYPT_TLS_CERT_PATH` et `SIKRYPT_TLS_KEY_PATH` (optionnels, sinon un certificat auto-signe est genere) -- `SIKRYPT_REQUEST_TIMEOUT_MS` (defaut: `15000`) -- `SIKRYPT_CONCURRENCY_LIMIT` (defaut: `128`) -- `SIKRYPT_CORS_ORIGINS` (defaut: `http://localhost:5173,http://127.0.0.1:5173`) - -## Docs API - -- OpenAPI JSON: `https://localhost:3000/openapi.json` -- Swagger UI: `https://localhost:3000/docs` - -## Exemples cURL (moderne) - -### Generer une paire X25519 - -```bash -curl -k -s -X POST https://localhost:3000/crypto/keys/x25519 -``` - -### Secure channel: chiffrer - -```bash -curl -k -s -X POST https://localhost:3000/crypto/secure-channel/encrypt \ - -H "content-type: application/json" \ - -d '{ - "sender_private_key_base64": "", - "receiver_public_key_base64": "", - "plaintext_base64": "", - "aad_base64": "" - }' -``` - -### Secure channel: dechiffrer - -```bash -curl -k -s -X POST https://localhost:3000/crypto/secure-channel/decrypt \ - -H "content-type: application/json" \ - -d '{ - "receiver_private_key_base64": "", - "sender_public_key_base64": "", - "salt_base64": "", - "nonce_base64": "", - "ciphertext_base64": "", - "aad_base64": "" - }' -``` - -### RSA OAEP: chiffrer - -```bash -curl -k -s -X POST https://localhost:3000/crypto/rsa/oaep/encrypt \ - -H "content-type: application/json" \ - -d '{ - "public_key_pem": "", - "plaintext_base64": "", - "label_base64": "" - }' -``` - -### Ed25519: signer/verifier - -```bash -curl -k -s -X POST https://localhost:3000/crypto/ed25519/sign \ - -H "content-type: application/json" \ - -d '{ - "private_key_base64": "", - "message_base64": "" - }' -``` - -```bash -curl -k -s -X POST https://localhost:3000/crypto/ed25519/verify \ - -H "content-type: application/json" \ - -d '{ - "public_key_base64": "", - "message_base64": "", - "signature_base64": "" - }' -``` - -## Exemples cURL (educatif) - -### Caesar (encrypt) - -```bash -curl -k -s -X POST https://localhost:3000/classic/caesar/encrypt \ - -H "content-type: application/json" \ - -d '{ "text": "HELLO", "shift": 3 }' -``` - -### Vigenere (estimate key length) - -```bash -curl -k -s -X POST https://localhost:3000/classic/vigenere/estimate-key-length \ - -H "content-type: application/json" \ - -d '{ "text": "ATTACKATDAWN", "max_key_len": 12 }' -``` - -### HMAC SHA-256 - -```bash -curl -k -s -X POST https://localhost:3000/hash/hmac \ - -H "content-type: application/json" \ - -d '{ - "key_base64": "", - "message_base64": "" - }' -``` - -## Tests - -```bash -cargo test -``` - -## Notes educatives - -Les endpoints educatifs sont destines a l'apprentissage et aux demonstrations. Ils ne visent pas un usage production. diff --git a/front/README.md b/front/README.md deleted file mode 100644 index 494b254..0000000 --- a/front/README.md +++ /dev/null @@ -1,74 +0,0 @@ -# Sikrypt Front - -Interface web pour tester et expliquer les algorithmes cryptographiques exposes par le backend. -Le front est un client Vite + React qui consomme l'API REST et la demo WebSocket. - -## Objectifs - -- Fournir une UI simple pour manipuler les endpoints educatifs et modernes. -- Rendre visibles les entrees/sorties (JSON, base64, hex) pour l'apprentissage. -- Proposer une demo de communication securisee via WebSocket. - -## Fonctionnalites principales - -- Classiques: Caesar, Vigenere, Affine, Playfair, Hill, OTP -- Symetriques: RC4, DES, AES, Rijndael, Twofish, Serpent, RC6 -- Asymetriques: RSA-OAEP, Diffie-Hellman, ElGamal, ECDH P-256 -- Signatures: RSA-PSS, RSA PKCS#1 v1.5, DSA, ECDSA, ElGamal -- Hash: MD5, SHA-256, SHA-512, HMAC-SHA256 -- Secure Chat: demo de communication avec negotiation de cle et chiffrement - -## Prerequis - -- Node.js 18+ - -## Demarrage rapide - -```bash -cd front -npm install -npm run dev -``` - -Le front est accessible sur `http://127.0.0.1:5173`. - -## Docker - -Le front peut etre servi via Nginx dans la stack Docker racine. - -```bash -docker compose up --build -``` - -Il sera accessible sur `http://localhost:8080` et pointera vers le backend en `https://localhost:3000`. - -## Configuration - -Le front parle au backend via un proxy local sur `/api` et `/ws/secure`. -En mode dev, Vite relaie les requetes vers `https://localhost:3000`. -En Docker, Nginx fait le relais vers le service backend. - -La seule variable utile au front est: - -- `VITE_API_BASE` (optionnelle, defaut: `/api`) - -Le secret `SIKRYPT_API_KEY` reste cote serveur/proxy et n'est plus injecte dans le bundle React. -En local, exporte `SIKRYPT_API_KEY` avant de lancer `npm run dev` pour que le proxy Vite ajoute bien l'en-tete. - -## Demo communication securisee - -Le panneau "Secure Chat" fait une demo WebSocket: - -- Connexion a `wss:///ws/secure` -- Le front utilise le meme chemin `/ws/secure`, proxifie en dev et en Docker -- Echange de cles RSA (partage de cle publique) -- Chiffrement d'une cle AES avec RSA -- Chiffrement des messages en AES-GCM - -Assure-toi que le backend est lance avant d'ouvrir cette section. - -## Notes - -- Les champs `*_base64` attendent du base64 valide. -- Les champs `*_hex` attendent de l'hex (longueur paire). -- Les entrees sont volontairement simples pour la lisibilite.