Configuring HSM for Key Storage
Overview
Hardware Security Modules (HSMs) are tamper-resistant physical devices that safeguard cryptographic keys and perform cryptographic operations in a hardened environment. Keys stored in an HSM never leave the device boundary, providing the highest level of key protection. This skill covers configuring HSMs using the PKCS#11 standard interface, including key generation, signing, encryption, and key management using both physical HSMs and SoftHSM2 for development.
Objectives
- Configure SoftHSM2 as a development PKCS#11 provider
- Generate and manage keys inside the HSM via PKCS#11
- Perform cryptographic operations (sign, verify, encrypt, decrypt) using HSM-resident keys
- Implement HSM-backed certificate authority operations
- Configure key access policies and user authentication
- Interface with cloud HSM services (AWS CloudHSM, Azure)
Key Concepts
HSM Compliance Levels
| FIPS Level |
Protection |
Use Case |
| FIPS 140-2 Level 1 |
Software only |
Development |
| FIPS 140-2 Level 2 |
Tamper-evident, role-based auth |
General production |
| FIPS 140-2 Level 3 |
Tamper-resistant, identity-based auth |
Financial, government |
| FIPS 140-2 Level 4 |
Physical tamper response |
Military, classified |
PKCS#11 Architecture
Application --> PKCS#11 API --> HSM Provider --> Hardware HSM
|
(SoftHSM2 for dev)
Key Objects in PKCS#11
| Object Type |
Description |
Operations |
| CKO_SECRET_KEY |
Symmetric keys (AES) |
Encrypt, Decrypt, Wrap |
| CKO_PUBLIC_KEY |
Public keys (RSA, EC) |
Verify, Encrypt, Wrap |
| CKO_PRIVATE_KEY |
Private keys (RSA, EC) |
Sign, Decrypt, Unwrap |
| CKO_CERTIFICATE |
X.509 certificates |
Storage, retrieval |
Security Considerations
- Never export private keys from HSM (use CKA_EXTRACTABLE=False)
- Use separate slots/partitions for different applications
- Implement multi-person key ceremony for CA root keys
- Enable audit logging for all HSM operations
- Implement HSM backup and disaster recovery
- Use strong PINs and enable SO (Security Officer) PIN
Validation Criteria
1---2name: configuring-hsm-for-key-storage3description: Hardware Security Modules (HSMs) are tamper-resistant physical devices that safeguard cryptographic keys and perform cryptographic operations in a hardened environment. Keys stored in an HSM never lea4domain: cybersecurity5subdomain: cryptography6tags: [cryptography, hsm, key-management, pkcs11, hardware-security]7version: "1.0"8author: mahipal9license: MIT10metadata:11 source: https://skillmd.com/skills/njones17/configuring-hsm-for-key-storage12---1314# Configuring HSM for Key Storage1516## Overview1718Hardware Security Modules (HSMs) are tamper-resistant physical devices that safeguard cryptographic keys and perform cryptographic operations in a hardened environment. Keys stored in an HSM never leave the device boundary, providing the highest level of key protection. This skill covers configuring HSMs using the PKCS#11 standard interface, including key generation, signing, encryption, and key management using both physical HSMs and SoftHSM2 for development.1920## Objectives2122- Configure SoftHSM2 as a development PKCS#11 provider23- Generate and manage keys inside the HSM via PKCS#1124- Perform cryptographic operations (sign, verify, encrypt, decrypt) using HSM-resident keys25- Implement HSM-backed certificate authority operations26- Configure key access policies and user authentication27- Interface with cloud HSM services (AWS CloudHSM, Azure)2829## Key Concepts3031### HSM Compliance Levels3233| FIPS Level | Protection | Use Case |34|-----------|-----------|----------|35| FIPS 140-2 Level 1 | Software only | Development |36| FIPS 140-2 Level 2 | Tamper-evident, role-based auth | General production |37| FIPS 140-2 Level 3 | Tamper-resistant, identity-based auth | Financial, government |38| FIPS 140-2 Level 4 | Physical tamper response | Military, classified |3940### PKCS#11 Architecture4142```43Application --> PKCS#11 API --> HSM Provider --> Hardware HSM44 |45 (SoftHSM2 for dev)46```4748### Key Objects in PKCS#114950| Object Type | Description | Operations |51|-------------|-------------|-----------|52| CKO_SECRET_KEY | Symmetric keys (AES) | Encrypt, Decrypt, Wrap |53| CKO_PUBLIC_KEY | Public keys (RSA, EC) | Verify, Encrypt, Wrap |54| CKO_PRIVATE_KEY | Private keys (RSA, EC) | Sign, Decrypt, Unwrap |55| CKO_CERTIFICATE | X.509 certificates | Storage, retrieval |5657## Security Considerations5859- Never export private keys from HSM (use CKA_EXTRACTABLE=False)60- Use separate slots/partitions for different applications61- Implement multi-person key ceremony for CA root keys62- Enable audit logging for all HSM operations63- Implement HSM backup and disaster recovery64- Use strong PINs and enable SO (Security Officer) PIN6566## Validation Criteria6768- [ ] SoftHSM2 initializes with token and user PIN69- [ ] AES key generates inside HSM70- [ ] RSA key pair generates inside HSM71- [ ] Encryption/decryption uses HSM-resident keys72- [ ] Signing/verification uses HSM-resident keys73- [ ] Keys cannot be exported (non-extractable)74- [ ] Key listing shows all HSM-stored objects