PCI-DSS Encryption and Key Management
Overview
This skill implements PCI-DSS v4.0 Requirements 3 and 4 for protecting account data at rest and in transit. These requirements apply to all systems that store, process, or transmit cardholder data (CHD) or sensitive authentication data (SAD).
Requirement 3 — Protect stored account data:
| Sub-requirement |
Focus |
| 3.1 |
Processes and mechanisms for protecting stored account data |
| 3.2 |
SAD storage prohibited after authorization (full track, CVV, PIN)—never store post-auth |
| 3.3 |
PAN masking when displayed (show first six/last four max per PCI guidance) |
| 3.4 |
PAN rendered unreadable anywhere stored (encryption, hashing, tokenization, truncation) |
| 3.5 |
Key management procedures documented and implemented |
| 3.6 |
Cryptographic keys protected against disclosure and misuse |
| 3.7 |
Key management documented for keys used to protect stored account data |
Requirement 4 — Protect CHD during transmission:
| Sub-requirement |
Focus |
| 4.1 |
Processes for strong cryptography during transmission over open, public networks |
| 4.2 |
PAN protected with strong cryptography during transmission |
| 4.2.1 |
Inventory of trusted keys and certificates |
| 4.2.2 |
Wireless networks transmitting PAN use strong cryptography |
Key management lifecycle (Req 3.6–3.7): generation, distribution, storage, rotation, retirement, destruction. HSMs (Hardware Security Modules) or cloud KMS (AWS KMS, Azure Key Vault, GCP Cloud KMS) are standard for production PAN encryption.
This skill integrates Terraform MCP (mcp/terraform.mcp.json) and HashiCorp Vault patterns per references/compliance-as-code-patterns.md and compliance-as-code-governance.
When to Use
Use this skill when:
- Scoping encryption for databases, logs, backups, and agent evidence stores touching CHD
- Auditing key rotation, dual control, and split knowledge (Req 3.6)
- Validating tokenization architecture for scope reduction
- Reviewing TLS configuration on payment endpoints, APIs, and MCP transport (Req 4.2)
- Scanning Terraform/IaC for unencrypted RDS, S3, or cleartext PAN fields
- Assessing whether compliance agent/MCP logs or Postgres evidence DB contain PAN
Do not use this skill when:
- Firewall/CDE segmentation (use
pci-dss-network-segmentation)
- Checkout JavaScript and Req 6.4.3 (use
pci-dss-script-audit)
- HIPAA ePHI encryption without CHD (use
hipaa-technical-safeguards)
- California consumer privacy rights (use
ccpa-cpra-privacy-rights)
Core Process
Execute steps in order.
Step 1: Account data inventory (Req 3.1)
- Locate all CHD and SAD: databases, flat files, logs, backups, crash dumps, agent session stores, MCP query results.
- Classify storage:
| Location |
PAN present? |
Protection method |
In CDE? |
| Payment DB |
Yes |
AES-256 + KMS |
Yes |
| Agent evidence Postgres |
Must be No |
Token only |
Assess scope |
| Application logs |
Must be No |
Masking/redaction |
Varies |
- CRITICAL: Any PAN in agent/MCP logs expands PCI scope—scan with synthetic test PAN patterns.
- Artifact:
account-data-inventory-{id}.csv.
Step 2: SAD and display controls (Req 3.2, 3.3)
- Verify no SAD stored after authorization—query schemas for track data, CVV, PIN fields.
- Review UI and admin consoles for PAN masking (max first six and last four for issuer identification).
- Verify agent tools and
deanonymize_response cannot expose full PAN without business justification and logging.
- FAIL if full PAN appears in Slack MCP notifications or evidence exports.
Step 3: PAN unreadable at rest (Req 3.4)
- For each PAN storage location, verify one of:
- Strong cryptography (AES-256 with per-record or envelope encryption)
- One-way hash (with salt, for non-reversible use cases only)
- Tokenization (irreversible token with secure token vault)
- Truncation (if no storage of full PAN required)
- Prohibit reversible encoding (Base64 alone) as "encryption."
- Verify encryption keys are not stored alongside encrypted PAN (same DB table, same S3 object metadata unprotected).
Step 4: Key management procedures (Req 3.5–3.7)
Document and test:
- Key generation — cryptographically secure RNG; HSM/KMS where feasible.
- Key distribution — secure channels; no keys in git, Slack, or agent prompts.
- Key storage — HSM, KMS, or Vault with access logging.
- Key rotation — periodic rotation per crypto period (typically annual or on compromise); document calendar.
- Key retirement — secure destruction/archival when keys expire.
- Split knowledge / dual control — minimum two people for critical key operations (Req 3.6.1.2).
- Artifact:
key-management-procedures-{id}.pdf with version and approver.
Step 5: HSM and KMS validation
- Inventory all key stores:
| System |
Key type |
FIPS 140-2/3 validated? |
Access control |
| AWS KMS |
DEK/CMK |
Level 2+ (KMS) |
IAM roles |
| HashiCorp Vault |
Transit keys |
Depends on backend |
Vault policies |
| On-prem HSM |
Master keys |
Level 3 typical |
M of N admin |
- Verify KMS/Vault policies enforce least privilege—cross-ref
access-control-identity-audit.
- Verify audit logs for key use—cross-ref
audit-logging-integrity (PCI Req 10 overlap).
- Test: unauthorized identity cannot
decrypt or export key material.
Step 6: Tokenization assessment
- Document tokenization flow: PAN → token vault → token returned to application/agent.
- Verify agent and MCP see tokens only, not PAN—supports scope reduction with
pci-dss-network-segmentation.
- Validate token vault meets Req 3.4–3.7 (same rigor as PAN encryption).
- Verify detokenization is restricted, logged, and not available via MCP without approval.
Step 7: Transmission security (Req 4.1, 4.2)
- Inventory all channels transmitting PAN: HTTPS checkout, API, internal service mesh, MCP transport.
- Verify TLS 1.2 or higher; disable SSLv3, TLS 1.0/1.1 (Req 4.2, industry standard).
- Review cipher suites—prefer forward secrecy (ECDHE); disable weak ciphers.
- Maintain certificate inventory (Req 4.2.1): expiry monitoring, trusted CA chain, no self-signed in production payment paths.
- Test with SSL Labs or
openssl s_client from authorized probe; store results.
- MCP compliance: TLS 1.2+ for all MCP server connections per
mcp-compliance-integration.
Step 8: Terraform/Vault MCP evidence collection
- Configure Terraform MCP read-only against state backend:
// mcp/terraform.mcp.json — read-only plan/state
- Scan for violations:
- RDS/SQL without
storage_encrypted = true
- S3 buckets with CHD tags lacking encryption
- ALB/listeners allowing TLS 1.0
- Secrets in plaintext Terraform variables
- Vault MCP (if deployed): export policy list showing who can read transit keys—never export key material via MCP.
- Integrate Checkov/tfsec rules from
compliance-as-code-governance—map to PCI 3.4, 4.2.
- Hash scan outputs for evidence manifest.
Step 9: Findings and remediation
- Severity guide:
- CRITICAL: Cleartext PAN in logs/agent store; SAD stored post-auth; TLS 1.0 on payment path
- HIGH: Missing key rotation; keys in source control; no dual control on HSM
- MEDIUM: Certificate expiry monitoring gap; incomplete key inventory
- Emit standard finding YAML with
control_id: PCI-3.4 or PCI-4.2.
Common Rationalizations
| Excuse the agent might generate |
Required rebuttal |
| "We tokenize at the gateway, so Req 3 doesn't apply to our app." |
If any system stores/processes PAN, Req 3 applies—tokenization must cover all PAN locations including logs. |
| "TLS terminates at the load balancer; backend HTTP is internal." |
Internal networks are not exempt if PAN traverses them—encrypt or segment per Req 4 and Req 1. |
| "KMS manages keys, so we don't need documented procedures." |
Req 3.5–3.7 require documented procedures for human processes around KMS—managed service ≠ procedural compliance. |
| "Agent only sees tokens occasionally—we don't audit that path." |
Any PAN exposure path is in scope—MCP Postgres queries must be proven token-only. |
| "Vault dev mode is fine for staging." |
Staging with real PAN patterns requires production-equivalent crypto—dev mode Vault is a CRITICAL finding if CHD present. |
| "Base64 encoding protects PAN in the database." |
Encoding is not encryption—Req 3.4 requires strong cryptography or approved alternative. |
Red Flags
- Full PAN or CVV in application, agent, or MCP logs
- Encryption keys in git repository or agent skill files
- TLS 1.0/1.1 enabled on payment or PAN API endpoints
- RDS/database storage encryption disabled in Terraform state
- Tokenization bypass API returns PAN to agent tools without audit
- No key rotation evidence for >12 months
- Single person can generate, distribute, and activate production keys (no dual control)
- Vault or KMS decrypt permission granted to broad
* IAM role
- SAD retained in database after authorization completes
Verification
1---2name: pci-dss-encryption-key-management3description: Audits PCI-DSS v4.0 Requirement 3 (protect stored account data) and Requirement 4 (protect cardholder data with strong cryptography during transmission)—covering key management lifecycle, HSM usage, PAN masking, tokenization, and TLS 1.2+ enforcement with Terraform/Vault MCP patterns for evidence collection. Trigger when assessing encryption of CHD/SAD at rest or in transit, reviewing key rotation and split knowledge, validating tokenization scope reduction, or scanning IaC for crypto misconfigurations. Do not use for network segmentation (use pci-dss-network-segmentation), payment-page script inventory (use pci-dss-script-audit), or general IAM without crypto focus (use access-control-identity-audit).4---56# PCI-DSS Encryption and Key Management78## Overview910This skill implements **PCI-DSS v4.0 Requirements 3 and 4** for **protecting account data** at rest and in transit. These requirements apply to all systems that **store, process, or transmit** cardholder data (CHD) or sensitive authentication data (SAD).1112**Requirement 3 — Protect stored account data:**1314| Sub-requirement | Focus |15| --- | --- |16| **3.1** | Processes and mechanisms for protecting stored account data |17| **3.2** | **SAD storage prohibited** after authorization (full track, CVV, PIN)—never store post-auth |18| **3.3** | **PAN masking** when displayed (show first six/last four max per PCI guidance) |19| **3.4** | PAN rendered unreadable anywhere stored (encryption, hashing, tokenization, truncation) |20| **3.5** | Key management procedures documented and implemented |21| **3.6** | **Cryptographic keys** protected against disclosure and misuse |22| **3.7** | Key management documented for keys used to protect stored account data |2324**Requirement 4 — Protect CHD during transmission:**2526| Sub-requirement | Focus |27| --- | --- |28| **4.1** | Processes for strong cryptography during transmission over open, public networks |29| **4.2** | **PAN** protected with strong cryptography during transmission |30| **4.2.1** | Inventory of trusted keys and certificates |31| **4.2.2** | Wireless networks transmitting PAN use strong cryptography |3233**Key management lifecycle** (Req 3.6–3.7): generation, distribution, storage, rotation, retirement, destruction. **HSMs** (Hardware Security Modules) or cloud KMS (AWS KMS, Azure Key Vault, GCP Cloud KMS) are standard for production PAN encryption.3435This skill integrates **Terraform MCP** (`mcp/terraform.mcp.json`) and **HashiCorp Vault** patterns per `references/compliance-as-code-patterns.md` and `compliance-as-code-governance`.3637## When to Use3839Use this skill when:4041- **Scoping encryption** for databases, logs, backups, and agent evidence stores touching CHD42- Auditing **key rotation**, dual control, and split knowledge (Req 3.6)43- Validating **tokenization** architecture for scope reduction44- Reviewing **TLS configuration** on payment endpoints, APIs, and MCP transport (Req 4.2)45- Scanning **Terraform/IaC** for unencrypted RDS, S3, or cleartext PAN fields46- Assessing whether **compliance agent/MCP** logs or Postgres evidence DB contain PAN4748Do **not** use this skill when:4950- Firewall/CDE segmentation (use `pci-dss-network-segmentation`)51- Checkout JavaScript and Req 6.4.3 (use `pci-dss-script-audit`)52- HIPAA ePHI encryption without CHD (use `hipaa-technical-safeguards`)53- California consumer privacy rights (use `ccpa-cpra-privacy-rights`)5455## Core Process5657Execute steps **in order**.5859### Step 1: Account data inventory (Req 3.1)60611. Locate all CHD and SAD: databases, flat files, logs, backups, crash dumps, agent session stores, MCP query results.622. Classify storage:6364| Location | PAN present? | Protection method | In CDE? |65| --- | --- | --- | --- |66| Payment DB | Yes | AES-256 + KMS | Yes |67| Agent evidence Postgres | Must be No | Token only | Assess scope |68| Application logs | Must be No | Masking/redaction | Varies |69703. **CRITICAL**: Any PAN in agent/MCP logs expands PCI scope—scan with synthetic test PAN patterns.714. Artifact: `account-data-inventory-{id}.csv`.7273### Step 2: SAD and display controls (Req 3.2, 3.3)74751. Verify **no SAD stored** after authorization—query schemas for track data, CVV, PIN fields.762. Review UI and admin consoles for **PAN masking** (max first six and last four for issuer identification).773. Verify agent tools and `deanonymize_response` cannot expose full PAN without business justification and logging.784. FAIL if full PAN appears in Slack MCP notifications or evidence exports.7980### Step 3: PAN unreadable at rest (Req 3.4)81821. For each PAN storage location, verify one of:83 - **Strong cryptography** (AES-256 with per-record or envelope encryption)84 - **One-way hash** (with salt, for non-reversible use cases only)85 - **Tokenization** (irreversible token with secure token vault)86 - **Truncation** (if no storage of full PAN required)872. Prohibit reversible encoding (Base64 alone) as "encryption."883. Verify encryption keys are **not stored alongside** encrypted PAN (same DB table, same S3 object metadata unprotected).8990### Step 4: Key management procedures (Req 3.5–3.7)9192Document and test:93941. **Key generation** — cryptographically secure RNG; HSM/KMS where feasible.952. **Key distribution** — secure channels; no keys in git, Slack, or agent prompts.963. **Key storage** — HSM, KMS, or Vault with access logging.974. **Key rotation** — periodic rotation per crypto period (typically annual or on compromise); document calendar.985. **Key retirement** — secure destruction/archival when keys expire.996. **Split knowledge / dual control** — minimum two people for critical key operations (Req 3.6.1.2).1007. Artifact: `key-management-procedures-{id}.pdf` with version and approver.101102### Step 5: HSM and KMS validation1031041. Inventory all key stores:105106| System | Key type | FIPS 140-2/3 validated? | Access control |107| --- | --- | --- | --- |108| AWS KMS | DEK/CMK | Level 2+ (KMS) | IAM roles |109| HashiCorp Vault | Transit keys | Depends on backend | Vault policies |110| On-prem HSM | Master keys | Level 3 typical | M of N admin |1111122. Verify KMS/Vault policies enforce **least privilege**—cross-ref `access-control-identity-audit`.1133. Verify **audit logs** for key use—cross-ref `audit-logging-integrity` (PCI Req 10 overlap).1144. Test: unauthorized identity cannot `decrypt` or `export` key material.115116### Step 6: Tokenization assessment1171181. Document tokenization flow: PAN → token vault → token returned to application/agent.1192. Verify agent and MCP see **tokens only**, not PAN—supports scope reduction with `pci-dss-network-segmentation`.1203. Validate token vault meets Req 3.4–3.7 (same rigor as PAN encryption).1214. Verify detokenization is restricted, logged, and not available via MCP without approval.122123### Step 7: Transmission security (Req 4.1, 4.2)1241251. Inventory all channels transmitting PAN: HTTPS checkout, API, internal service mesh, MCP transport.1262. Verify **TLS 1.2 or higher**; disable SSLv3, TLS 1.0/1.1 (Req 4.2, industry standard).1273. Review cipher suites—prefer forward secrecy (ECDHE); disable weak ciphers.1284. Maintain **certificate inventory** (Req 4.2.1): expiry monitoring, trusted CA chain, no self-signed in production payment paths.1295. Test with SSL Labs or `openssl s_client` from authorized probe; store results.1306. **MCP compliance**: TLS 1.2+ for all MCP server connections per `mcp-compliance-integration`.131132### Step 8: Terraform/Vault MCP evidence collection1331341. Configure **Terraform MCP** read-only against state backend:135 ```json136 // mcp/terraform.mcp.json — read-only plan/state137 ```1382. Scan for violations:139 - RDS/SQL without `storage_encrypted = true`140 - S3 buckets with CHD tags lacking encryption141 - ALB/listeners allowing TLS 1.0142 - Secrets in plaintext Terraform variables1433. **Vault MCP** (if deployed): export policy list showing who can read transit keys—never export key material via MCP.1444. Integrate **Checkov/tfsec** rules from `compliance-as-code-governance`—map to PCI 3.4, 4.2.1455. Hash scan outputs for evidence manifest.146147### Step 9: Findings and remediation1481491. Severity guide:150 - **CRITICAL**: Cleartext PAN in logs/agent store; SAD stored post-auth; TLS 1.0 on payment path151 - **HIGH**: Missing key rotation; keys in source control; no dual control on HSM152 - **MEDIUM**: Certificate expiry monitoring gap; incomplete key inventory1532. Emit standard finding YAML with `control_id: PCI-3.4` or `PCI-4.2`.154155## Common Rationalizations156157| Excuse the agent might generate | Required rebuttal |158| --- | --- |159| "We tokenize at the gateway, so Req 3 doesn't apply to our app." | If **any** system stores/processes PAN, Req 3 applies—tokenization must cover **all** PAN locations including logs. |160| "TLS terminates at the load balancer; backend HTTP is internal." | Internal networks are not exempt if PAN traverses them—encrypt or segment per Req 4 and Req 1. |161| "KMS manages keys, so we don't need documented procedures." | Req 3.5–3.7 require **documented procedures** for human processes around KMS—managed service ≠ procedural compliance. |162| "Agent only sees tokens occasionally—we don't audit that path." | **Any** PAN exposure path is in scope—MCP Postgres queries must be proven token-only. |163| "Vault dev mode is fine for staging." | Staging with real PAN patterns requires **production-equivalent** crypto—dev mode Vault is a CRITICAL finding if CHD present. |164| "Base64 encoding protects PAN in the database." | Encoding is **not encryption**—Req 3.4 requires strong cryptography or approved alternative. |165166## Red Flags167168- Full PAN or CVV in application, agent, or MCP logs169- Encryption keys in git repository or agent skill files170- TLS 1.0/1.1 enabled on payment or PAN API endpoints171- RDS/database storage encryption disabled in Terraform state172- Tokenization bypass API returns PAN to agent tools without audit173- No key rotation evidence for >12 months174- Single person can generate, distribute, and activate production keys (no dual control)175- Vault or KMS decrypt permission granted to broad `*` IAM role176- SAD retained in database after authorization completes177178## Verification179180- [ ] Account data inventory complete including agent/MCP/log locations181- [ ] SAD storage verified absent post-authorization (Req 3.2)182- [ ] PAN masking validated on all display and notification paths (Req 3.3)183- [ ] All PAN at rest rendered unreadable per Req 3.4 with method documented184- [ ] Key management procedures documented covering full lifecycle (Req 3.5–3.7)185- [ ] HSM/KMS/Vault access controls and audit logging verified186- [ ] Tokenization flow documented; agent/MCP confirmed token-only187- [ ] TLS 1.2+ verified on all PAN transmission paths (Req 4.2)188- [ ] Certificate inventory and expiry monitoring operational (Req 4.2.1)189- [ ] Terraform MCP / Checkov scan completed with findings remediated or tracked190- [ ] Evidence manifest with SHA-256 hashes and PCI control ID mapping