Overview
The Erst simulator supports Hardware Security Module (HSM) integration for cryptographic operations through a generic Signer interface. This allows for secure key management and signing operations using both software-based keys and hardware-backed keys via PKCS#11.Architecture
Generic signer interface
The HSM integration is built around a genericSigner trait that abstracts cryptographic operations:
Supported implementations
Software signer
Software signer
Uses local Ed25519/secp256k1 keys for development and testing environments.
PKCS#11 signer
PKCS#11 signer
Interfaces with hardware security modules for production environments requiring enhanced security.
Quick start
Software signer
PKCS#11 HSM signer
Configuration
Environment variables
Software signer
PKCS#11 signer
Programmatic configuration
Supported hardware
YubiKey
YubiKey devices with PIV support are fully compatible:Generic PKCS#11 modules
Any PKCS#11-compliant HSM should work:SoftHSM
SoftHSM
Nitrokey HSM
Nitrokey HSM
AWS CloudHSM
AWS CloudHSM
Key management
Generating keys
Software keys
HSM keys
HSM keys must be generated using the HSM’s native tools:YubiKey
YubiKey
SoftHSM
SoftHSM
Key formats
Ed25519 keys
- Private: PKCS#8 PEM format
- Public: SPKI DER format
secp256k1 keys
- Private: PKCS#8 PEM format
- Public: SPKI DER format
Security considerations
Key protection
1
HSM keys
Private keys never leave the HSM device, providing the highest level of security.
2
Software keys
Store securely with restricted file permissions (chmod 600).
3
PIN management
Use strong PINs and avoid hardcoding them in source code. Use environment variables or secure vaults.
Best practices
Use HSM for production
Use HSM for production
Hardware keys provide better security than software keys for production environments.
Backup keys
Backup keys
Maintain secure backups of critical keys in encrypted storage.
Rotate keys
Rotate keys
Regularly rotate signing keys according to your security policy.
Audit access
Audit access
Monitor and log all key usage for security auditing.
Threat mitigation
Performance
Benchmarks
HSM times vary by device and connection type (USB, network, etc.)
Optimization tips
- Reuse sessions: For HSM, reuse PKCS#11 sessions when possible
- Batch operations: Group multiple signing operations together
- Connection pooling: For network-connected HSMs, use connection pooling
- Caching: Cache public keys to avoid repeated HSM calls
Troubleshooting
Common issues
PKCS#11 module not found
PKCS#11 module not found
Error:
Failed to load PKCS#11 module: No such file or directorySolution:HSM not detected
HSM not detected
Error:
No slots foundSolution:PIN incorrect
PIN incorrect
Error:
Failed to login: 0x1000Solution:Key not found
Key not found
Error:
Private key not found in HSMSolution:Debug mode
Enable debug logging for troubleshooting:Migration guide
From in-memory keys to HSM
1
Extract current keys
Export existing keys to PEM format for backup.
2
Generate HSM keys
Create new keys in your HSM device using the appropriate tools.
3
Update configuration
Switch from software signer to PKCS#11 signer in your environment variables.
4
Test verification
Ensure signatures verify correctly with the new HSM keys.