Aller au contenu

PD-33 — Plan d'implémentation


📚 Navigation User Story | Document | | | ---------- | -- | | 📋 [Spécification](PD-33-specification.md) | | | 🛠️ **Plan d'implémentation** | *(ce document)* | | ✅ [Critères d'acceptation](PD-33-acceptability.md) | | | 📝 [Retour d'expérience](PD-33-rex.md) | | [← Retour à crypto](../PD-189-epic.md) · [↑ Index User Story](index.md)

Objectif

Implémenter la dérivation Argon2id conforme RFC 9106 pour transformer le mot de passe utilisateur en clés cryptographiques K_encryption et K_auth.

Choix techniques retenus

  • Bibliothèque : argon2-browser (bundle WASM)
  • Fallback Expo Go : PBKDF2 via crypto-js (DEV-ONLY)
  • Paramètres OWASP 2024 : t=3, m=64 MiB, p=4
  • Domain separation : Contextes distincts pour K_encryption et K_auth

Architecture ciblée

src/services/keyDerivation.ts
├── deriveEncryptionKey()     → K_encryption (chiffre K_master)
├── deriveSRPAuthKey()        → K_auth (authentification SRP)
├── generateSalt()            → Salt CSPRNG 16 bytes
└── Helpers (wipeKey, bytesToHex, hexToBytes)

Découpage technique

Phase 1 : Configuration Argon2id

  1. Définir interface Argon2Params avec paramètres OWASP
  2. Créer constantes DEFAULT_ARGON2_PARAMS et DEVICE_PARAMS
  3. Implémenter détection WebAssembly (isWebAssemblyAvailable())
  4. Implémenter détection Expo Go (isExpoGo())

Phase 2 : Fallback PBKDF2 (DEV-ONLY)

  1. Implémenter deriveKeyPBKDF2Fallback() via crypto-js
  2. Itérations adaptées : 10k (Expo Go) / 600k (prod impossible)
  3. Logs d'avertissement explicites (non-conformité PD-97)
  4. Bloquer en production si Argon2id indisponible

Phase 3 : Dérivation principale

  1. Implémenter deriveKeyInternal() avec validation input
  2. Import dynamique argon2-browser/dist/argon2-bundled.min.js
  3. Domain separation via secret (associated data)
  4. Wrapper deriveEncryptionKey() avec contexte ProbatioVault::Encryption::v1
  5. Wrapper deriveSRPAuthKey() avec contexte ProbatioVault::SRP_Auth::v1

Phase 4 : Utilitaires

  1. generateSalt() via expo-crypto (16 bytes CSPRNG)
  2. wipeKey() pour effacement mémoire (best effort)
  3. detectDeviceCapability() pour ajustement params (TODO)
  4. Conversions bytesToHex() / hexToBytes()

Phase 5 : Tests

  1. Tests unitaires conformité RFC 9106
  2. Tests vecteurs IETF officiels
  3. Tests performance (~500ms sur iPhone 12+)
  4. Tests rejet paramètres invalides

Points de vigilance

  • Expo Go : Pas de WebAssembly → fallback PBKDF2 en DEV uniquement
  • Production : Argon2id OBLIGATOIRE, erreur si indisponible
  • Password minimum : 12 caractères (prod), 4 (dev)
  • Memory leak : Appeler wipeKey() après usage
  • Strings immutables : Effacement password best-effort en JS

Hors périmètre

  • Stockage des clés dérivées (→ PD-98)
  • Intégration SRP complète (→ PD-24)
  • Dérivation K_doc (→ PD-34)