Skip to main content

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 generic Signer trait that abstracts cryptographic operations:

Supported implementations

Uses local Ed25519/secp256k1 keys for development and testing environments.
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:

Key management

Generating keys

Software keys

HSM keys

HSM keys must be generated using the HSM’s native tools:

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

Hardware keys provide better security than software keys for production environments.
Maintain secure backups of critical keys in encrypted storage.
Regularly rotate signing keys according to your security policy.
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

Error: Failed to load PKCS#11 module: No such file or directorySolution:
Error: No slots foundSolution:
Error: Failed to login: 0x1000Solution:
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.

Example migration

Testing

Unit tests

Integration tests

Example usage

Never commit HSM PINs or private keys to version control. Always use environment variables or secure secret management systems.