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.
When to Use
- When deploying or configuring configuring hsm for key storage capabilities in your environment
- When establishing security controls aligned to compliance requirements
- When building or improving security architecture for this domain
- When conducting security assessments that require this implementation
Prerequisites
- Familiarity with cryptography concepts and tools
- Access to a test or lab environment for safe execution
- Python 3.8+ with required dependencies installed
- Appropriate authorization for any testing activities
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: Configures Hardware Security Modules for cryptographic key4version: '1.0'5author: mahipal (vendored by SOCIS)6license: Apache-2.07platforms:8- linux9- macos10- windows11category: security12metadata:13 source: https://skillmd.com/skills/socisio/configuring-hsm-for-key-storage14 socis:15 tags:16 - cryptography17 - hsm18 - key-management19 - pkcs1120 - hardware-security21 subdomain: cryptography22 upstream: mukul975/Anthropic-Cybersecurity-Skills23 nist_csf:24 - PR.DS-0125 - PR.DS-0226 - PR.DS-1027 atlas_techniques:28 - AML.T007029 - AML.T006630 - AML.T008231 nist_ai_rmf:32 - MEASURE-2.733 - MAP-5.134 - MANAGE-2.435 mitre_attack:36 - T1552.00437 - T155538 - T107839---4041# Configuring HSM for Key Storage4243## Overview4445Hardware 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.464748## When to Use4950- When deploying or configuring configuring hsm for key storage capabilities in your environment51- When establishing security controls aligned to compliance requirements52- When building or improving security architecture for this domain53- When conducting security assessments that require this implementation5455## Prerequisites5657- Familiarity with cryptography concepts and tools58- Access to a test or lab environment for safe execution59- Python 3.8+ with required dependencies installed60- Appropriate authorization for any testing activities6162## Objectives6364- Configure SoftHSM2 as a development PKCS#11 provider65- Generate and manage keys inside the HSM via PKCS#1166- Perform cryptographic operations (sign, verify, encrypt, decrypt) using HSM-resident keys67- Implement HSM-backed certificate authority operations68- Configure key access policies and user authentication69- Interface with cloud HSM services (AWS CloudHSM, Azure)7071## Key Concepts7273### HSM Compliance Levels7475| FIPS Level | Protection | Use Case |76|-----------|-----------|----------|77| FIPS 140-2 Level 1 | Software only | Development |78| FIPS 140-2 Level 2 | Tamper-evident, role-based auth | General production |79| FIPS 140-2 Level 3 | Tamper-resistant, identity-based auth | Financial, government |80| FIPS 140-2 Level 4 | Physical tamper response | Military, classified |8182### PKCS#11 Architecture8384```85Application --> PKCS#11 API --> HSM Provider --> Hardware HSM86 |87 (SoftHSM2 for dev)88```8990### Key Objects in PKCS#119192| Object Type | Description | Operations |93|-------------|-------------|-----------|94| CKO_SECRET_KEY | Symmetric keys (AES) | Encrypt, Decrypt, Wrap |95| CKO_PUBLIC_KEY | Public keys (RSA, EC) | Verify, Encrypt, Wrap |96| CKO_PRIVATE_KEY | Private keys (RSA, EC) | Sign, Decrypt, Unwrap |97| CKO_CERTIFICATE | X.509 certificates | Storage, retrieval |9899## Security Considerations100101- Never export private keys from HSM (use CKA_EXTRACTABLE=False)102- Use separate slots/partitions for different applications103- Implement multi-person key ceremony for CA root keys104- Enable audit logging for all HSM operations105- Implement HSM backup and disaster recovery106- Use strong PINs and enable SO (Security Officer) PIN107108## Validation Criteria109110- [ ] SoftHSM2 initializes with token and user PIN111- [ ] AES key generates inside HSM112- [ ] RSA key pair generates inside HSM113- [ ] Encryption/decryption uses HSM-resident keys114- [ ] Signing/verification uses HSM-resident keys115- [ ] Keys cannot be exported (non-extractable)116- [ ] Key listing shows all HSM-stored objects