Performing Hardware Security Module Integration
Overview
Hardware Security Modules (HSMs) provide tamper-resistant cryptographic key storage and operations. This skill covers integrating with HSMs via the PKCS#11 standard interface using python-pkcs11, performing key generation, signing, encryption, and verification operations, querying token and slot information, and validating HSM configuration for compliance with FIPS 140-2/3 requirements.
When to Use
Trigger phrases:
"performing hardware security module integration"
"Integrate Hardware Security Modules (HSMs) using PKCS#11 interface for cryptogra"
When conducting security assessments that involve performing hardware security module integration
When following incident response procedures for related security events
When performing scheduled security testing or auditing activities
When validating security controls through hands-on testing
Prerequisites
- HSM device or software HSM (SoftHSM2 for testing)
- PKCS#11 shared library (.so/.dll) for the HSM vendor
- Python 3.9+ with
python-pkcs11
- Token initialized with SO PIN and user PIN
- For AWS CloudHSM:
cloudhsm-pkcs11 provider configured
Steps
# Example: IOC detection
import re
IOC_PATTERNS = {
"ip": r"\b(?:\d{1,3}\.){3}\d{1,3}\b",
"domain": r"\b[a-z0-9-]+\.[a-z]{2,}\b",
"hash_md5": r"\b[a-f0-9]{32}\b",
"hash_sha256": r"\b[a-f0-9]{64}\b",
}
def extract_iocs(text: str) -> dict:
return {k: re.findall(v, text) for k, v in IOC_PATTERNS.items()}
- Load PKCS#11 library and enumerate available slots and tokens
- Open session and authenticate with user PIN
- Generate RSA 2048-bit or EC P-256 key pairs on the HSM
- Perform signing and verification using on-device keys
- List all objects (keys, certificates) stored on the token
- Query mechanism list to verify supported algorithms
- Generate compliance report with key inventory and algorithm audit
Expected Output
- JSON report listing HSM slots, tokens, stored keys, supported mechanisms, and compliance status
- Signing test results with key metadata and algorithm details
When NOT to Use
- You don't have explicit written authorization to test
- Task is about defense/detection, not offense (use detection skills)
- You need to implement security controls (use implementing-* skills)
- Task requires compliance auditing (use auditing-* skills)
- You're investigating an incident (use incident response skills)
- Target is out of scope for your engagement
- Task is about vulnerability scanning only (use scanning tools)
Red Flags
- Performing actions without explicit written authorization from the asset owner
- Testing against production systems without a defined scope and rules of engagement
- Sharing sensitive findings or credentials in unencrypted communications
- Failing to properly scope and contain the assessment before starting
Process
- Reconnaissance — Gather target information, identify attack surface, enumerate services
- Analysis/Exploitation — Execute the technique, analyze results, document findings
- Reporting — Document IOCs, write findings, provide remediation recommendations
Verification
- All steps executed successfully against a test environment before production use
- Output documented with screenshots or logs demonstrating expected behavior
- Results validated against known-good baselines or reference implementations
- Documentation complete enough for another analyst to reproduce findings
Anti-Rationalization Table
| Rationalization |
Reality |
| "We are too small to be targeted" |
Automated attacks target everyone. Size does not matter. |
| "Security slows us down" |
A breach slows you down 100x more. Build security in from the start. |
| "We will fix it after launch" |
Vulnerabilities in production are exploited within hours. Fix before deploy. |
1---2name: performing-hardware-security-module-integration3description: Use when integrate Hardware Security Modules (HSMs) using PKCS#11 interface for cryptographic key management, signing operations, and secure key storage with python-pkcs11, AWS CloudHSM, and YubiHSM2. Use when integrateing hardware security modules (hsms) using pkcs#11 interface for cryptographic.4license: Apache-2.05---678# Performing Hardware Security Module Integration910## Overview1112Hardware Security Modules (HSMs) provide tamper-resistant cryptographic key storage and operations. This skill covers integrating with HSMs via the PKCS#11 standard interface using python-pkcs11, performing key generation, signing, encryption, and verification operations, querying token and slot information, and validating HSM configuration for compliance with FIPS 140-2/3 requirements.131415## When to Use16**Trigger phrases:**17- "performing hardware security module integration"18- "Integrate Hardware Security Modules (HSMs) using PKCS#11 interface for cryptogra"192021- When conducting security assessments that involve performing hardware security module integration22- When following incident response procedures for related security events23- When performing scheduled security testing or auditing activities24- When validating security controls through hands-on testing2526## Prerequisites2728- HSM device or software HSM (SoftHSM2 for testing)29- PKCS#11 shared library (.so/.dll) for the HSM vendor30- Python 3.9+ with `python-pkcs11`31- Token initialized with SO PIN and user PIN32- For AWS CloudHSM: `cloudhsm-pkcs11` provider configured3334## Steps3536```python37# Example: IOC detection38import re3940IOC_PATTERNS = {41 "ip": r"\b(?:\d{1,3}\.){3}\d{1,3}\b",42 "domain": r"\b[a-z0-9-]+\.[a-z]{2,}\b",43 "hash_md5": r"\b[a-f0-9]{32}\b",44 "hash_sha256": r"\b[a-f0-9]{64}\b",45}4647def extract_iocs(text: str) -> dict:48 return {k: re.findall(v, text) for k, v in IOC_PATTERNS.items()}49```50511. Load PKCS#11 library and enumerate available slots and tokens522. Open session and authenticate with user PIN533. Generate RSA 2048-bit or EC P-256 key pairs on the HSM544. Perform signing and verification using on-device keys555. List all objects (keys, certificates) stored on the token566. Query mechanism list to verify supported algorithms577. Generate compliance report with key inventory and algorithm audit5859## Expected Output6061- JSON report listing HSM slots, tokens, stored keys, supported mechanisms, and compliance status62- Signing test results with key metadata and algorithm details63## When NOT to Use6465- You don't have explicit written authorization to test66- Task is about defense/detection, not offense (use detection skills)67- You need to implement security controls (use implementing-* skills)68- Task requires compliance auditing (use auditing-* skills)69- You're investigating an incident (use incident response skills)70- Target is out of scope for your engagement71- Task is about vulnerability scanning only (use scanning tools)727374## Red Flags7576- Performing actions without explicit written authorization from the asset owner77- Testing against production systems without a defined scope and rules of engagement78- Sharing sensitive findings or credentials in unencrypted communications79- Failing to properly scope and contain the assessment before starting8081## Process82831. **Reconnaissance** — Gather target information, identify attack surface, enumerate services841. **Analysis/Exploitation** — Execute the technique, analyze results, document findings851. **Reporting** — Document IOCs, write findings, provide remediation recommendations8687## Verification8889- All steps executed successfully against a test environment before production use90- Output documented with screenshots or logs demonstrating expected behavior91- Results validated against known-good baselines or reference implementations92- Documentation complete enough for another analyst to reproduce findings9394## Anti-Rationalization Table9596| Rationalization | Reality |97|---|---|98| "We are too small to be targeted" | Automated attacks target everyone. Size does not matter. |99| "Security slows us down" | A breach slows you down 100x more. Build security in from the start. |100| "We will fix it after launch" | Vulnerabilities in production are exploited within hours. Fix before deploy. |