PD-36 — Plan d'implémentation¶
📚 Navigation User Story
| Document | | | ---------- | -- | | 📋 [Spécification](PD-36-specification.md) | | | 🛠️ **Plan d'implémentation** | *(ce document)* | | ✅ [Critères d'acceptation](PD-36-acceptability.md) | | | 📝 [Retour d'expérience](PD-36-rex.md) | | [← Retour à crypto-proof](../PD-189-epic.md) · [↑ Index User Story](index.md)Objectif¶
Implémenter un client HSM Cloud compatible PKCS#11 pour les opérations cryptographiques sensibles.
Choix techniques retenus¶
- HSM : AWS CloudHSM (FIPS 140-2 Level 3)
- Interface : PKCS#11 via pkcs11js
- Connectivité : VPN Site-to-Site OVH ↔ AWS
- Lifecycle : NestJS OnModuleInit/OnModuleDestroy
Architecture ciblée¶
src/modules/crypto/hsm/
├── hsm.module.ts # Module NestJS
├── hsm.service.ts # Service principal
├── hsm.config.ts # Configuration
├── interfaces/
│ └── pkcs11.interface.ts # Types PKCS#11
└── providers/
├── cloudhsm-pkcs11.provider.ts # Provider réel
└── pkcs11-mock.provider.ts # Mock pour tests
Découpage technique¶
Phase 1 : Configuration¶
- Définir variables d'environnement :
CLOUDHSM_LIBRARY_PATHCLOUDHSM_PINCLOUDHSM_SLOTCLOUDHSM_USERCLOUDHSM_SESSION_TIMEOUT-
CLOUDHSM_MAX_SESSIONS -
Créer
HsmConfigavec validation
Phase 2 : Interfaces PKCS#11¶
- Définir types :
IPkcs11SessionKeyAttributesSignatureAlgorithmSignatureResultVerificationResultKeyType(ECDSA_P256, RSA_4096)
Phase 3 : Provider CloudHSM¶
CloudHsmPkcs11Provider:initialize(): Charger libcloudhsm_pkcs11.socreateSession(): Ouvrir session slot-
finalize(): Fermer proprement -
CloudHsmPkcs11Operations: sign(data, keyLabel, algorithm)verify(data, signature, keyLabel, algorithm)generateKeyPair(keyType, attributes)findKey(label)deleteKey(label)listKeys()
Phase 4 : HSM Service¶
- Lifecycle NestJS :
onModuleInit(): Initialize provider-
onModuleDestroy(): Finalize provider -
Méthodes publiques :
sign(),verify()generateKeyPair()findKey(),listKeys()isEnabled(),isSessionActive()
Phase 5 : Gestion certificats¶
createCsr(subject, keyLabel):- Générer CSR avec clé HSM
-
Retourner PEM
-
storeCertificate(cert, keyLabel): - Importer certificat signé
-
Lier à la clé
-
getCertificate(keyLabel): - Récupérer certificat DER
Phase 6 : mTLS¶
buildMtlsAgent(config):- Créer https.Agent avec cert HSM
- Signature déléguée au HSM
- Clé privée jamais exposée
Phase 7 : Rotation clés¶
rotateKey(currentLabel, newLabel, keyType):- Générer nouvelle clé
- Archiver ancienne (rename)
- Retourner résultat
Phase 8 : Tests¶
- Tests unitaires avec mock provider
- Tests intégration avec CloudHSM réel
- Tests signature/vérification
- Tests gestion erreurs
Points de vigilance¶
- HSM obligatoire : Pas de fallback, erreur si indisponible
- VPN : Vérifier connectivité OVH ↔ AWS
- Session timeout : Renouveler avant expiration
- Logs : Jamais de clés ou données sensibles
Hors périmètre¶
- Provisioning HSM (→ Terraform)
- Création clés initiales (→ procédure manuelle)
- Signature audit logs (→ PD-37)
Annexes¶
- CloudHSM On-Demand CI/CD — Stratégie on-demand pour réduire les coûts CloudHSM DEV (~78% d'économie)