@quantakrypto/core 0.4.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -27
- package/dist/cbom-merge.d.ts +9 -0
- package/dist/cbom-merge.d.ts.map +1 -0
- package/dist/cbom-merge.js +121 -0
- package/dist/cbom-merge.js.map +1 -0
- package/dist/cbom.d.ts +5 -0
- package/dist/cbom.d.ts.map +1 -1
- package/dist/cbom.js +132 -37
- package/dist/cbom.js.map +1 -1
- package/dist/comments.d.ts +6 -26
- package/dist/comments.d.ts.map +1 -1
- package/dist/comments.js +77 -38
- package/dist/comments.js.map +1 -1
- package/dist/dependencies.d.ts.map +1 -1
- package/dist/dependencies.js +1 -1
- package/dist/dependencies.js.map +1 -1
- package/dist/detect-utils.d.ts +59 -21
- package/dist/detect-utils.d.ts.map +1 -1
- package/dist/detect-utils.js +143 -8
- package/dist/detect-utils.js.map +1 -1
- package/dist/detectors/age.d.ts +16 -0
- package/dist/detectors/age.d.ts.map +1 -0
- package/dist/detectors/age.js +40 -0
- package/dist/detectors/age.js.map +1 -0
- package/dist/detectors/ansible.d.ts +13 -0
- package/dist/detectors/ansible.d.ts.map +1 -0
- package/dist/detectors/ansible.js +108 -0
- package/dist/detectors/ansible.js.map +1 -0
- package/dist/detectors/bicep.d.ts +20 -0
- package/dist/detectors/bicep.d.ts.map +1 -0
- package/dist/detectors/bicep.js +74 -0
- package/dist/detectors/bicep.js.map +1 -0
- package/dist/detectors/c.d.ts +4 -2
- package/dist/detectors/c.d.ts.map +1 -1
- package/dist/detectors/c.js +222 -4
- package/dist/detectors/c.js.map +1 -1
- package/dist/detectors/cicd.d.ts +27 -0
- package/dist/detectors/cicd.d.ts.map +1 -0
- package/dist/detectors/cicd.js +129 -0
- package/dist/detectors/cicd.js.map +1 -0
- package/dist/detectors/cloud-kms.d.ts +24 -0
- package/dist/detectors/cloud-kms.d.ts.map +1 -0
- package/dist/detectors/cloud-kms.js +99 -0
- package/dist/detectors/cloud-kms.js.map +1 -0
- package/dist/detectors/cloudformation.d.ts +38 -0
- package/dist/detectors/cloudformation.d.ts.map +1 -0
- package/dist/detectors/cloudformation.js +201 -0
- package/dist/detectors/cloudformation.js.map +1 -0
- package/dist/detectors/codesign.d.ts +50 -0
- package/dist/detectors/codesign.d.ts.map +1 -0
- package/dist/detectors/codesign.js +143 -0
- package/dist/detectors/codesign.js.map +1 -0
- package/dist/detectors/csharp.d.ts.map +1 -1
- package/dist/detectors/csharp.js +13 -3
- package/dist/detectors/csharp.js.map +1 -1
- package/dist/detectors/dart.d.ts +35 -0
- package/dist/detectors/dart.d.ts.map +1 -0
- package/dist/detectors/dart.js +177 -0
- package/dist/detectors/dart.js.map +1 -0
- package/dist/detectors/database.d.ts +19 -0
- package/dist/detectors/database.d.ts.map +1 -0
- package/dist/detectors/database.js +97 -0
- package/dist/detectors/database.js.map +1 -0
- package/dist/detectors/dkim.d.ts +54 -0
- package/dist/detectors/dkim.d.ts.map +1 -0
- package/dist/detectors/dkim.js +92 -0
- package/dist/detectors/dkim.js.map +1 -0
- package/dist/detectors/dnssec.d.ts +55 -0
- package/dist/detectors/dnssec.d.ts.map +1 -0
- package/dist/detectors/dnssec.js +116 -0
- package/dist/detectors/dnssec.js.map +1 -0
- package/dist/detectors/elixir.d.ts +20 -0
- package/dist/detectors/elixir.d.ts.map +1 -0
- package/dist/detectors/elixir.js +227 -0
- package/dist/detectors/elixir.js.map +1 -0
- package/dist/detectors/java.d.ts.map +1 -1
- package/dist/detectors/java.js +34 -4
- package/dist/detectors/java.js.map +1 -1
- package/dist/detectors/jose.d.ts +20 -0
- package/dist/detectors/jose.d.ts.map +1 -0
- package/dist/detectors/jose.js +72 -0
- package/dist/detectors/jose.js.map +1 -0
- package/dist/detectors/jwk.d.ts +25 -0
- package/dist/detectors/jwk.d.ts.map +1 -0
- package/dist/detectors/jwk.js +131 -0
- package/dist/detectors/jwk.js.map +1 -0
- package/dist/detectors/k8s.d.ts +17 -0
- package/dist/detectors/k8s.d.ts.map +1 -0
- package/dist/detectors/k8s.js +88 -0
- package/dist/detectors/k8s.js.map +1 -0
- package/dist/detectors/keystore.d.ts +19 -0
- package/dist/detectors/keystore.d.ts.map +1 -0
- package/dist/detectors/keystore.js +76 -0
- package/dist/detectors/keystore.js.map +1 -0
- package/dist/detectors/mesh.d.ts +34 -0
- package/dist/detectors/mesh.d.ts.map +1 -0
- package/dist/detectors/mesh.js +91 -0
- package/dist/detectors/mesh.js.map +1 -0
- package/dist/detectors/messaging.d.ts +16 -0
- package/dist/detectors/messaging.d.ts.map +1 -0
- package/dist/detectors/messaging.js +79 -0
- package/dist/detectors/messaging.js.map +1 -0
- package/dist/detectors/objc.d.ts +41 -0
- package/dist/detectors/objc.d.ts.map +1 -0
- package/dist/detectors/objc.js +146 -0
- package/dist/detectors/objc.js.map +1 -0
- package/dist/detectors/openpgp.d.ts +20 -0
- package/dist/detectors/openpgp.d.ts.map +1 -0
- package/dist/detectors/openpgp.js +151 -0
- package/dist/detectors/openpgp.js.map +1 -0
- package/dist/detectors/pem.d.ts.map +1 -1
- package/dist/detectors/pem.js +33 -1
- package/dist/detectors/pem.js.map +1 -1
- package/dist/detectors/php.d.ts +25 -0
- package/dist/detectors/php.d.ts.map +1 -0
- package/dist/detectors/php.js +171 -0
- package/dist/detectors/php.js.map +1 -0
- package/dist/detectors/pkcs11.d.ts +17 -0
- package/dist/detectors/pkcs11.d.ts.map +1 -0
- package/dist/detectors/pkcs11.js +87 -0
- package/dist/detectors/pkcs11.js.map +1 -0
- package/dist/detectors/proxy.d.ts +52 -0
- package/dist/detectors/proxy.d.ts.map +1 -0
- package/dist/detectors/proxy.js +157 -0
- package/dist/detectors/proxy.js.map +1 -0
- package/dist/detectors/pulumi.d.ts +19 -0
- package/dist/detectors/pulumi.d.ts.map +1 -0
- package/dist/detectors/pulumi.js +80 -0
- package/dist/detectors/pulumi.js.map +1 -0
- package/dist/detectors/python.d.ts.map +1 -1
- package/dist/detectors/python.js +70 -0
- package/dist/detectors/python.js.map +1 -1
- package/dist/detectors/rust.d.ts.map +1 -1
- package/dist/detectors/rust.js +73 -0
- package/dist/detectors/rust.js.map +1 -1
- package/dist/detectors/secrets.d.ts +24 -0
- package/dist/detectors/secrets.d.ts.map +1 -0
- package/dist/detectors/secrets.js +63 -0
- package/dist/detectors/secrets.js.map +1 -0
- package/dist/detectors/solidity.d.ts +50 -0
- package/dist/detectors/solidity.d.ts.map +1 -0
- package/dist/detectors/solidity.js +108 -0
- package/dist/detectors/solidity.js.map +1 -0
- package/dist/detectors/source.d.ts.map +1 -1
- package/dist/detectors/source.js +243 -53
- package/dist/detectors/source.js.map +1 -1
- package/dist/detectors/spire.d.ts +49 -0
- package/dist/detectors/spire.d.ts.map +1 -0
- package/dist/detectors/spire.js +77 -0
- package/dist/detectors/spire.js.map +1 -0
- package/dist/detectors/ssh-ca.d.ts +72 -0
- package/dist/detectors/ssh-ca.d.ts.map +1 -0
- package/dist/detectors/ssh-ca.js +119 -0
- package/dist/detectors/ssh-ca.js.map +1 -0
- package/dist/detectors/stateful-hbs.d.ts.map +1 -1
- package/dist/detectors/stateful-hbs.js +9 -6
- package/dist/detectors/stateful-hbs.js.map +1 -1
- package/dist/detectors/supply-chain.d.ts +17 -0
- package/dist/detectors/supply-chain.d.ts.map +1 -0
- package/dist/detectors/supply-chain.js +89 -0
- package/dist/detectors/supply-chain.js.map +1 -0
- package/dist/detectors/swift.d.ts +22 -0
- package/dist/detectors/swift.d.ts.map +1 -0
- package/dist/detectors/swift.js +120 -0
- package/dist/detectors/swift.js.map +1 -0
- package/dist/detectors/terraform.d.ts +21 -0
- package/dist/detectors/terraform.d.ts.map +1 -0
- package/dist/detectors/terraform.js +150 -0
- package/dist/detectors/terraform.js.map +1 -0
- package/dist/detectors/vault.d.ts +15 -0
- package/dist/detectors/vault.d.ts.map +1 -0
- package/dist/detectors/vault.js +97 -0
- package/dist/detectors/vault.js.map +1 -0
- package/dist/detectors/vpn.d.ts +22 -0
- package/dist/detectors/vpn.d.ts.map +1 -0
- package/dist/detectors/vpn.js +73 -0
- package/dist/detectors/vpn.js.map +1 -0
- package/dist/detectors/weak-hash.d.ts +71 -0
- package/dist/detectors/weak-hash.d.ts.map +1 -0
- package/dist/detectors/weak-hash.js +116 -0
- package/dist/detectors/weak-hash.js.map +1 -0
- package/dist/detectors/webauthn.d.ts +61 -0
- package/dist/detectors/webauthn.d.ts.map +1 -0
- package/dist/detectors/webauthn.js +109 -0
- package/dist/detectors/webauthn.js.map +1 -0
- package/dist/detectors/xmldsig.d.ts +23 -0
- package/dist/detectors/xmldsig.d.ts.map +1 -0
- package/dist/detectors/xmldsig.js +84 -0
- package/dist/detectors/xmldsig.js.map +1 -0
- package/dist/evidence.d.ts +79 -4
- package/dist/evidence.d.ts.map +1 -1
- package/dist/evidence.js +76 -0
- package/dist/evidence.js.map +1 -1
- package/dist/index.d.ts +17 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -9
- package/dist/index.js.map +1 -1
- package/dist/inventory.d.ts +0 -2
- package/dist/inventory.d.ts.map +1 -1
- package/dist/inventory.js +15 -6
- package/dist/inventory.js.map +1 -1
- package/dist/policy.d.ts +67 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +115 -0
- package/dist/policy.js.map +1 -0
- package/dist/registry.d.ts +9 -4
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +81 -4
- package/dist/registry.js.map +1 -1
- package/dist/remediate-pipeline.d.ts +0 -3
- package/dist/remediate-pipeline.d.ts.map +1 -1
- package/dist/remediate-pipeline.js +23 -2
- package/dist/remediate-pipeline.js.map +1 -1
- package/dist/remediation.d.ts +10 -0
- package/dist/remediation.d.ts.map +1 -1
- package/dist/remediation.js +32 -0
- package/dist/remediation.js.map +1 -1
- package/dist/report.d.ts +9 -0
- package/dist/report.d.ts.map +1 -1
- package/dist/report.js +38 -1
- package/dist/report.js.map +1 -1
- package/dist/scan-worker.js +5 -3
- package/dist/scan-worker.js.map +1 -1
- package/dist/scan.d.ts.map +1 -1
- package/dist/scan.js +35 -6
- package/dist/scan.js.map +1 -1
- package/dist/standards-profiles.d.ts +58 -0
- package/dist/standards-profiles.d.ts.map +1 -0
- package/dist/standards-profiles.js +100 -0
- package/dist/standards-profiles.js.map +1 -0
- package/dist/standards.d.ts +96 -0
- package/dist/standards.d.ts.map +1 -0
- package/dist/standards.js +107 -0
- package/dist/standards.js.map +1 -0
- package/dist/types.d.ts +6 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/dist/vex.d.ts +39 -0
- package/dist/vex.d.ts.map +1 -0
- package/dist/vex.js +87 -0
- package/dist/vex.js.map +1 -0
- package/dist/walk.d.ts +8 -3
- package/dist/walk.d.ts.map +1 -1
- package/dist/walk.js +32 -1
- package/dist/walk.js.map +1 -1
- package/package.json +1 -1
- package/src/cbom-merge.ts +146 -0
- package/src/cbom.ts +153 -39
- package/src/comments.ts +84 -39
- package/src/dependencies.ts +2 -1
- package/src/detect-utils.ts +146 -12
- package/src/detectors/age.ts +60 -0
- package/src/detectors/ansible.ts +140 -0
- package/src/detectors/bicep.ts +107 -0
- package/src/detectors/c.ts +240 -6
- package/src/detectors/cicd.ts +171 -0
- package/src/detectors/cloud-kms.ts +141 -0
- package/src/detectors/cloudformation.ts +250 -0
- package/src/detectors/codesign.ts +214 -0
- package/src/detectors/csharp.ts +13 -3
- package/src/detectors/dart.ts +237 -0
- package/src/detectors/database.ts +141 -0
- package/src/detectors/dkim.ts +172 -0
- package/src/detectors/dnssec.ts +195 -0
- package/src/detectors/elixir.ts +268 -0
- package/src/detectors/java.ts +39 -4
- package/src/detectors/jose.ts +110 -0
- package/src/detectors/jwk.ts +170 -0
- package/src/detectors/k8s.ts +115 -0
- package/src/detectors/keystore.ts +109 -0
- package/src/detectors/mesh.ts +130 -0
- package/src/detectors/messaging.ts +106 -0
- package/src/detectors/objc.ts +209 -0
- package/src/detectors/openpgp.ts +194 -0
- package/src/detectors/pem.ts +31 -1
- package/src/detectors/php.ts +230 -0
- package/src/detectors/pkcs11.ts +113 -0
- package/src/detectors/proxy.ts +236 -0
- package/src/detectors/pulumi.ts +106 -0
- package/src/detectors/python.ts +71 -0
- package/src/detectors/rust.ts +76 -0
- package/src/detectors/secrets.ts +103 -0
- package/src/detectors/solidity.ts +176 -0
- package/src/detectors/source.ts +283 -73
- package/src/detectors/spire.ts +143 -0
- package/src/detectors/ssh-ca.ts +215 -0
- package/src/detectors/stateful-hbs.ts +9 -6
- package/src/detectors/supply-chain.ts +117 -0
- package/src/detectors/swift.ts +149 -0
- package/src/detectors/terraform.ts +188 -0
- package/src/detectors/vault.ts +120 -0
- package/src/detectors/vpn.ts +103 -0
- package/src/detectors/weak-hash.ts +217 -0
- package/src/detectors/webauthn.ts +205 -0
- package/src/detectors/xmldsig.ts +115 -0
- package/src/evidence.ts +138 -4
- package/src/index.ts +50 -12
- package/src/inventory.ts +15 -7
- package/src/policy.ts +180 -0
- package/src/registry.ts +81 -4
- package/src/remediate-pipeline.ts +26 -3
- package/src/remediation.ts +39 -0
- package/src/report.ts +43 -1
- package/src/scan-worker.ts +5 -3
- package/src/scan.ts +41 -6
- package/src/standards-profiles.ts +136 -0
- package/src/standards.ts +186 -0
- package/src/types.ts +11 -4
- package/src/version.ts +1 -1
- package/src/vex.ts +122 -0
- package/src/walk.ts +33 -2
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config detector: classical key material in JSON Web Keys (JWK / JWKS, RFC 7517
|
|
3
|
+
* / 7518). JWKs appear in `.json` / `.jwks` files, OIDC discovery documents, and
|
|
4
|
+
* config — a real key-material surface the source packs (which look at *code*)
|
|
5
|
+
* and the PEM detector (which looks at PEM markers) both miss.
|
|
6
|
+
*
|
|
7
|
+
* Detection keys off the JWK's distinctive JSON fields:
|
|
8
|
+
* - `"kty":"RSA"` → classical RSA key.
|
|
9
|
+
* - `"crv":"P-256"|"P-384"|"P-521"|…` → classical EC key (ECDSA + ECDH).
|
|
10
|
+
* - `"crv":"Ed25519"|"Ed448"` → EdDSA signing key.
|
|
11
|
+
* - `"crv":"X25519"|"X448"` → classical Montgomery-curve key agreement.
|
|
12
|
+
*
|
|
13
|
+
* Usage-aware classification: when a key's surrounding `"use"` / `"alg"` marks it
|
|
14
|
+
* as a SIGNING key (`use:"sig"`, or an `RS`/`PS`/`ES` signature alg), the finding
|
|
15
|
+
* is a `signature` (`hndl:false`) — a signing key is forgeable at a CRQC but not
|
|
16
|
+
* harvest-now exposed. An encryption/unspecified key stays `hndl:true`.
|
|
17
|
+
*
|
|
18
|
+
* Deferrals to avoid double-counting: skipped on doc extensions (a README JWK
|
|
19
|
+
* example is not live) and inside CloudFormation/ARM templates, where the
|
|
20
|
+
* cloudformation detector owns the `kty` of a `Microsoft.KeyVault` key resource.
|
|
21
|
+
*/
|
|
22
|
+
import type { Detector, Finding, RuleMeta } from "../types.js";
|
|
23
|
+
import {
|
|
24
|
+
DOC_EXTENSIONS,
|
|
25
|
+
eachMatch,
|
|
26
|
+
enclosingObject,
|
|
27
|
+
findingFromRule,
|
|
28
|
+
hasExtension,
|
|
29
|
+
} from "../detect-utils.js";
|
|
30
|
+
import { isCloudTemplateFile } from "./cloudformation.js";
|
|
31
|
+
import { CWE_BROKEN_CRYPTO } from "../cwe.js";
|
|
32
|
+
|
|
33
|
+
interface JwkRule {
|
|
34
|
+
re: RegExp;
|
|
35
|
+
meta: RuleMeta;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const JWK_RULES: JwkRule[] = [
|
|
39
|
+
{
|
|
40
|
+
re: /"kty"\s*:\s*"RSA"/g,
|
|
41
|
+
meta: {
|
|
42
|
+
id: "jwk-rsa",
|
|
43
|
+
title: "RSA JSON Web Key (JWK)",
|
|
44
|
+
description: 'JWK with "kty":"RSA" (RFC 7518)',
|
|
45
|
+
category: "certificate",
|
|
46
|
+
severity: "medium",
|
|
47
|
+
confidence: "high",
|
|
48
|
+
algorithm: "RSA",
|
|
49
|
+
hndl: true,
|
|
50
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
51
|
+
message: "RSA JSON Web Key (JWK); classical RSA, not quantum-safe.",
|
|
52
|
+
remediation: "Re-issue with PQC keys (ML-KEM-768 for encryption, ML-DSA-65 for signatures).",
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
re: /"crv"\s*:\s*"(?:P-256K?|P-384|P-521|secp256k1)"/g,
|
|
57
|
+
meta: {
|
|
58
|
+
id: "jwk-ec",
|
|
59
|
+
title: "EC JSON Web Key (JWK)",
|
|
60
|
+
description: 'JWK with an "crv" naming a NIST/secp curve (RFC 7518)',
|
|
61
|
+
category: "key-exchange",
|
|
62
|
+
severity: "medium",
|
|
63
|
+
confidence: "high",
|
|
64
|
+
algorithm: "ECDH",
|
|
65
|
+
hndl: true,
|
|
66
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
67
|
+
message:
|
|
68
|
+
"Elliptic-curve JSON Web Key (JWK); a classical EC key feeds BOTH ECDSA signatures and ECDH key agreement — the ECDH path is harvest-now-decrypt-later exposed.",
|
|
69
|
+
remediation:
|
|
70
|
+
"For key agreement: hybrid X25519MLKEM768 (ML-KEM-768). For signatures: ML-DSA-65 (FIPS 204).",
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
re: /"crv"\s*:\s*"Ed(?:25519|448)"/g,
|
|
75
|
+
meta: {
|
|
76
|
+
id: "jwk-eddsa",
|
|
77
|
+
title: "EdDSA JSON Web Key (JWK)",
|
|
78
|
+
description: 'JWK OKP key with "crv":"Ed25519"/"Ed448" (RFC 8037)',
|
|
79
|
+
category: "signature",
|
|
80
|
+
severity: "low",
|
|
81
|
+
confidence: "high",
|
|
82
|
+
algorithm: "EdDSA",
|
|
83
|
+
hndl: false,
|
|
84
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
85
|
+
message:
|
|
86
|
+
"EdDSA (Ed25519/Ed448) JSON Web Key (JWK); classical and forgeable by a quantum attacker.",
|
|
87
|
+
remediation: "ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205).",
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
re: /"crv"\s*:\s*"X(?:25519|448)"/g,
|
|
92
|
+
meta: {
|
|
93
|
+
id: "jwk-xdh",
|
|
94
|
+
title: "X25519/X448 JSON Web Key (JWK)",
|
|
95
|
+
description: 'JWK OKP key with "crv":"X25519"/"X448" (RFC 8037)',
|
|
96
|
+
category: "key-exchange",
|
|
97
|
+
severity: "medium",
|
|
98
|
+
confidence: "high",
|
|
99
|
+
algorithm: "X25519",
|
|
100
|
+
hndl: true,
|
|
101
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
102
|
+
message:
|
|
103
|
+
"X25519/X448 JSON Web Key (JWK); modern but classical key agreement, and harvest-now-decrypt-later exposed.",
|
|
104
|
+
remediation: "Migrate key agreement to hybrid X25519MLKEM768 (ML-KEM-768).",
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
];
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* True when THIS key's own object marks it as a signing key via `use`/`alg`. The
|
|
111
|
+
* caller passes the enclosing `{…}` object so a neighbouring key in a JWKS array
|
|
112
|
+
* can't contaminate the result, and an explicit `"use":"enc"` on the key always
|
|
113
|
+
* wins (never classify an encryption key as a signature).
|
|
114
|
+
*/
|
|
115
|
+
function isSigningUse(objectText: string, sigAlg: RegExp): boolean {
|
|
116
|
+
if (/"use"\s*:\s*"enc"/.test(objectText)) return false;
|
|
117
|
+
return /"use"\s*:\s*"sig"/.test(objectText) || sigAlg.test(objectText);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const RSA_SIG_ALG = /"alg"\s*:\s*"(?:RS|PS)(?:256|384|512)"/;
|
|
121
|
+
const EC_SIG_ALG = /"alg"\s*:\s*"ES(?:256K?|384|512)"/;
|
|
122
|
+
|
|
123
|
+
/** Detects classical JSON Web Key (JWK/JWKS) material in any JSON/text file. */
|
|
124
|
+
export const jwkDetector: Detector = {
|
|
125
|
+
id: "jwk-material",
|
|
126
|
+
description: "Classical key material in JSON Web Keys (JWK / JWKS)",
|
|
127
|
+
scope: "config",
|
|
128
|
+
language: "any",
|
|
129
|
+
rules: JWK_RULES.map((r) => r.meta),
|
|
130
|
+
appliesTo: (f) => !hasExtension(f, DOC_EXTENSIONS),
|
|
131
|
+
detect({ file, content }): Finding[] {
|
|
132
|
+
// Fast reject: a JWK always has one of these two members.
|
|
133
|
+
if (!content.includes('"kty"') && !content.includes('"crv"')) return [];
|
|
134
|
+
// The ONLY overlap with the cloudformation detector is the ARM Key Vault key
|
|
135
|
+
// `kty:"RSA"` (cfn-arm-keyvault-rsa), which only fires when Microsoft.KeyVault is
|
|
136
|
+
// present. Defer just the RSA rule in that case — everything else (crv keys, and
|
|
137
|
+
// JWKs embedded in AWS CloudFormation, which cfn does not own) is still reported.
|
|
138
|
+
const isArm = isCloudTemplateFile(file, content) && content.includes("Microsoft.KeyVault");
|
|
139
|
+
|
|
140
|
+
const findings: Finding[] = [];
|
|
141
|
+
for (const rule of JWK_RULES) {
|
|
142
|
+
eachMatch(rule.re, content, (m) => {
|
|
143
|
+
if (rule.meta.id === "jwk-rsa" && isArm) return; // cfn-arm-keyvault-rsa owns it
|
|
144
|
+
const at = { file, content, index: m.index, matchLength: m[0].length };
|
|
145
|
+
// Analyse the key's OWN enclosing object so a neighbouring key in a JWKS
|
|
146
|
+
// array can't flip this key's sig/enc classification.
|
|
147
|
+
const obj = enclosingObject(content, m.index);
|
|
148
|
+
let overrides;
|
|
149
|
+
if (rule.meta.id === "jwk-rsa" && isSigningUse(obj, RSA_SIG_ALG)) {
|
|
150
|
+
overrides = {
|
|
151
|
+
category: "signature" as const,
|
|
152
|
+
hndl: false,
|
|
153
|
+
message:
|
|
154
|
+
"RSA JSON Web Key (JWK) used for signing (RS*/PS*); forgeable by a quantum attacker.",
|
|
155
|
+
};
|
|
156
|
+
} else if (rule.meta.id === "jwk-ec" && isSigningUse(obj, EC_SIG_ALG)) {
|
|
157
|
+
overrides = {
|
|
158
|
+
category: "signature" as const,
|
|
159
|
+
algorithm: "ECDSA" as const,
|
|
160
|
+
hndl: false,
|
|
161
|
+
message:
|
|
162
|
+
"Elliptic-curve JSON Web Key (JWK) used for ECDSA signing; forgeable by a quantum attacker.",
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
findings.push(findingFromRule(rule.meta, at, overrides));
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
return findings;
|
|
169
|
+
},
|
|
170
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config detector: classical crypto in Kubernetes manifests — cert-manager key
|
|
3
|
+
* algorithms and service-mesh (Istio) TLS floors. These mint the certificates
|
|
4
|
+
* and secure the pod-to-pod traffic of a cluster, a surface neither the language
|
|
5
|
+
* packs nor the Terraform detector see.
|
|
6
|
+
*
|
|
7
|
+
* Covered (gated by a cert-manager / Istio marker in the document to keep the
|
|
8
|
+
* generic `algorithm:` / `minProtocolVersion:` keys from firing on unrelated YAML):
|
|
9
|
+
* - cert-manager `Certificate`/`Issuer` `privateKey.algorithm` (or legacy
|
|
10
|
+
* `keyAlgorithm`): `RSA` | `ECDSA` | `Ed25519`.
|
|
11
|
+
* - Istio `minProtocolVersion: TLSV1_0 | TLSV1_1` — a legacy TLS floor on mesh
|
|
12
|
+
* traffic, whose (EC)DHE key exchange is classical and harvestable.
|
|
13
|
+
*/
|
|
14
|
+
import type { Detector, Finding, RuleMeta } from "../types.js";
|
|
15
|
+
import { eachMatch, findingFromRule, hasExtension, maskCommentLines } from "../detect-utils.js";
|
|
16
|
+
import { CWE_BROKEN_CRYPTO, CWE_RISKY_PRIMITIVE } from "../cwe.js";
|
|
17
|
+
|
|
18
|
+
const K8S_EXTENSIONS: readonly string[] = [".yaml", ".yml", ".json"];
|
|
19
|
+
|
|
20
|
+
const RE_CM_RSA = /(?:algorithm|keyAlgorithm):\s*["']?RSA\b/g;
|
|
21
|
+
const RE_CM_ECDSA = /(?:algorithm|keyAlgorithm):\s*["']?ECDSA\b/g;
|
|
22
|
+
const RE_CM_ED25519 = /(?:algorithm|keyAlgorithm):\s*["']?Ed25519\b/g;
|
|
23
|
+
const RE_ISTIO_LEGACY_TLS = /minProtocolVersion:\s*["']?TLSV1_[01]\b/g;
|
|
24
|
+
|
|
25
|
+
const RULE_CM_RSA: RuleMeta = {
|
|
26
|
+
id: "k8s-certmanager-rsa",
|
|
27
|
+
title: "cert-manager RSA key",
|
|
28
|
+
description: "cert-manager Certificate/Issuer privateKey.algorithm = RSA",
|
|
29
|
+
category: "certificate",
|
|
30
|
+
severity: "medium",
|
|
31
|
+
confidence: "high",
|
|
32
|
+
algorithm: "RSA",
|
|
33
|
+
hndl: true,
|
|
34
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
35
|
+
message: "cert-manager mints certificates with a classical RSA key, which is not quantum-safe.",
|
|
36
|
+
remediation:
|
|
37
|
+
"Plan migration to PQC certificate keys (ML-DSA-65) as the CA/issuer chain adds support.",
|
|
38
|
+
};
|
|
39
|
+
const RULE_CM_ECDSA: RuleMeta = {
|
|
40
|
+
id: "k8s-certmanager-ecdsa",
|
|
41
|
+
title: "cert-manager ECDSA key",
|
|
42
|
+
description: "cert-manager Certificate/Issuer privateKey.algorithm = ECDSA",
|
|
43
|
+
category: "certificate",
|
|
44
|
+
severity: "medium",
|
|
45
|
+
confidence: "high",
|
|
46
|
+
algorithm: "ECDSA",
|
|
47
|
+
hndl: false,
|
|
48
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
49
|
+
message:
|
|
50
|
+
"cert-manager mints certificates with a classical ECDSA key, forgeable by a quantum attacker.",
|
|
51
|
+
remediation: "Plan migration to ML-DSA-65 (FIPS 204) certificate keys.",
|
|
52
|
+
};
|
|
53
|
+
const RULE_CM_ED25519: RuleMeta = {
|
|
54
|
+
id: "k8s-certmanager-ed25519",
|
|
55
|
+
title: "cert-manager Ed25519 key",
|
|
56
|
+
description: "cert-manager Certificate/Issuer privateKey.algorithm = Ed25519",
|
|
57
|
+
category: "certificate",
|
|
58
|
+
severity: "low",
|
|
59
|
+
confidence: "high",
|
|
60
|
+
algorithm: "EdDSA",
|
|
61
|
+
hndl: false,
|
|
62
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
63
|
+
message:
|
|
64
|
+
"cert-manager mints certificates with a classical Ed25519 key, forgeable by a quantum attacker.",
|
|
65
|
+
remediation: "Plan migration to ML-DSA-65 (FIPS 204) certificate keys.",
|
|
66
|
+
};
|
|
67
|
+
const RULE_ISTIO_LEGACY_TLS: RuleMeta = {
|
|
68
|
+
id: "k8s-istio-legacy-tls",
|
|
69
|
+
title: "Istio legacy TLS floor",
|
|
70
|
+
description: "Istio minProtocolVersion allows TLS 1.0 / 1.1 on mesh traffic",
|
|
71
|
+
category: "tls",
|
|
72
|
+
severity: "medium",
|
|
73
|
+
confidence: "high",
|
|
74
|
+
hndl: false,
|
|
75
|
+
cwe: CWE_RISKY_PRIMITIVE,
|
|
76
|
+
message:
|
|
77
|
+
"Istio mesh TLS floor allows TLS 1.0/1.1; its classical (EC)DHE key exchange is weak and harvestable.",
|
|
78
|
+
remediation:
|
|
79
|
+
"Raise minProtocolVersion to TLSV1_3 and track PQC-hybrid mesh KEX (X25519MLKEM768).",
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/** Detects classical cert-manager keys and legacy Istio TLS floors in K8s YAML. */
|
|
83
|
+
export const k8sDetector: Detector = {
|
|
84
|
+
id: "k8s-crypto",
|
|
85
|
+
description: "Classical crypto in Kubernetes manifests (cert-manager keys, Istio TLS floors)",
|
|
86
|
+
scope: "config",
|
|
87
|
+
language: "any",
|
|
88
|
+
rules: [RULE_CM_RSA, RULE_CM_ECDSA, RULE_CM_ED25519, RULE_ISTIO_LEGACY_TLS],
|
|
89
|
+
appliesTo: (f) => hasExtension(f, K8S_EXTENSIONS),
|
|
90
|
+
detect({ file, content }): Finding[] {
|
|
91
|
+
const isCertManager =
|
|
92
|
+
content.includes("cert-manager.io") ||
|
|
93
|
+
/kind:\s*["']?(?:Certificate|Issuer|ClusterIssuer)\b/.test(content);
|
|
94
|
+
const isIstio = content.includes("minProtocolVersion");
|
|
95
|
+
if (!isCertManager && !isIstio) return [];
|
|
96
|
+
|
|
97
|
+
// A `# algorithm: RSA` YAML comment is not an active setting; match over
|
|
98
|
+
// comment-masked content (offsets preserved).
|
|
99
|
+
const scan = maskCommentLines(content, ["#"]);
|
|
100
|
+
const findings: Finding[] = [];
|
|
101
|
+
const add = (re: RegExp, rule: RuleMeta) =>
|
|
102
|
+
eachMatch(re, scan, (m) =>
|
|
103
|
+
findings.push(
|
|
104
|
+
findingFromRule(rule, { file, content, index: m.index, matchLength: m[0].length }),
|
|
105
|
+
),
|
|
106
|
+
);
|
|
107
|
+
if (isCertManager) {
|
|
108
|
+
add(RE_CM_RSA, RULE_CM_RSA);
|
|
109
|
+
add(RE_CM_ECDSA, RULE_CM_ECDSA);
|
|
110
|
+
add(RE_CM_ED25519, RULE_CM_ED25519);
|
|
111
|
+
}
|
|
112
|
+
if (isIstio) add(RE_ISTIO_LEGACY_TLS, RULE_ISTIO_LEGACY_TLS);
|
|
113
|
+
return findings;
|
|
114
|
+
},
|
|
115
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config detector: classical cryptographic KEYSTORES committed to a repository —
|
|
3
|
+
* Java KeyStore (JKS), JCEKS, PKCS#12 (.p12/.pfx), and BouncyCastle (.bks). These
|
|
4
|
+
* binary containers hold private keys and certificate chains, essentially always
|
|
5
|
+
* classical (RSA / EC / DSA). A keystore in version control is committed key
|
|
6
|
+
* material: harvest-now-decrypt-later exposed and retroactively un-fixable.
|
|
7
|
+
*
|
|
8
|
+
* The scan pipeline reads these extensions byte-preserving (latin1; see
|
|
9
|
+
* {@link ../walk.ts isKeystorePath} and scan.ts), so `content.charCodeAt(i)` is the
|
|
10
|
+
* i-th file byte and we can identify the container by its magic number. We do NOT
|
|
11
|
+
* parse the enclosed key algorithm (that needs full ASN.1 / proprietary parsing);
|
|
12
|
+
* flagging the presence of a classical keystore is the actionable signal.
|
|
13
|
+
*
|
|
14
|
+
* The match is sensitive key material, so reporters drop the (binary) snippet.
|
|
15
|
+
*/
|
|
16
|
+
import type { Detector, Finding, RuleMeta } from "../types.js";
|
|
17
|
+
import { findingFromRule, hasExtension } from "../detect-utils.js";
|
|
18
|
+
import { CWE_HARDCODED_KEY } from "../cwe.js";
|
|
19
|
+
|
|
20
|
+
const KEYSTORE_EXTENSIONS: readonly string[] = [
|
|
21
|
+
".jks",
|
|
22
|
+
".keystore",
|
|
23
|
+
".jceks",
|
|
24
|
+
".bks",
|
|
25
|
+
".p12",
|
|
26
|
+
".pfx",
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
function baseRule(id: string, title: string, message: string): RuleMeta {
|
|
30
|
+
return {
|
|
31
|
+
id,
|
|
32
|
+
title,
|
|
33
|
+
description: message,
|
|
34
|
+
category: "certificate",
|
|
35
|
+
severity: "high",
|
|
36
|
+
confidence: "high",
|
|
37
|
+
hndl: true,
|
|
38
|
+
cwe: CWE_HARDCODED_KEY,
|
|
39
|
+
sensitive: true,
|
|
40
|
+
message,
|
|
41
|
+
remediation:
|
|
42
|
+
"Remove key material from version control and rotate it; store keys in a secret manager / HSM. Plan re-issuance with PQC keys (ML-DSA-65 / ML-KEM-768) as tooling supports it.",
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const RULE_JKS = baseRule(
|
|
47
|
+
"keystore-jks",
|
|
48
|
+
"Java KeyStore (JKS)",
|
|
49
|
+
"A Java KeyStore (JKS) holds classical private keys / certificates (RSA/EC/DSA); a keystore in version control is committed, harvest-now-decrypt-later exposed key material.",
|
|
50
|
+
);
|
|
51
|
+
const RULE_JCEKS = baseRule(
|
|
52
|
+
"keystore-jceks",
|
|
53
|
+
"Java JCEKS keystore",
|
|
54
|
+
"A JCEKS keystore holds classical key material (RSA/EC/DSA); committed to version control it is harvest-now-decrypt-later exposed.",
|
|
55
|
+
);
|
|
56
|
+
const RULE_PKCS12 = baseRule(
|
|
57
|
+
"keystore-pkcs12",
|
|
58
|
+
"PKCS#12 keystore",
|
|
59
|
+
"A PKCS#12 container (a `.p12`/`.pfx`, or a modern `.jks`/`.keystore` — keytool writes PKCS#12 by default since Java 9) holds classical private keys / certificate chains (RSA/EC); committed to version control it is harvest-now-decrypt-later exposed.",
|
|
60
|
+
);
|
|
61
|
+
const RULE_BKS = baseRule(
|
|
62
|
+
"keystore-bks",
|
|
63
|
+
"BouncyCastle keystore (.bks)",
|
|
64
|
+
"A BouncyCastle (.bks) keystore holds classical key material; committed to version control it is harvest-now-decrypt-later exposed.",
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
/** Bytes-equal check against `content` read as latin1 (charCodeAt == file byte). */
|
|
68
|
+
function magic(content: string, ...bytes: number[]): boolean {
|
|
69
|
+
if (content.length < bytes.length) return false;
|
|
70
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
71
|
+
if (content.charCodeAt(i) !== bytes[i]) return false;
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Detects committed classical keystores by magic number / extension. */
|
|
77
|
+
export const keystoreDetector: Detector = {
|
|
78
|
+
id: "keystore-material",
|
|
79
|
+
description: "Committed classical cryptographic keystores (JKS, JCEKS, PKCS#12, BKS)",
|
|
80
|
+
scope: "config",
|
|
81
|
+
language: "any",
|
|
82
|
+
rules: [RULE_JKS, RULE_JCEKS, RULE_PKCS12, RULE_BKS],
|
|
83
|
+
appliesTo: (f) => hasExtension(f, KEYSTORE_EXTENSIONS),
|
|
84
|
+
detect({ file, content }): Finding[] {
|
|
85
|
+
const at = { file, content, index: 0, matchLength: 4 };
|
|
86
|
+
// JKS: 0xFEEDFEED. JCEKS: 0xCECECECE.
|
|
87
|
+
if (magic(content, 0xfe, 0xed, 0xfe, 0xed)) return [findingFromRule(RULE_JKS, at)];
|
|
88
|
+
if (magic(content, 0xce, 0xce, 0xce, 0xce)) return [findingFromRule(RULE_JCEKS, at)];
|
|
89
|
+
// PKCS#12 is a DER SEQUENCE. Since Java 9, `keytool` writes PKCS#12 BY DEFAULT
|
|
90
|
+
// even for files named `.jks`/`.keystore` (and Android release keystores are
|
|
91
|
+
// PKCS#12), so this runs for ANY keystore extension once the JKS/JCEKS magics
|
|
92
|
+
// fail. Accept the long-form length octets 0x81/0x82/0x83 (real PKCS#12 is
|
|
93
|
+
// always >127 bytes, so short-form would be a false positive).
|
|
94
|
+
if (content.length >= 2 && content.charCodeAt(0) === 0x30) {
|
|
95
|
+
const lenOctet = content.charCodeAt(1);
|
|
96
|
+
// Long-form DER length (0x81/0x82/0x83) or BER indefinite length (0x80, emitted
|
|
97
|
+
// by NSS/Firefox .p12 exports). Short-form is excluded (real PKCS#12 is >127 B).
|
|
98
|
+
if (lenOctet === 0x80 || lenOctet === 0x81 || lenOctet === 0x82 || lenOctet === 0x83) {
|
|
99
|
+
return [findingFromRule(RULE_PKCS12, { ...at, matchLength: 2 })];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// BouncyCastle keystores have no stable magic; key off the extension, but
|
|
103
|
+
// require some content so an empty `.bks` placeholder does not fire.
|
|
104
|
+
if (file.toLowerCase().endsWith(".bks") && content.length > 0) {
|
|
105
|
+
return [findingFromRule(RULE_BKS, { ...at, matchLength: 1 })];
|
|
106
|
+
}
|
|
107
|
+
return [];
|
|
108
|
+
},
|
|
109
|
+
};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config detector: classical crypto in SERVICE MESH configuration — the
|
|
3
|
+
* control-plane identity/CA systems and mesh-internal TLS settings of
|
|
4
|
+
* Linkerd, HashiCorp Consul Connect, and Istio. These mint the mTLS identity
|
|
5
|
+
* certificates that secure sidecar-to-sidecar traffic and are configured in
|
|
6
|
+
* their own Helm values / HCL / CRD surfaces, distinct from what `k8s.ts`
|
|
7
|
+
* already covers (cert-manager `Certificate`/`Issuer` keys and Istio's
|
|
8
|
+
* `minProtocolVersion` TLS floor — NOT duplicated here).
|
|
9
|
+
*
|
|
10
|
+
* Covered (gated by a mesh marker in the document to keep generic keys like
|
|
11
|
+
* `scheme:` / `private_key_type` from firing on unrelated YAML/HCL):
|
|
12
|
+
* - Linkerd control-plane identity issuer: Helm values `identityTrustAnchorsPEM`
|
|
13
|
+
* and `identity.issuer.scheme` / nested `issuer.scheme: linkerd.io/tls` — the
|
|
14
|
+
* default self-managed Linkerd identity scheme, which mints workload
|
|
15
|
+
* certificates from an ECDSA P-256 trust anchor. Flagged as a classical mesh
|
|
16
|
+
* CA (certificate, ECDSA, hndl:false) since Linkerd's identity issuer signs
|
|
17
|
+
* forgeable-by-quantum leaf certs, not a confidentiality key.
|
|
18
|
+
* - HashiCorp Consul Connect: the `connect { ca_config { private_key_type =
|
|
19
|
+
* "ec" | "rsa" } } }` mesh CA provider setting (also `ca_provider`). Flagged
|
|
20
|
+
* as a classical mesh CA (certificate; ECDSA for "ec", RSA for "rsa").
|
|
21
|
+
* Istio `tls.cipherSuites:` `ECDHE-RSA-*` / `ECDHE-ECDSA-*` suites are NOT handled
|
|
22
|
+
* here — the language-agnostic `tls-classical-kex` token rule in `source.ts`
|
|
23
|
+
* already flags those cipher strings in any config file, so a rule here would
|
|
24
|
+
* double-count.
|
|
25
|
+
*/
|
|
26
|
+
import type { Detector, Finding, RuleMeta } from "../types.js";
|
|
27
|
+
import { eachMatch, findingFromRule, hasExtension, maskCommentLines } from "../detect-utils.js";
|
|
28
|
+
import { CWE_BROKEN_CRYPTO } from "../cwe.js";
|
|
29
|
+
|
|
30
|
+
// `.json` is included because Consul agent config is commonly JSON (the
|
|
31
|
+
// `private_key_type` rules already support the JSON `:` form); the content gates
|
|
32
|
+
// keep unrelated generic JSON/YAML out.
|
|
33
|
+
const MESH_EXTENSIONS: readonly string[] = [".yaml", ".yml", ".hcl", ".json"];
|
|
34
|
+
|
|
35
|
+
// Linkerd's default self-managed identity scheme (`linkerd.io/tls`, as opposed
|
|
36
|
+
// to a `kubernetes.io/tls` bring-your-own-cert secret) mints its trust anchor
|
|
37
|
+
// and issuer credentials as ECDSA P-256 by default. Matched in both nested
|
|
38
|
+
// YAML form (`scheme: linkerd.io/tls`) and the flattened Helm `--set`/values
|
|
39
|
+
// key form (`identity.issuer.scheme: linkerd.io/tls`), plus the distinctive
|
|
40
|
+
// `identityTrustAnchorsPEM` values key which only exists in Linkerd charts.
|
|
41
|
+
const RE_MESH_LINKERD_ECDSA =
|
|
42
|
+
/identityTrustAnchorsPEM\b|(?:identity\.issuer\.scheme|scheme)\s*[:=]\s*["']?linkerd\.io\/tls\b/g;
|
|
43
|
+
|
|
44
|
+
// Consul Connect's CA provider config: `private_key_type = "ec" | "rsa"`
|
|
45
|
+
// inside a `ca_config` block. Matched in both HCL (`=`) and JSON (`:`) forms,
|
|
46
|
+
// mirroring the terraform.ts attribute-matching convention.
|
|
47
|
+
const RE_MESH_CONSUL_RSA = /(?<![\w"-])"?private_key_type"?\s*[:=]\s*"rsa"/gi;
|
|
48
|
+
const RE_MESH_CONSUL_EC = /(?<![\w"-])"?private_key_type"?\s*[:=]\s*"ec"/gi;
|
|
49
|
+
|
|
50
|
+
const RULE_MESH_LINKERD_ECDSA: RuleMeta = {
|
|
51
|
+
id: "mesh-linkerd-identity-ecdsa",
|
|
52
|
+
title: "Linkerd ECDSA identity issuer",
|
|
53
|
+
description: "Linkerd control-plane identity issuer (default ECDSA P-256 mesh CA)",
|
|
54
|
+
category: "certificate",
|
|
55
|
+
severity: "medium",
|
|
56
|
+
confidence: "high",
|
|
57
|
+
algorithm: "ECDSA",
|
|
58
|
+
hndl: false,
|
|
59
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
60
|
+
message:
|
|
61
|
+
"Linkerd's control-plane identity issuer mints workload certificates from a classical ECDSA P-256 trust anchor by default, forgeable by a quantum attacker.",
|
|
62
|
+
remediation:
|
|
63
|
+
"Plan migration to ML-DSA-65 (FIPS 204) once Linkerd's identity issuer supports PQC signing.",
|
|
64
|
+
};
|
|
65
|
+
const RULE_MESH_CONSUL_RSA: RuleMeta = {
|
|
66
|
+
id: "mesh-consul-connect-rsa",
|
|
67
|
+
title: "Consul Connect RSA mesh CA",
|
|
68
|
+
description: 'Consul Connect ca_config private_key_type = "rsa"',
|
|
69
|
+
category: "certificate",
|
|
70
|
+
severity: "medium",
|
|
71
|
+
confidence: "high",
|
|
72
|
+
algorithm: "RSA",
|
|
73
|
+
hndl: true,
|
|
74
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
75
|
+
message:
|
|
76
|
+
"Consul Connect's mesh CA issues leaf certificates from a classical RSA private key, which is not quantum-safe.",
|
|
77
|
+
remediation:
|
|
78
|
+
"Plan migration to PQC certificate keys (ML-DSA-65) as the Connect CA provider adds support.",
|
|
79
|
+
};
|
|
80
|
+
const RULE_MESH_CONSUL_EC: RuleMeta = {
|
|
81
|
+
id: "mesh-consul-connect-ec",
|
|
82
|
+
title: "Consul Connect EC mesh CA",
|
|
83
|
+
description: 'Consul Connect ca_config private_key_type = "ec"',
|
|
84
|
+
category: "certificate",
|
|
85
|
+
severity: "medium",
|
|
86
|
+
confidence: "high",
|
|
87
|
+
algorithm: "ECDSA",
|
|
88
|
+
hndl: false,
|
|
89
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
90
|
+
message:
|
|
91
|
+
"Consul Connect's mesh CA issues leaf certificates from a classical EC private key, forgeable by a quantum attacker.",
|
|
92
|
+
remediation: "Plan migration to ML-DSA-65 (FIPS 204) as the Connect CA provider adds support.",
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Detects classical asymmetric crypto in service-mesh configuration: Linkerd's
|
|
96
|
+
* default ECDSA identity issuer and Consul Connect's mesh CA private key type.
|
|
97
|
+
* (Istio ECDHE cipher-suite strings are covered by `source.ts`'s
|
|
98
|
+
* `tls-classical-kex` token rule, so they are not duplicated here.)
|
|
99
|
+
*/
|
|
100
|
+
export const meshDetector: Detector = {
|
|
101
|
+
id: "service-mesh-crypto",
|
|
102
|
+
description: "Classical crypto in service-mesh config (Linkerd identity, Consul Connect CA)",
|
|
103
|
+
scope: "config",
|
|
104
|
+
language: "any",
|
|
105
|
+
rules: [RULE_MESH_LINKERD_ECDSA, RULE_MESH_CONSUL_RSA, RULE_MESH_CONSUL_EC],
|
|
106
|
+
appliesTo: (f) => hasExtension(f, MESH_EXTENSIONS),
|
|
107
|
+
detect({ file, content }): Finding[] {
|
|
108
|
+
const isLinkerd = content.includes("linkerd") || content.includes("identityTrustAnchors");
|
|
109
|
+
const isConsulConnect = content.includes("consul") && content.includes("connect");
|
|
110
|
+
if (!isLinkerd && !isConsulConnect) return [];
|
|
111
|
+
|
|
112
|
+
// Mask whole comment lines (YAML/HCL `#`, HCL/JSON5 `//`) so a commented-out
|
|
113
|
+
// directive can't fire — `.yaml`/`.hcl`/`.json` are not centrally stripped.
|
|
114
|
+
// Offsets are preserved, so the finding location stays exact.
|
|
115
|
+
const scan = maskCommentLines(content, ["#", "//"]);
|
|
116
|
+
const findings: Finding[] = [];
|
|
117
|
+
const add = (re: RegExp, rule: RuleMeta) =>
|
|
118
|
+
eachMatch(re, scan, (m) =>
|
|
119
|
+
findings.push(
|
|
120
|
+
findingFromRule(rule, { file, content, index: m.index, matchLength: m[0].length }),
|
|
121
|
+
),
|
|
122
|
+
);
|
|
123
|
+
if (isLinkerd) add(RE_MESH_LINKERD_ECDSA, RULE_MESH_LINKERD_ECDSA);
|
|
124
|
+
if (isConsulConnect) {
|
|
125
|
+
add(RE_MESH_CONSUL_RSA, RULE_MESH_CONSUL_RSA);
|
|
126
|
+
add(RE_MESH_CONSUL_EC, RULE_MESH_CONSUL_EC);
|
|
127
|
+
}
|
|
128
|
+
return findings;
|
|
129
|
+
},
|
|
130
|
+
};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config detector: classical transport crypto in message brokers / event streams
|
|
3
|
+
* (Kafka, RabbitMQ, MQTT/Mosquitto, NATS). Broker traffic is "communication
|
|
4
|
+
* between things"; a legacy TLS floor or a classical (EC)DHE cipher suite makes
|
|
5
|
+
* every message in flight harvest-now-decrypt-later exposed.
|
|
6
|
+
*
|
|
7
|
+
* Covered in broker config files (`.properties`, `.conf`, `.cfg`, `.ini`):
|
|
8
|
+
* - Kafka `ssl.protocol` / `ssl.enabled.protocols = TLSv1 | TLSv1.1` (legacy).
|
|
9
|
+
* - MQTT/Mosquitto `tls_version tlsv1 | tlsv1.1` (legacy).
|
|
10
|
+
* - Kafka `ssl.cipher.suites` naming a static-RSA `TLS_RSA_WITH_*` key-transport
|
|
11
|
+
* suite (the ECDHE/DHE suites are owned by source.ts's `tls-classical-kex`).
|
|
12
|
+
*/
|
|
13
|
+
import type { Detector, Finding, RuleMeta } from "../types.js";
|
|
14
|
+
import { eachMatch, findingFromRule, hasExtension, maskCommentLines } from "../detect-utils.js";
|
|
15
|
+
import { CWE_RISKY_PRIMITIVE, CWE_BROKEN_CRYPTO } from "../cwe.js";
|
|
16
|
+
|
|
17
|
+
const MQ_EXTENSIONS: readonly string[] = [".properties", ".conf", ".cfg", ".ini"];
|
|
18
|
+
|
|
19
|
+
interface MqRule {
|
|
20
|
+
re: RegExp;
|
|
21
|
+
meta: RuleMeta;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const MQ_RULES: MqRule[] = [
|
|
25
|
+
{
|
|
26
|
+
// Match TLSv1 (=1.0) and TLSv1.1 but never TLSv1.2 / TLSv1.3: the negative
|
|
27
|
+
// lookahead stops "TLSv1" from matching the "TLSv1" inside "TLSv1.3".
|
|
28
|
+
re: /\bssl\.(?:enabled\.)?protocols?\s*=\s*[^\n]{0,80}?\bTLSv1(?:\.1)?(?![.\d])/gi,
|
|
29
|
+
meta: {
|
|
30
|
+
id: "mq-kafka-legacy-tls",
|
|
31
|
+
title: "Kafka legacy TLS protocol",
|
|
32
|
+
description: "Kafka ssl.protocol / ssl.enabled.protocols permits TLS 1.0 / 1.1",
|
|
33
|
+
category: "tls",
|
|
34
|
+
severity: "medium",
|
|
35
|
+
confidence: "high",
|
|
36
|
+
hndl: false,
|
|
37
|
+
cwe: CWE_RISKY_PRIMITIVE,
|
|
38
|
+
message:
|
|
39
|
+
"Kafka broker permits legacy TLS 1.0/1.1, an obsolete protocol; require TLS 1.3 (the harvestable classical key exchange is reported separately by the cipher-suite rule).",
|
|
40
|
+
remediation: "Require TLS 1.3 and track PQC-hybrid KEX (X25519MLKEM768).",
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
re: /\btls_version\s+tlsv1(?:\.1)?(?![.\d])/gi,
|
|
45
|
+
meta: {
|
|
46
|
+
id: "mq-mqtt-legacy-tls",
|
|
47
|
+
title: "MQTT legacy TLS version",
|
|
48
|
+
description: "Mosquitto/MQTT tls_version permits TLS 1.0 / 1.1",
|
|
49
|
+
category: "tls",
|
|
50
|
+
severity: "medium",
|
|
51
|
+
confidence: "high",
|
|
52
|
+
hndl: false,
|
|
53
|
+
cwe: CWE_RISKY_PRIMITIVE,
|
|
54
|
+
message:
|
|
55
|
+
"MQTT broker permits legacy TLS 1.0/1.1, an obsolete protocol; require TLS 1.3 (the harvestable classical key exchange is reported separately).",
|
|
56
|
+
remediation: "Require TLS 1.3 and track PQC-hybrid KEX for device fleets.",
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
// Only static-RSA key transport (`TLS_RSA_WITH_…`) is flagged here: the ECDHE /
|
|
61
|
+
// DHE suites are owned by source.ts's language-agnostic `tls-classical-kex` token
|
|
62
|
+
// rule (which fires on `.properties` too), so flagging them here would double-count.
|
|
63
|
+
re: /\bssl\.cipher\.suites\s*=\s*[^\n]{0,200}?\bTLS_RSA_WITH_/g,
|
|
64
|
+
meta: {
|
|
65
|
+
id: "mq-rsa-key-transport",
|
|
66
|
+
title: "Broker static-RSA key transport cipher",
|
|
67
|
+
description:
|
|
68
|
+
"Kafka ssl.cipher.suites names a static-RSA (TLS_RSA_WITH_*) key-transport suite",
|
|
69
|
+
category: "kem",
|
|
70
|
+
algorithm: "RSA",
|
|
71
|
+
severity: "medium",
|
|
72
|
+
confidence: "high",
|
|
73
|
+
hndl: true,
|
|
74
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
75
|
+
message:
|
|
76
|
+
"Broker TLS is pinned to a static-RSA (TLS_RSA_WITH_*) key-transport suite; the wrapped session key is harvest-now-decrypt-later exposed (and it has no forward secrecy).",
|
|
77
|
+
remediation:
|
|
78
|
+
"Move to TLS 1.3 with a PQC-hybrid group (X25519MLKEM768) once the broker/runtime supports it.",
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
];
|
|
82
|
+
|
|
83
|
+
/** Detects classical transport crypto in message-broker / event-stream config. */
|
|
84
|
+
export const messagingDetector: Detector = {
|
|
85
|
+
id: "messaging-transport",
|
|
86
|
+
description: "Classical transport crypto in message brokers (Kafka, MQTT, RabbitMQ, NATS)",
|
|
87
|
+
scope: "config",
|
|
88
|
+
language: "any",
|
|
89
|
+
rules: MQ_RULES.map((r) => r.meta),
|
|
90
|
+
appliesTo: (f) => hasExtension(f, MQ_EXTENSIONS),
|
|
91
|
+
detect({ file, content }): Finding[] {
|
|
92
|
+
const findings: Finding[] = [];
|
|
93
|
+
// Broker config files ship large commented-out example blocks; a commented
|
|
94
|
+
// directive is not active. Match over comment-masked content (offsets preserved,
|
|
95
|
+
// so the snippet from the original `content` is still correct).
|
|
96
|
+
const scan = maskCommentLines(content, ["#", "!", ";"]);
|
|
97
|
+
for (const rule of MQ_RULES) {
|
|
98
|
+
eachMatch(rule.re, scan, (m) => {
|
|
99
|
+
findings.push(
|
|
100
|
+
findingFromRule(rule.meta, { file, content, index: m.index, matchLength: m[0].length }),
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return findings;
|
|
105
|
+
},
|
|
106
|
+
};
|