@quantakrypto/core 0.4.3 → 0.4.4

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.
Files changed (163) hide show
  1. package/dist/cbom-merge.d.ts +9 -0
  2. package/dist/cbom-merge.d.ts.map +1 -0
  3. package/dist/cbom-merge.js +99 -0
  4. package/dist/cbom-merge.js.map +1 -0
  5. package/dist/comments.d.ts +4 -3
  6. package/dist/comments.d.ts.map +1 -1
  7. package/dist/comments.js +53 -33
  8. package/dist/comments.js.map +1 -1
  9. package/dist/dependencies.d.ts.map +1 -1
  10. package/dist/dependencies.js +1 -1
  11. package/dist/dependencies.js.map +1 -1
  12. package/dist/detect-utils.d.ts +5 -1
  13. package/dist/detect-utils.d.ts.map +1 -1
  14. package/dist/detect-utils.js +11 -2
  15. package/dist/detect-utils.js.map +1 -1
  16. package/dist/detectors/c.d.ts +4 -2
  17. package/dist/detectors/c.d.ts.map +1 -1
  18. package/dist/detectors/c.js +192 -1
  19. package/dist/detectors/c.js.map +1 -1
  20. package/dist/detectors/cicd.d.ts +27 -0
  21. package/dist/detectors/cicd.d.ts.map +1 -0
  22. package/dist/detectors/cicd.js +116 -0
  23. package/dist/detectors/cicd.js.map +1 -0
  24. package/dist/detectors/cloud-kms.d.ts +21 -0
  25. package/dist/detectors/cloud-kms.d.ts.map +1 -0
  26. package/dist/detectors/cloud-kms.js +57 -0
  27. package/dist/detectors/cloud-kms.js.map +1 -0
  28. package/dist/detectors/cloudformation.d.ts +30 -0
  29. package/dist/detectors/cloudformation.d.ts.map +1 -0
  30. package/dist/detectors/cloudformation.js +170 -0
  31. package/dist/detectors/cloudformation.js.map +1 -0
  32. package/dist/detectors/database.d.ts +17 -0
  33. package/dist/detectors/database.d.ts.map +1 -0
  34. package/dist/detectors/database.js +60 -0
  35. package/dist/detectors/database.js.map +1 -0
  36. package/dist/detectors/dnssec.d.ts +55 -0
  37. package/dist/detectors/dnssec.d.ts.map +1 -0
  38. package/dist/detectors/dnssec.js +107 -0
  39. package/dist/detectors/dnssec.js.map +1 -0
  40. package/dist/detectors/elixir.d.ts +20 -0
  41. package/dist/detectors/elixir.d.ts.map +1 -0
  42. package/dist/detectors/elixir.js +195 -0
  43. package/dist/detectors/elixir.js.map +1 -0
  44. package/dist/detectors/java.d.ts.map +1 -1
  45. package/dist/detectors/java.js +1 -1
  46. package/dist/detectors/java.js.map +1 -1
  47. package/dist/detectors/jose.d.ts +20 -0
  48. package/dist/detectors/jose.d.ts.map +1 -0
  49. package/dist/detectors/jose.js +62 -0
  50. package/dist/detectors/jose.js.map +1 -0
  51. package/dist/detectors/jwk.d.ts +25 -0
  52. package/dist/detectors/jwk.d.ts.map +1 -0
  53. package/dist/detectors/jwk.js +95 -0
  54. package/dist/detectors/jwk.js.map +1 -0
  55. package/dist/detectors/k8s.d.ts +17 -0
  56. package/dist/detectors/k8s.d.ts.map +1 -0
  57. package/dist/detectors/k8s.js +85 -0
  58. package/dist/detectors/k8s.js.map +1 -0
  59. package/dist/detectors/mesh.d.ts +35 -0
  60. package/dist/detectors/mesh.d.ts.map +1 -0
  61. package/dist/detectors/mesh.js +109 -0
  62. package/dist/detectors/mesh.js.map +1 -0
  63. package/dist/detectors/messaging.d.ts +16 -0
  64. package/dist/detectors/messaging.d.ts.map +1 -0
  65. package/dist/detectors/messaging.js +72 -0
  66. package/dist/detectors/messaging.js.map +1 -0
  67. package/dist/detectors/pem.js +1 -1
  68. package/dist/detectors/pem.js.map +1 -1
  69. package/dist/detectors/php.d.ts +24 -0
  70. package/dist/detectors/php.d.ts.map +1 -0
  71. package/dist/detectors/php.js +167 -0
  72. package/dist/detectors/php.js.map +1 -0
  73. package/dist/detectors/python.d.ts.map +1 -1
  74. package/dist/detectors/python.js +70 -0
  75. package/dist/detectors/python.js.map +1 -1
  76. package/dist/detectors/rust.d.ts.map +1 -1
  77. package/dist/detectors/rust.js +68 -0
  78. package/dist/detectors/rust.js.map +1 -1
  79. package/dist/detectors/secrets.d.ts +21 -0
  80. package/dist/detectors/secrets.d.ts.map +1 -0
  81. package/dist/detectors/secrets.js +79 -0
  82. package/dist/detectors/secrets.js.map +1 -0
  83. package/dist/detectors/source.d.ts.map +1 -1
  84. package/dist/detectors/source.js +190 -47
  85. package/dist/detectors/source.js.map +1 -1
  86. package/dist/detectors/stateful-hbs.d.ts.map +1 -1
  87. package/dist/detectors/stateful-hbs.js +9 -6
  88. package/dist/detectors/stateful-hbs.js.map +1 -1
  89. package/dist/detectors/terraform.d.ts +21 -0
  90. package/dist/detectors/terraform.d.ts.map +1 -0
  91. package/dist/detectors/terraform.js +123 -0
  92. package/dist/detectors/terraform.js.map +1 -0
  93. package/dist/detectors/vpn.d.ts +22 -0
  94. package/dist/detectors/vpn.d.ts.map +1 -0
  95. package/dist/detectors/vpn.js +99 -0
  96. package/dist/detectors/vpn.js.map +1 -0
  97. package/dist/evidence.d.ts +5 -0
  98. package/dist/evidence.d.ts.map +1 -1
  99. package/dist/evidence.js +5 -0
  100. package/dist/evidence.js.map +1 -1
  101. package/dist/index.d.ts +5 -0
  102. package/dist/index.d.ts.map +1 -1
  103. package/dist/index.js +6 -0
  104. package/dist/index.js.map +1 -1
  105. package/dist/policy.d.ts +67 -0
  106. package/dist/policy.d.ts.map +1 -0
  107. package/dist/policy.js +115 -0
  108. package/dist/policy.js.map +1 -0
  109. package/dist/registry.d.ts.map +1 -1
  110. package/dist/registry.js +30 -0
  111. package/dist/registry.js.map +1 -1
  112. package/dist/remediate-pipeline.d.ts.map +1 -1
  113. package/dist/remediate-pipeline.js +22 -1
  114. package/dist/remediate-pipeline.js.map +1 -1
  115. package/dist/report.d.ts.map +1 -1
  116. package/dist/report.js +7 -0
  117. package/dist/report.js.map +1 -1
  118. package/dist/standards.d.ts +96 -0
  119. package/dist/standards.d.ts.map +1 -0
  120. package/dist/standards.js +107 -0
  121. package/dist/standards.js.map +1 -0
  122. package/dist/types.d.ts +1 -1
  123. package/dist/types.d.ts.map +1 -1
  124. package/dist/types.js.map +1 -1
  125. package/dist/version.d.ts +1 -1
  126. package/dist/version.js +1 -1
  127. package/dist/version.js.map +1 -1
  128. package/package.json +1 -1
  129. package/src/cbom-merge.ts +116 -0
  130. package/src/comments.ts +59 -33
  131. package/src/dependencies.ts +2 -1
  132. package/src/detect-utils.ts +14 -2
  133. package/src/detectors/c.ts +209 -3
  134. package/src/detectors/cicd.ts +158 -0
  135. package/src/detectors/cloud-kms.ts +87 -0
  136. package/src/detectors/cloudformation.ts +215 -0
  137. package/src/detectors/database.ts +88 -0
  138. package/src/detectors/dnssec.ts +186 -0
  139. package/src/detectors/elixir.ts +237 -0
  140. package/src/detectors/java.ts +2 -1
  141. package/src/detectors/jose.ts +94 -0
  142. package/src/detectors/jwk.ts +128 -0
  143. package/src/detectors/k8s.ts +112 -0
  144. package/src/detectors/mesh.ts +154 -0
  145. package/src/detectors/messaging.ts +98 -0
  146. package/src/detectors/pem.ts +1 -1
  147. package/src/detectors/php.ts +225 -0
  148. package/src/detectors/python.ts +71 -0
  149. package/src/detectors/rust.ts +71 -0
  150. package/src/detectors/secrets.ts +114 -0
  151. package/src/detectors/source.ts +235 -68
  152. package/src/detectors/stateful-hbs.ts +9 -6
  153. package/src/detectors/terraform.ts +154 -0
  154. package/src/detectors/vpn.ts +131 -0
  155. package/src/evidence.ts +11 -0
  156. package/src/index.ts +10 -0
  157. package/src/policy.ts +180 -0
  158. package/src/registry.ts +30 -0
  159. package/src/remediate-pipeline.ts +25 -2
  160. package/src/report.ts +7 -0
  161. package/src/standards.ts +186 -0
  162. package/src/types.ts +2 -0
  163. package/src/version.ts +1 -1
@@ -0,0 +1,195 @@
1
+ import { ELIXIR_EXTENSIONS, eachMatch, findingFromRule, hasExtension } from "../detect-utils.js";
2
+ import { CWE_BROKEN_CRYPTO } from "../cwe.js";
3
+ const RE_EX_GEN = /:crypto\.generate_key\s*\(\s*:(\w+)/g;
4
+ const RE_EX_SIGN = /:crypto\.(?:sign|verify)\s*\(\s*:(\w+)/g;
5
+ const RE_EX_X509_RSA = /\bX509\.PrivateKey\.new_rsa\s*\(/g;
6
+ const RE_EX_X509_EC = /\bX509\.PrivateKey\.new_ec\s*\(/g;
7
+ const RE_EX_JOSE = /\bJOSE\.JWK\.generate_key\s*\(\s*\{\s*:(\w+)/g;
8
+ const SIG_REM = "ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)";
9
+ const KEX_REM = "hybrid X25519MLKEM768 (ML-KEM-768)";
10
+ const RULE_EX_KEYGEN = {
11
+ id: "elixir-crypto-keygen",
12
+ title: "Elixir :crypto key generation",
13
+ description: ":crypto.generate_key (rsa/ecdh/dh/eddsa)",
14
+ category: "kem",
15
+ severity: "high",
16
+ confidence: "high",
17
+ algorithm: "RSA",
18
+ hndl: true,
19
+ cwe: CWE_BROKEN_CRYPTO,
20
+ message: "Generates a classical key pair via Erlang :crypto (Elixir) — not quantum-safe.",
21
+ };
22
+ const RULE_EX_SIGN = {
23
+ id: "elixir-crypto-sign",
24
+ title: "Elixir :crypto signature",
25
+ description: ":crypto.sign / :crypto.verify (rsa/ecdsa/eddsa)",
26
+ category: "signature",
27
+ severity: "high",
28
+ confidence: "high",
29
+ algorithm: "unknown",
30
+ hndl: false,
31
+ cwe: CWE_BROKEN_CRYPTO,
32
+ message: "Classical signature via Erlang :crypto (Elixir) is forgeable by a quantum attacker.",
33
+ remediation: SIG_REM,
34
+ };
35
+ const RULE_EX_X509 = {
36
+ id: "elixir-x509-keygen",
37
+ title: "Elixir X509 key generation",
38
+ description: "X509.PrivateKey.new_rsa / new_ec",
39
+ category: "kem",
40
+ severity: "high",
41
+ confidence: "high",
42
+ algorithm: "RSA",
43
+ hndl: true,
44
+ cwe: CWE_BROKEN_CRYPTO,
45
+ message: "Generates a classical key pair via the X509 library (Elixir) — not quantum-safe.",
46
+ };
47
+ const RULE_EX_JOSE = {
48
+ id: "elixir-jose-jwk",
49
+ title: "Elixir JOSE JWK generation",
50
+ description: "JOSE.JWK.generate_key ({:rsa|:ec|:okp})",
51
+ category: "kem",
52
+ severity: "high",
53
+ confidence: "high",
54
+ algorithm: "RSA",
55
+ hndl: true,
56
+ cwe: CWE_BROKEN_CRYPTO,
57
+ message: "Generates a classical JWK via JOSE (Elixir) — not quantum-safe.",
58
+ };
59
+ const RSA_CLS = { algo: "RSA", cat: "kem", sev: "high", hndl: true, label: "RSA" };
60
+ const DH_CLS = { algo: "DH", cat: "key-exchange", sev: "high", hndl: true, label: "DH" };
61
+ const ECDH_CLS = {
62
+ algo: "ECDH",
63
+ cat: "key-exchange",
64
+ sev: "high",
65
+ hndl: true,
66
+ label: "ECDH",
67
+ remediation: KEX_REM,
68
+ };
69
+ const X25519_CLS = {
70
+ algo: "X25519",
71
+ cat: "key-exchange",
72
+ sev: "medium",
73
+ hndl: true,
74
+ label: "X25519",
75
+ remediation: KEX_REM,
76
+ };
77
+ const X448_CLS = { ...X25519_CLS, algo: "X448", label: "X448" };
78
+ const EDDSA_CLS = {
79
+ algo: "EdDSA",
80
+ cat: "signature",
81
+ sev: "low",
82
+ hndl: false,
83
+ label: "EdDSA",
84
+ remediation: SIG_REM,
85
+ };
86
+ const EC_CLS = {
87
+ algo: "ECDH",
88
+ cat: "key-exchange",
89
+ sev: "high",
90
+ hndl: true,
91
+ label: "EC (ECDSA/ECDH)",
92
+ remediation: KEX_REM,
93
+ };
94
+ /** Classify a `:crypto.generate_key(:<type>, …)` by its type atom (+ the curve
95
+ * atom in a short window for the ecdh X25519/X448 case). */
96
+ function classifyGen(type, window) {
97
+ switch (type) {
98
+ case "rsa":
99
+ return RSA_CLS;
100
+ case "dh":
101
+ return DH_CLS;
102
+ case "eddsa":
103
+ case "ed25519":
104
+ return EDDSA_CLS;
105
+ case "ecdh":
106
+ if (/:x25519\b/i.test(window))
107
+ return X25519_CLS;
108
+ if (/:x448\b/i.test(window))
109
+ return X448_CLS;
110
+ return ECDH_CLS;
111
+ default:
112
+ return null; // srp / other non-broken-in-this-model types
113
+ }
114
+ }
115
+ /** Signature algorithm classification for `:crypto.sign(:<type>, …)`. */
116
+ function classifySign(type) {
117
+ if (type === "rsa")
118
+ return "RSA";
119
+ if (type === "ecdsa")
120
+ return "ECDSA";
121
+ if (type === "eddsa" || type === "ed25519")
122
+ return "EdDSA";
123
+ return null;
124
+ }
125
+ /** Detects classical asymmetric crypto in Elixir (:crypto, X509, JOSE). */
126
+ export const elixirDetector = {
127
+ id: "elixir-crypto",
128
+ description: "Classical asymmetric crypto in Elixir (:crypto, X509, JOSE)",
129
+ scope: "source",
130
+ language: "elixir",
131
+ rules: [RULE_EX_KEYGEN, RULE_EX_SIGN, RULE_EX_X509, RULE_EX_JOSE],
132
+ appliesTo: (f) => hasExtension(f, ELIXIR_EXTENSIONS),
133
+ detect({ file, content }) {
134
+ const findings = [];
135
+ const at = (m) => ({
136
+ file,
137
+ content,
138
+ index: m.index,
139
+ matchLength: m[0].length,
140
+ });
141
+ // :crypto.generate_key(:type, …) — classify by the type atom (+ curve window).
142
+ eachMatch(RE_EX_GEN, content, (m) => {
143
+ const cls = classifyGen(m[1], content.slice(m.index, m.index + 80));
144
+ if (!cls)
145
+ return;
146
+ findings.push(findingFromRule(RULE_EX_KEYGEN, at(m), {
147
+ title: `Elixir :crypto ${cls.label} key generation`,
148
+ category: cls.cat,
149
+ severity: cls.sev,
150
+ algorithm: cls.algo,
151
+ hndl: cls.hndl,
152
+ message: `Generates a classical ${cls.label} key pair via Erlang :crypto (Elixir) — not quantum-safe.`,
153
+ ...(cls.remediation ? { remediation: cls.remediation } : {}),
154
+ }));
155
+ });
156
+ // :crypto.sign / :crypto.verify(:type, …).
157
+ eachMatch(RE_EX_SIGN, content, (m) => {
158
+ const algo = classifySign(m[1]);
159
+ if (!algo)
160
+ return;
161
+ findings.push(findingFromRule(RULE_EX_SIGN, at(m), {
162
+ algorithm: algo,
163
+ message: `Classical ${algo} signature via Erlang :crypto (Elixir) is forgeable by a quantum attacker.`,
164
+ }));
165
+ });
166
+ // X509.PrivateKey.new_rsa / new_ec.
167
+ eachMatch(RE_EX_X509_RSA, content, (m) => findings.push(findingFromRule(RULE_EX_X509, at(m), { algorithm: "RSA" })));
168
+ eachMatch(RE_EX_X509_EC, content, (m) => findings.push(findingFromRule(RULE_EX_X509, at(m), {
169
+ title: "Elixir X509 EC key generation",
170
+ category: EC_CLS.cat,
171
+ algorithm: EC_CLS.algo,
172
+ hndl: EC_CLS.hndl,
173
+ message: "Generates a classical EC key pair via the X509 library (Elixir); EC keys feed BOTH ECDSA and ECDH.",
174
+ remediation: KEX_REM,
175
+ })));
176
+ // JOSE.JWK.generate_key({:rsa|:ec|:okp, …}).
177
+ eachMatch(RE_EX_JOSE, content, (m) => {
178
+ const kind = m[1];
179
+ const cls = kind === "rsa" ? RSA_CLS : kind === "ec" ? EC_CLS : kind === "okp" ? EDDSA_CLS : null;
180
+ if (!cls)
181
+ return;
182
+ findings.push(findingFromRule(RULE_EX_JOSE, at(m), {
183
+ title: `Elixir JOSE ${cls.label} JWK`,
184
+ category: cls.cat,
185
+ severity: cls.sev,
186
+ algorithm: cls.algo,
187
+ hndl: cls.hndl,
188
+ message: `Generates a classical ${cls.label} JWK via JOSE (Elixir) — not quantum-safe.`,
189
+ ...(cls.remediation ? { remediation: cls.remediation } : {}),
190
+ }));
191
+ });
192
+ return findings;
193
+ },
194
+ };
195
+ //# sourceMappingURL=elixir.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elixir.js","sourceRoot":"","sources":["../../src/detectors/elixir.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACjG,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C,MAAM,SAAS,GAAG,sCAAsC,CAAC;AACzD,MAAM,UAAU,GAAG,yCAAyC,CAAC;AAC7D,MAAM,cAAc,GAAG,mCAAmC,CAAC;AAC3D,MAAM,aAAa,GAAG,kCAAkC,CAAC;AACzD,MAAM,UAAU,GA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,GAAG,CAAC,IAAI;gBACnB,IAAI,EAAE,GAAG,CAAC,IAAI;gBACd,OAAO,EAAE,yBAAyB,GAAG,CAAC,KAAK,4CAA4C;gBACvF,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAC7D,CAAC,CACH,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC","sourcesContent":["/**\n * Source-code detector for classical asymmetric cryptography in Elixir (the BEAM\n * / Phoenix ecosystem), previously uncovered. Handles the three common surfaces:\n *\n * - **Erlang `:crypto`** — `:crypto.generate_key(:rsa|:ecdh|:dh|:eddsa, …)`\n * (the curve atom disambiguates X25519/X448 from a generic ECDH curve) and\n * `:crypto.sign/:crypto.verify(:rsa|:ecdsa|:eddsa, …)`.\n * - **`X509`** (the `x509` hex package) — `X509.PrivateKey.new_rsa` / `new_ec`.\n * - **`JOSE`** (erlang-jose) — `JOSE.JWK.generate_key({:rsa|:ec|:okp, …})`.\n *\n * Lexical, like the other packs; the `:crypto.` atom-module syntax and the\n * `X509.` / `JOSE.` module paths are distinctive, so the false-positive rate is low.\n *\n * HNDL: RSA and (EC/X)DH key agreement are harvest-now-decrypt-later exposed\n * (hndl:true); ECDSA / EdDSA signatures are hndl:false but forgeable.\n */\nimport type { AlgorithmFamily, Detector, Finding, RuleMeta } from \"../types.js\";\nimport { ELIXIR_EXTENSIONS, eachMatch, findingFromRule, hasExtension } from \"../detect-utils.js\";\nimport { CWE_BROKEN_CRYPTO } from \"../cwe.js\";\n\nconst RE_EX_GEN = /:crypto\\.generate_key\\s*\\(\\s*:(\\w+)/g;\nconst RE_EX_SIGN = /:crypto\\.(?:sign|verify)\\s*\\(\\s*:(\\w+)/g;\nconst RE_EX_X509_RSA = /\\bX509\\.PrivateKey\\.new_rsa\\s*\\(/g;\nconst RE_EX_X509_EC = /\\bX509\\.PrivateKey\\.new_ec\\s*\\(/g;\nconst RE_EX_JOSE = /\\bJOSE\\.JWK\\.generate_key\\s*\\(\\s*\\{\\s*:(\\w+)/g;\n\ninterface Cls {\n algo: AlgorithmFamily;\n cat: Finding[\"category\"];\n sev: Finding[\"severity\"];\n hndl: boolean;\n label: string;\n remediation?: string;\n}\nconst SIG_REM = \"ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)\";\nconst KEX_REM = \"hybrid X25519MLKEM768 (ML-KEM-768)\";\n\nconst RULE_EX_KEYGEN: RuleMeta = {\n id: \"elixir-crypto-keygen\",\n title: \"Elixir :crypto key generation\",\n description: \":crypto.generate_key (rsa/ecdh/dh/eddsa)\",\n category: \"kem\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Generates a classical key pair via Erlang :crypto (Elixir) — not quantum-safe.\",\n};\nconst RULE_EX_SIGN: RuleMeta = {\n id: \"elixir-crypto-sign\",\n title: \"Elixir :crypto signature\",\n description: \":crypto.sign / :crypto.verify (rsa/ecdsa/eddsa)\",\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"unknown\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Classical signature via Erlang :crypto (Elixir) is forgeable by a quantum attacker.\",\n remediation: SIG_REM,\n};\nconst RULE_EX_X509: RuleMeta = {\n id: \"elixir-x509-keygen\",\n title: \"Elixir X509 key generation\",\n description: \"X509.PrivateKey.new_rsa / new_ec\",\n category: \"kem\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Generates a classical key pair via the X509 library (Elixir) — not quantum-safe.\",\n};\nconst RULE_EX_JOSE: RuleMeta = {\n id: \"elixir-jose-jwk\",\n title: \"Elixir JOSE JWK generation\",\n description: \"JOSE.JWK.generate_key ({:rsa|:ec|:okp})\",\n category: \"kem\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Generates a classical JWK via JOSE (Elixir) — not quantum-safe.\",\n};\n\nconst RSA_CLS: Cls = { algo: \"RSA\", cat: \"kem\", sev: \"high\", hndl: true, label: \"RSA\" };\nconst DH_CLS: Cls = { algo: \"DH\", cat: \"key-exchange\", sev: \"high\", hndl: true, label: \"DH\" };\nconst ECDH_CLS: Cls = {\n algo: \"ECDH\",\n cat: \"key-exchange\",\n sev: \"high\",\n hndl: true,\n label: \"ECDH\",\n remediation: KEX_REM,\n};\nconst X25519_CLS: Cls = {\n algo: \"X25519\",\n cat: \"key-exchange\",\n sev: \"medium\",\n hndl: true,\n label: \"X25519\",\n remediation: KEX_REM,\n};\nconst X448_CLS: Cls = { ...X25519_CLS, algo: \"X448\", label: \"X448\" };\nconst EDDSA_CLS: Cls = {\n algo: \"EdDSA\",\n cat: \"signature\",\n sev: \"low\",\n hndl: false,\n label: \"EdDSA\",\n remediation: SIG_REM,\n};\nconst EC_CLS: Cls = {\n algo: \"ECDH\",\n cat: \"key-exchange\",\n sev: \"high\",\n hndl: true,\n label: \"EC (ECDSA/ECDH)\",\n remediation: KEX_REM,\n};\n\n/** Classify a `:crypto.generate_key(:<type>, …)` by its type atom (+ the curve\n * atom in a short window for the ecdh X25519/X448 case). */\nfunction classifyGen(type: string, window: string): Cls | null {\n switch (type) {\n case \"rsa\":\n return RSA_CLS;\n case \"dh\":\n return DH_CLS;\n case \"eddsa\":\n case \"ed25519\":\n return EDDSA_CLS;\n case \"ecdh\":\n if (/:x25519\\b/i.test(window)) return X25519_CLS;\n if (/:x448\\b/i.test(window)) return X448_CLS;\n return ECDH_CLS;\n default:\n return null; // srp / other non-broken-in-this-model types\n }\n}\n\n/** Signature algorithm classification for `:crypto.sign(:<type>, …)`. */\nfunction classifySign(type: string): AlgorithmFamily | null {\n if (type === \"rsa\") return \"RSA\";\n if (type === \"ecdsa\") return \"ECDSA\";\n if (type === \"eddsa\" || type === \"ed25519\") return \"EdDSA\";\n return null;\n}\n\n/** Detects classical asymmetric crypto in Elixir (:crypto, X509, JOSE). */\nexport const elixirDetector: Detector = {\n id: \"elixir-crypto\",\n description: \"Classical asymmetric crypto in Elixir (:crypto, X509, JOSE)\",\n scope: \"source\",\n language: \"elixir\",\n rules: [RULE_EX_KEYGEN, RULE_EX_SIGN, RULE_EX_X509, RULE_EX_JOSE],\n appliesTo: (f) => hasExtension(f, ELIXIR_EXTENSIONS),\n detect({ file, content }): Finding[] {\n const findings: Finding[] = [];\n const at = (m: RegExpExecArray) => ({\n file,\n content,\n index: m.index,\n matchLength: m[0].length,\n });\n\n // :crypto.generate_key(:type, …) — classify by the type atom (+ curve window).\n eachMatch(RE_EX_GEN, content, (m) => {\n const cls = classifyGen(m[1], content.slice(m.index, m.index + 80));\n if (!cls) return;\n findings.push(\n findingFromRule(RULE_EX_KEYGEN, at(m), {\n title: `Elixir :crypto ${cls.label} key generation`,\n category: cls.cat,\n severity: cls.sev,\n algorithm: cls.algo,\n hndl: cls.hndl,\n message: `Generates a classical ${cls.label} key pair via Erlang :crypto (Elixir) — not quantum-safe.`,\n ...(cls.remediation ? { remediation: cls.remediation } : {}),\n }),\n );\n });\n\n // :crypto.sign / :crypto.verify(:type, …).\n eachMatch(RE_EX_SIGN, content, (m) => {\n const algo = classifySign(m[1]);\n if (!algo) return;\n findings.push(\n findingFromRule(RULE_EX_SIGN, at(m), {\n algorithm: algo,\n message: `Classical ${algo} signature via Erlang :crypto (Elixir) is forgeable by a quantum attacker.`,\n }),\n );\n });\n\n // X509.PrivateKey.new_rsa / new_ec.\n eachMatch(RE_EX_X509_RSA, content, (m) =>\n findings.push(findingFromRule(RULE_EX_X509, at(m), { algorithm: \"RSA\" })),\n );\n eachMatch(RE_EX_X509_EC, content, (m) =>\n findings.push(\n findingFromRule(RULE_EX_X509, at(m), {\n title: \"Elixir X509 EC key generation\",\n category: EC_CLS.cat,\n algorithm: EC_CLS.algo,\n hndl: EC_CLS.hndl,\n message:\n \"Generates a classical EC key pair via the X509 library (Elixir); EC keys feed BOTH ECDSA and ECDH.\",\n remediation: KEX_REM,\n }),\n ),\n );\n\n // JOSE.JWK.generate_key({:rsa|:ec|:okp, …}).\n eachMatch(RE_EX_JOSE, content, (m) => {\n const kind = m[1];\n const cls =\n kind === \"rsa\" ? RSA_CLS : kind === \"ec\" ? EC_CLS : kind === \"okp\" ? EDDSA_CLS : null;\n if (!cls) return;\n findings.push(\n findingFromRule(RULE_EX_JOSE, at(m), {\n title: `Elixir JOSE ${cls.label} JWK`,\n category: cls.cat,\n severity: cls.sev,\n algorithm: cls.algo,\n hndl: cls.hndl,\n message: `Generates a classical ${cls.label} JWK via JOSE (Elixir) — not quantum-safe.`,\n ...(cls.remediation ? { remediation: cls.remediation } : {}),\n }),\n );\n });\n\n return findings;\n },\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"java.d.ts","sourceRoot":"","sources":["../../src/detectors/java.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAqB,MAAM,aAAa,CAAC;AAkT/D,iFAAiF;AACjF,eAAO,MAAM,YAAY,EAAE,QA4F1B,CAAC"}
1
+ {"version":3,"file":"java.d.ts","sourceRoot":"","sources":["../../src/detectors/java.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAqB,MAAM,aAAa,CAAC;AAkT/D,iFAAiF;AACjF,eAAO,MAAM,YAAY,EAAE,QA6F1B,CAAC"}
@@ -287,7 +287,7 @@ const BC_CURVE_CLASS_RULES = {
287
287
  /** Detects classical asymmetric crypto in Java / Kotlin (JCA + BouncyCastle). */
288
288
  export const javaDetector = {
289
289
  id: "java-crypto",
290
- description: "Classical asymmetric crypto in Java/Kotlin (JCA getInstance + BouncyCastle)",
290
+ description: "Classical asymmetric crypto on the JVM — Java/Kotlin/Scala (JCA getInstance + BouncyCastle)",
291
291
  scope: "source",
292
292
  language: "java",
293
293
  rules: [
@@ -1 +1 @@
1
- {"version":3,"file":"java.js","sourceRoot":"","sources":["../../src/detectors/java.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC/F,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEtF,gFAAgF;AAChF,gFAAgF;AAChF,gFAAgF;AAEhF,8EAA8E;AAC9E,8EAA8E;AAC9E,iCAAiC;AACjC,MAAM,mBAAmB,GACvB,oGAAoG,CAAC;AAEvG,qDAAqD;AACrD,MAAM,UAAU,GACd,0PAA0P,CAAC;AAE7P,gFAAgF;AAChF,iFAAiF;AACjF,8EAA8E;AAC9E,+EAA+E;AAC/E,8EAA8E;AAC9E,gFAAgF;AAChF,sEAAsE;AACtE,MAAM,gBAAgB,GACpB,mMAAmM,CAAC;AAEtM,6EAA6E;AAC7E,+EAA+E;AAC/E,2EAA2E;AAC3E,oEAAoE;AACpE,gCAAgC;AAChC,MAAM,kBAAkB,GAAG,6DAA6D,CAAC;AACzF,MAAM,oBAAoB,GAAG,yDAAyD,CAAC;AAEvF,8EAA8E;AAC9E,gFAAgF;AAChF,8EAA8E;AAC9E,8EAA8E;AAC9E,8EAA8E;AAC9E,mEAAmE;AACnE,MAAM,eAAe,GACnB,kGAAkG,CAAC;AAErG,gFAAgF;AAChF,gFAAgF;AAChF,gFAAgF;AAEhF,MAAM,aAAa,GAAa;IAC9B,EAAE,EAAE,UAAU;IACd,KAAK,EAAE,yBAAyB;IAChC,WAAW,EAAE,gDAAgD;IAC7D,QAAQ,EAAE,KAAK;IACf,QAAQ,EAAE,MAAM;IAChB,UAAU,EAAE,MAAM;IAClB,SAAS,EAAE,KAAK;IAChB,IAAI,EAAE,IA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J,OAAO;gBACP,KAAK,EAAE,CAAC,CAAC,KAAK;gBACd,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM;aACzB,CAAC,CACH,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,gEAAgE;QAChE,SAAS,CAAC,eAAe,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;YACxC,QAAQ,CAAC,IAAI,CACX,eAAe,CAAC,iBAAiB,EAAE;gBACjC,IAAI;gBACJ,OAAO;gBACP,KAAK,EAAE,CAAC,CAAC,KAAK;gBACd,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM;aACzB,CAAC,CACH,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC","sourcesContent":["/**\n * Source-code detector for classical, non-quantum-safe asymmetric cryptography\n * in Java / Kotlin (the JCA — Java Cryptography Architecture). Same lexical\n * strategy as the other language packs.\n *\n * The JCA funnels almost everything through a handful of factory methods keyed\n * by an ALGORITHM STRING: `KeyPairGenerator.getInstance(\"RSA\")`,\n * `Signature.getInstance(\"SHA256withECDSA\")`, `Cipher.getInstance(\"RSA/ECB/…\")`,\n * `KeyAgreement.getInstance(\"ECDH\")`. So detection here is two steps: match the\n * `<Factory>.getInstance(\"<alg>\")` call, then classify the (factory, alg) pair\n * into a rule. Symmetric / hashing algorithms (\"AES\", \"HmacSHA256\", …) classify\n * to nothing and are ignored. A small set of BouncyCastle lightweight-API class\n * names (`new ECDSASigner()`, `new X25519Agreement()`, …) is matched directly.\n *\n * HNDL policy mirrors the other detectors: KEM / key agreement (RSA encryption,\n * (EC)DH, X25519/X448) is harvest-now-decrypt-later exposed (hndl:true);\n * signatures (RSA/ECDSA/DSA/EdDSA) are hndl:false but forgeable by a quantum\n * attacker. `KeyPairGenerator.getInstance(\"EC\")` is ambiguous (an EC key feeds\n * both ECDSA and ECDH), so it is classified conservatively as\n * key-exchange-capable (hndl:true), exactly as the Node/Python EC keygen rules.\n */\nimport type { Detector, Finding, RuleMeta } from \"../types.js\";\nimport { JAVA_EXTENSIONS, eachMatch, findingFromRule, hasExtension } from \"../detect-utils.js\";\nimport { CWE_BROKEN_CRYPTO, CWE_CERT_VALIDATION, CWE_WEAK_STRENGTH } from \"../cwe.js\";\n\n/* -------------------------------------------------------------------------- */\n/* Regexes */\n/* -------------------------------------------------------------------------- */\n\n// <Factory>.getInstance(\"<alg>\") — the JCA entry points that carry asymmetric\n// algorithms. KeyGenerator/MessageDigest/Mac are intentionally excluded (they\n// are symmetric / hashing only).\nconst RE_JAVA_GETINSTANCE =\n /\\b(KeyPairGenerator|Signature|Cipher|KeyAgreement|KeyFactory)\\s*\\.\\s*getInstance\\s*\\(\\s*\"([^\"]+)\"/g;\n\n// BouncyCastle lightweight-API class instantiations.\nconst RE_JAVA_BC =\n /\\bnew\\s+(RSAKeyPairGenerator|DSAKeyPairGenerator|ECKeyPairGenerator|ECDSASigner|Ed25519Signer|Ed448Signer|X25519Agreement|X448Agreement|ECDHBasicAgreement|DHBasicAgreement|X25519KeyPairGenerator|Ed25519KeyPairGenerator|RSAEngine|OAEPEncoding)\\s*\\(/g;\n\n// BouncyCastle lightweight-API curve/EdDSA classes as a BARE constructor call —\n// the Kotlin form (`X448KeyPairGenerator()`, no `new` keyword). RE_JAVA_BC above\n// only matches the Java `new <Class>(` form, so Kotlin sources that drive the\n// lightweight API directly are missed. The negative lookbehind `(?<!\\bnew\\s+)`\n// keeps this additive: `new X448Agreement(` stays with RE_JAVA_BC (java-xdh),\n// while bare `X448Agreement(` routes to the family-specific rules below. Scoped\n// to the exact X448/X25519/Ed448/Ed25519 class names to stay precise.\nconst RE_JAVA_BC_CURVE =\n /(?<!\\bnew\\s+)\\b(X448KeyPairGenerator|X448Agreement|X448PrivateKeyParameters|X25519KeyPairGenerator|X25519Agreement|Ed448KeyPairGenerator|Ed448Signer|Ed25519KeyPairGenerator|Ed25519Signer)\\s*\\(/g;\n\n// Insecure JSSE / TLS configuration expressed in Java source. Mirrors the JS\n// tlsDetector in source.ts (category \"tls\"): a legacy SSL/TLS protocol version\n// requested from SSLContext, and TLS hostname verification neutered via an\n// all-trusting verifier (Apache HttpClient's NoopHostnameVerifier /\n// ALLOW_ALL_HOSTNAME_VERIFIER).\nconst RE_JAVA_TLS_LEGACY = /\\bSSLContext\\s*\\.\\s*getInstance\\s*\\(\\s*\"(SSL|SSLv3|TLSv1)\"/g;\nconst RE_JAVA_TLS_NOVERIFY = /\\b(NoopHostnameVerifier|ALLOW_ALL_HOSTNAME_VERIFIER)\\b/g;\n\n// Identifier-form JWT/JOSE signature algorithms (audit F7). The quoted-string\n// alg token (\"RS256\") is caught by the language-agnostic jwt-jose detector, but\n// the Java JWT libraries pass the alg as an IDENTIFIER, not a string literal:\n// jjwt's `SignatureAlgorithm.RS256` and auth0 java-jwt's `Algorithm.RSA256` /\n// `Algorithm.ECDSA256`. (\"SignatureAlgorithm\" has no word boundary before its\n// \"Algorithm\", so the auth0 branch cannot re-match the jjwt form.)\nconst RE_JAVA_JWT_ALG =\n /\\bSignatureAlgorithm\\.(?:RS|PS|ES)(?:256|384|512)\\b|\\bAlgorithm\\.(?:RSA|ECDSA)(?:256|384|512)\\b/g;\n\n/* -------------------------------------------------------------------------- */\n/* Rule catalog */\n/* -------------------------------------------------------------------------- */\n\nconst RULE_JAVA_RSA: RuleMeta = {\n id: \"java-rsa\",\n title: \"Java RSA key/encryption\",\n description: \"JCA RSA KeyPairGenerator / Cipher / KeyFactory\",\n category: \"kem\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Classical RSA (Java/JCA) is not quantum-safe and RSA encryption is HNDL-exposed.\",\n};\nconst RULE_JAVA_RSA_SIGN: RuleMeta = {\n id: \"java-rsa-sign\",\n title: \"Java RSA signature\",\n description: 'JCA Signature.getInstance(\"…withRSA\")',\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Classical RSA signing (Java/JCA) is forgeable by a quantum attacker.\",\n remediation: \"ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)\",\n};\nconst RULE_JAVA_EC_KEYGEN: RuleMeta = {\n id: \"java-ec-keygen\",\n title: \"Java EC key generation\",\n description: 'JCA KeyPairGenerator.getInstance(\"EC\")',\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"ECDH\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Generates a classical EC key pair (Java/JCA). EC keys feed BOTH ECDSA signatures and ECDH key agreement; the ECDH path is harvest-now-decrypt-later exposed.\",\n remediation:\n \"For key agreement: hybrid X25519MLKEM768 (ML-KEM-768). For signatures: ML-DSA-65 (FIPS 204).\",\n};\nconst RULE_JAVA_ECDSA_SIGN: RuleMeta = {\n id: \"java-ecdsa-sign\",\n title: \"Java ECDSA signature\",\n description: 'JCA Signature.getInstance(\"…withECDSA\")',\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"ECDSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Classical ECDSA signing (Java/JCA) is forgeable by a quantum attacker.\",\n remediation: \"ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)\",\n};\nconst RULE_JAVA_ECDH: RuleMeta = {\n id: \"java-ecdh\",\n title: \"Java ECDH key agreement\",\n description: 'JCA KeyAgreement.getInstance(\"ECDH\")',\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"ECDH\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Elliptic-curve Diffie-Hellman (Java/JCA) is broken by Shor's algorithm (harvest-now-decrypt-later).\",\n};\nconst RULE_JAVA_DSA: RuleMeta = {\n id: \"java-dsa\",\n title: \"Java DSA key/signature\",\n description: \"JCA DSA KeyPairGenerator / Signature\",\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"DSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Classical DSA (Java/JCA) is deprecated and forgeable by a quantum attacker.\",\n remediation: \"Rotate off DSA and migrate to ML-DSA-65 (FIPS 204).\",\n};\nconst RULE_JAVA_DH: RuleMeta = {\n id: \"java-dh\",\n title: \"Java Diffie-Hellman key exchange\",\n description: \"JCA DiffieHellman KeyPairGenerator / KeyAgreement\",\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"DH\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Finite-field Diffie-Hellman (Java/JCA) is broken by Shor's algorithm (harvest-now-decrypt-later).\",\n};\nconst RULE_JAVA_XDH: RuleMeta = {\n id: \"java-xdh\",\n title: \"Java X25519/X448 key agreement\",\n description: \"JCA XDH / X25519 / X448 (KeyPairGenerator / KeyAgreement)\",\n category: \"key-exchange\",\n severity: \"medium\",\n confidence: \"high\",\n algorithm: \"X25519\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"X25519/X448 (Java/JCA) is modern but still classical key agreement — harvest-now-decrypt-later.\",\n};\nconst RULE_JAVA_EDDSA: RuleMeta = {\n id: \"java-eddsa\",\n title: \"Java Ed25519/Ed448 signature\",\n description: \"JCA EdDSA / Ed25519 / Ed448\",\n category: \"signature\",\n severity: \"low\",\n confidence: \"high\",\n algorithm: \"EdDSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Ed25519/Ed448 (Java/JCA) is a modern but still classical signature scheme.\",\n};\n// BouncyCastle lightweight-API rules for bare (Kotlin-form) constructor calls.\n// Split by family so X448 and X25519 report their own algorithm string (java-xdh\n// lumps both under \"X25519\"). Severity/CWE copied from the JCA siblings above.\nconst RULE_JAVA_BC_X448: RuleMeta = {\n id: \"java-bc-x448\",\n title: \"Java/Kotlin X448 key agreement (BouncyCastle lightweight API)\",\n description: \"BouncyCastle X448KeyPairGenerator / X448Agreement / X448PrivateKeyParameters\",\n category: \"key-exchange\",\n severity: \"medium\",\n confidence: \"high\",\n algorithm: \"X448\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"X448 (Java/Kotlin, BouncyCastle lightweight API) is modern but still classical key agreement — harvest-now-decrypt-later.\",\n};\nconst RULE_JAVA_BC_X25519: RuleMeta = {\n id: \"java-bc-x25519\",\n title: \"Java/Kotlin X25519 key agreement (BouncyCastle lightweight API)\",\n description: \"BouncyCastle X25519KeyPairGenerator / X25519Agreement\",\n category: \"key-exchange\",\n severity: \"medium\",\n confidence: \"high\",\n algorithm: \"X25519\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"X25519 (Java/Kotlin, BouncyCastle lightweight API) is modern but still classical key agreement — harvest-now-decrypt-later.\",\n};\nconst RULE_JAVA_BC_EDDSA: RuleMeta = {\n id: \"java-bc-eddsa\",\n title: \"Java/Kotlin Ed25519/Ed448 signature (BouncyCastle lightweight API)\",\n description:\n \"BouncyCastle Ed448KeyPairGenerator / Ed448Signer / Ed25519KeyPairGenerator / Ed25519Signer\",\n category: \"signature\",\n severity: \"low\",\n confidence: \"high\",\n algorithm: \"EdDSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Ed25519/Ed448 (Java/Kotlin, BouncyCastle lightweight API) is a modern but still classical signature scheme.\",\n};\nconst RULE_JAVA_TLS_LEGACY: RuleMeta = {\n id: \"java-tls-legacy-version\",\n title: \"Legacy SSL/TLS version requested\",\n description: 'SSLContext.getInstance(\"SSL\" | \"SSLv3\" | \"TLSv1\")',\n category: \"tls\",\n severity: \"medium\",\n confidence: \"high\",\n hndl: false,\n cwe: CWE_WEAK_STRENGTH,\n message: \"SSL/SSLv3/TLS 1.0 are deprecated and insecure (Java/JSSE); require TLS 1.3.\",\n remediation: 'Use SSLContext.getInstance(\"TLSv1.3\") and prefer PQC-hybrid key exchange.',\n};\nconst RULE_JAVA_TLS_NOVERIFY: RuleMeta = {\n id: \"java-tls-hostname-verification-disabled\",\n title: \"TLS hostname verification disabled\",\n description: \"NoopHostnameVerifier / ALLOW_ALL_HOSTNAME_VERIFIER\",\n category: \"tls\",\n severity: \"high\",\n confidence: \"high\",\n hndl: false,\n cwe: CWE_CERT_VALIDATION,\n message: \"An all-trusting hostname verifier (Java) disables TLS hostname checking (MITM risk).\",\n remediation: \"Remove the all-trusting verifier; rely on the default hostname verifier.\",\n};\nconst RULE_JAVA_JWT_ALG: RuleMeta = {\n id: \"java-jwt-alg\",\n title: \"Java identifier-form JWT/JOSE algorithm\",\n description: \"jjwt SignatureAlgorithm.RS/PS/ES* / auth0 Algorithm.RSA*/ECDSA*\",\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"unknown\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"A classical JWT/JOSE signature algorithm (Java, identifier form) is used, forgeable by a quantum attacker.\",\n remediation: \"ML-DSA-65 (FIPS 204); track IETF PQC JOSE/COSE algorithms\",\n};\n\n/**\n * Classify a `<factory>.getInstance(\"<alg>\")` pair into a rule, or null when the\n * algorithm is not classical asymmetric crypto (AES, HMAC, PBKDF2, hashes, …).\n * `alg` is normalised to upper-case with any Cipher transformation suffix\n * (`RSA/ECB/OAEPPadding` → `RSA`) stripped.\n */\nfunction classifyGetInstance(factory: string, rawAlg: string): RuleMeta | null {\n const alg = rawAlg.split(\"/\")[0].trim().toUpperCase();\n const isSignature = factory === \"Signature\";\n\n if (alg.includes(\"ECDSA\")) return RULE_JAVA_ECDSA_SIGN;\n if (alg.includes(\"ECDH\")) return RULE_JAVA_ECDH;\n if (alg === \"EC\") return isSignature ? RULE_JAVA_ECDSA_SIGN : RULE_JAVA_EC_KEYGEN;\n if (alg.includes(\"ED25519\") || alg.includes(\"ED448\") || alg.includes(\"EDDSA\"))\n return RULE_JAVA_EDDSA;\n if (alg.includes(\"X25519\") || alg.includes(\"X448\") || alg === \"XDH\") return RULE_JAVA_XDH;\n // RSASSA-PSS is an RSA *signature* scheme, not encryption/KEM. The string\n // contains \"RSA\", so it must be caught here — BEFORE the generic RSA branch\n // below, which would otherwise (mis)classify it as HNDL-exposed RSA\n // encryption (java-rsa / hndl:true). Signatures are hndl:false. (Fixes F8.)\n if (alg.includes(\"PSS\")) return RULE_JAVA_RSA_SIGN;\n if (alg.includes(\"RSA\")) return isSignature ? RULE_JAVA_RSA_SIGN : RULE_JAVA_RSA;\n if (alg.includes(\"DSA\")) return RULE_JAVA_DSA; // ECDSA already handled above\n if (alg.includes(\"DH\") || alg.includes(\"DIFFIEHELLMAN\")) return RULE_JAVA_DH;\n return null;\n}\n\n/** BouncyCastle lightweight-API class name → rule. */\nconst BC_CLASS_RULES: Record<string, RuleMeta> = {\n RSAKeyPairGenerator: RULE_JAVA_RSA,\n DSAKeyPairGenerator: RULE_JAVA_DSA,\n ECKeyPairGenerator: RULE_JAVA_EC_KEYGEN,\n ECDSASigner: RULE_JAVA_ECDSA_SIGN,\n Ed25519Signer: RULE_JAVA_EDDSA,\n Ed448Signer: RULE_JAVA_EDDSA,\n X25519Agreement: RULE_JAVA_XDH,\n X448Agreement: RULE_JAVA_XDH,\n ECDHBasicAgreement: RULE_JAVA_ECDH,\n DHBasicAgreement: RULE_JAVA_DH,\n X25519KeyPairGenerator: RULE_JAVA_XDH,\n Ed25519KeyPairGenerator: RULE_JAVA_EDDSA,\n RSAEngine: RULE_JAVA_RSA,\n OAEPEncoding: RULE_JAVA_RSA,\n};\n\n/** BouncyCastle lightweight-API bare-constructor class name → family rule. */\nconst BC_CURVE_CLASS_RULES: Record<string, RuleMeta> = {\n X448KeyPairGenerator: RULE_JAVA_BC_X448,\n X448Agreement: RULE_JAVA_BC_X448,\n X448PrivateKeyParameters: RULE_JAVA_BC_X448,\n X25519KeyPairGenerator: RULE_JAVA_BC_X25519,\n X25519Agreement: RULE_JAVA_BC_X25519,\n Ed448KeyPairGenerator: RULE_JAVA_BC_EDDSA,\n Ed448Signer: RULE_JAVA_BC_EDDSA,\n Ed25519KeyPairGenerator: RULE_JAVA_BC_EDDSA,\n Ed25519Signer: RULE_JAVA_BC_EDDSA,\n};\n\n/** Detects classical asymmetric crypto in Java / Kotlin (JCA + BouncyCastle). */\nexport const javaDetector: Detector = {\n id: \"java-crypto\",\n description: \"Classical asymmetric crypto in Java/Kotlin (JCA getInstance + BouncyCastle)\",\n scope: \"source\",\n language: \"java\",\n rules: [\n RULE_JAVA_RSA,\n RULE_JAVA_RSA_SIGN,\n RULE_JAVA_EC_KEYGEN,\n RULE_JAVA_ECDSA_SIGN,\n RULE_JAVA_ECDH,\n RULE_JAVA_DSA,\n RULE_JAVA_DH,\n RULE_JAVA_XDH,\n RULE_JAVA_EDDSA,\n RULE_JAVA_BC_X448,\n RULE_JAVA_BC_X25519,\n RULE_JAVA_BC_EDDSA,\n RULE_JAVA_TLS_LEGACY,\n RULE_JAVA_TLS_NOVERIFY,\n RULE_JAVA_JWT_ALG,\n ],\n appliesTo: (f) => hasExtension(f, JAVA_EXTENSIONS),\n detect({ file, content }): Finding[] {\n const findings: Finding[] = [];\n\n eachMatch(RE_JAVA_GETINSTANCE, content, (m) => {\n const rule = classifyGetInstance(m[1], m[2]);\n if (!rule) return; // symmetric / hashing algorithm — not our concern.\n findings.push(\n findingFromRule(rule, { file, content, index: m.index, matchLength: m[0].length }),\n );\n });\n\n eachMatch(RE_JAVA_BC, content, (m) => {\n const rule = BC_CLASS_RULES[m[1]];\n if (!rule) return;\n findings.push(\n findingFromRule(rule, { file, content, index: m.index, matchLength: m[0].length }),\n );\n });\n\n // BouncyCastle lightweight-API classes as a bare constructor call (Kotlin\n // form, no `new`). RE_JAVA_BC_CURVE's negative lookbehind excludes the\n // `new <Class>(` form already handled above, so this only adds the missed\n // 448/25519 Kotlin-style matches — no double-counting.\n eachMatch(RE_JAVA_BC_CURVE, content, (m) => {\n const rule = BC_CURVE_CLASS_RULES[m[1]];\n if (!rule) return;\n findings.push(\n findingFromRule(rule, { file, content, index: m.index, matchLength: m[0].length }),\n );\n });\n\n // Legacy SSL/TLS protocol version requested from SSLContext.\n eachMatch(RE_JAVA_TLS_LEGACY, content, (m) => {\n findings.push(\n findingFromRule(RULE_JAVA_TLS_LEGACY, {\n file,\n content,\n index: m.index,\n matchLength: m[0].length,\n }),\n );\n });\n\n // All-trusting hostname verifier — disables TLS hostname verification.\n eachMatch(RE_JAVA_TLS_NOVERIFY, content, (m) => {\n findings.push(\n findingFromRule(RULE_JAVA_TLS_NOVERIFY, {\n file,\n content,\n index: m.index,\n matchLength: m[0].length,\n }),\n );\n });\n\n // Identifier-form JWT/JOSE signature algorithms (jjwt / auth0).\n eachMatch(RE_JAVA_JWT_ALG, content, (m) => {\n findings.push(\n findingFromRule(RULE_JAVA_JWT_ALG, {\n file,\n content,\n index: m.index,\n matchLength: m[0].length,\n }),\n );\n });\n\n return findings;\n },\n};\n"]}
1
+ {"version":3,"file":"java.js","sourceRoot":"","sources":["../../src/detectors/java.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC/F,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEtF,gFAAgF;AAChF,gFAAgF;AAChF,gFAAgF;AAEhF,8EAA8E;AAC9E,8EAA8E;AAC9E,iCAAiC;AACjC,MAAM,mBAAmB,GACvB,oGAAoG,CAAC;AAEvG,qDAAqD;AACrD,MAAM,UAAU,GACd,0PAA0P,CAAC;AAE7P,gFAAgF;AAChF,iFAAiF;AACjF,8EAA8E;AAC9E,+EAA+E;AAC/E,8EAA8E;AAC9E,gFAAgF;AAChF,sEAAsE;AACtE,MAAM,gBAAgB,GACpB,mMAAmM,CAAC;AAEtM,6EAA6E;AAC7E,+EAA+E;AAC/E,2EAA2E;AAC3E,oEAAoE;AACpE,gCAAgC;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,CAAC,CAAC;QAEH,6DAA6D;QAC7D,SAAS,CAAC,kBAAkB,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;YAC3C,QAAQ,CAAC,IAAI,CACX,eAAe,CAAC,oBAAoB,EAAE;gBACpC,IAAI;gBACJ,OAAO;gBACP,KAAK,EAAE,CAAC,CAAC,KAAK;gBACd,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM;aACzB,CAAC,CACH,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,uEAAuE;QACvE,SAAS,CAAC,oBAAoB,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;YAC7C,QAAQ,CAAC,IAAI,CACX,eAAe,CAAC,sBAAsB,EAAE;gBACtC,IAAI;gBACJ,OAAO;gBACP,KAAK,EAAE,CAAC,CAAC,KAAK;gBACd,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM;aACzB,CAAC,CACH,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,gEAAgE;QAChE,SAAS,CAAC,eAAe,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;YACxC,QAAQ,CAAC,IAAI,CACX,eAAe,CAAC,iBAAiB,EAAE;gBACjC,IAAI;gBACJ,OAAO;gBACP,KAAK,EAAE,CAAC,CAAC,KAAK;gBACd,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM;aACzB,CAAC,CACH,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC","sourcesContent":["/**\n * Source-code detector for classical, non-quantum-safe asymmetric cryptography\n * in Java / Kotlin (the JCA — Java Cryptography Architecture). Same lexical\n * strategy as the other language packs.\n *\n * The JCA funnels almost everything through a handful of factory methods keyed\n * by an ALGORITHM STRING: `KeyPairGenerator.getInstance(\"RSA\")`,\n * `Signature.getInstance(\"SHA256withECDSA\")`, `Cipher.getInstance(\"RSA/ECB/…\")`,\n * `KeyAgreement.getInstance(\"ECDH\")`. So detection here is two steps: match the\n * `<Factory>.getInstance(\"<alg>\")` call, then classify the (factory, alg) pair\n * into a rule. Symmetric / hashing algorithms (\"AES\", \"HmacSHA256\", …) classify\n * to nothing and are ignored. A small set of BouncyCastle lightweight-API class\n * names (`new ECDSASigner()`, `new X25519Agreement()`, …) is matched directly.\n *\n * HNDL policy mirrors the other detectors: KEM / key agreement (RSA encryption,\n * (EC)DH, X25519/X448) is harvest-now-decrypt-later exposed (hndl:true);\n * signatures (RSA/ECDSA/DSA/EdDSA) are hndl:false but forgeable by a quantum\n * attacker. `KeyPairGenerator.getInstance(\"EC\")` is ambiguous (an EC key feeds\n * both ECDSA and ECDH), so it is classified conservatively as\n * key-exchange-capable (hndl:true), exactly as the Node/Python EC keygen rules.\n */\nimport type { Detector, Finding, RuleMeta } from \"../types.js\";\nimport { JAVA_EXTENSIONS, eachMatch, findingFromRule, hasExtension } from \"../detect-utils.js\";\nimport { CWE_BROKEN_CRYPTO, CWE_CERT_VALIDATION, CWE_WEAK_STRENGTH } from \"../cwe.js\";\n\n/* -------------------------------------------------------------------------- */\n/* Regexes */\n/* -------------------------------------------------------------------------- */\n\n// <Factory>.getInstance(\"<alg>\") — the JCA entry points that carry asymmetric\n// algorithms. KeyGenerator/MessageDigest/Mac are intentionally excluded (they\n// are symmetric / hashing only).\nconst RE_JAVA_GETINSTANCE =\n /\\b(KeyPairGenerator|Signature|Cipher|KeyAgreement|KeyFactory)\\s*\\.\\s*getInstance\\s*\\(\\s*\"([^\"]+)\"/g;\n\n// BouncyCastle lightweight-API class instantiations.\nconst RE_JAVA_BC =\n /\\bnew\\s+(RSAKeyPairGenerator|DSAKeyPairGenerator|ECKeyPairGenerator|ECDSASigner|Ed25519Signer|Ed448Signer|X25519Agreement|X448Agreement|ECDHBasicAgreement|DHBasicAgreement|X25519KeyPairGenerator|Ed25519KeyPairGenerator|RSAEngine|OAEPEncoding)\\s*\\(/g;\n\n// BouncyCastle lightweight-API curve/EdDSA classes as a BARE constructor call —\n// the Kotlin form (`X448KeyPairGenerator()`, no `new` keyword). RE_JAVA_BC above\n// only matches the Java `new <Class>(` form, so Kotlin sources that drive the\n// lightweight API directly are missed. The negative lookbehind `(?<!\\bnew\\s+)`\n// keeps this additive: `new X448Agreement(` stays with RE_JAVA_BC (java-xdh),\n// while bare `X448Agreement(` routes to the family-specific rules below. Scoped\n// to the exact X448/X25519/Ed448/Ed25519 class names to stay precise.\nconst RE_JAVA_BC_CURVE =\n /(?<!\\bnew\\s+)\\b(X448KeyPairGenerator|X448Agreement|X448PrivateKeyParameters|X25519KeyPairGenerator|X25519Agreement|Ed448KeyPairGenerator|Ed448Signer|Ed25519KeyPairGenerator|Ed25519Signer)\\s*\\(/g;\n\n// Insecure JSSE / TLS configuration expressed in Java source. Mirrors the JS\n// tlsDetector in source.ts (category \"tls\"): a legacy SSL/TLS protocol version\n// requested from SSLContext, and TLS hostname verification neutered via an\n// all-trusting verifier (Apache HttpClient's NoopHostnameVerifier /\n// ALLOW_ALL_HOSTNAME_VERIFIER).\nconst RE_JAVA_TLS_LEGACY = /\\bSSLContext\\s*\\.\\s*getInstance\\s*\\(\\s*\"(SSL|SSLv3|TLSv1)\"/g;\nconst RE_JAVA_TLS_NOVERIFY = /\\b(NoopHostnameVerifier|ALLOW_ALL_HOSTNAME_VERIFIER)\\b/g;\n\n// Identifier-form JWT/JOSE signature algorithms (audit F7). The quoted-string\n// alg token (\"RS256\") is caught by the language-agnostic jwt-jose detector, but\n// the Java JWT libraries pass the alg as an IDENTIFIER, not a string literal:\n// jjwt's `SignatureAlgorithm.RS256` and auth0 java-jwt's `Algorithm.RSA256` /\n// `Algorithm.ECDSA256`. (\"SignatureAlgorithm\" has no word boundary before its\n// \"Algorithm\", so the auth0 branch cannot re-match the jjwt form.)\nconst RE_JAVA_JWT_ALG =\n /\\bSignatureAlgorithm\\.(?:RS|PS|ES)(?:256|384|512)\\b|\\bAlgorithm\\.(?:RSA|ECDSA)(?:256|384|512)\\b/g;\n\n/* -------------------------------------------------------------------------- */\n/* Rule catalog */\n/* -------------------------------------------------------------------------- */\n\nconst RULE_JAVA_RSA: RuleMeta = {\n id: \"java-rsa\",\n title: \"Java RSA key/encryption\",\n description: \"JCA RSA KeyPairGenerator / Cipher / KeyFactory\",\n category: \"kem\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Classical RSA (Java/JCA) is not quantum-safe and RSA encryption is HNDL-exposed.\",\n};\nconst RULE_JAVA_RSA_SIGN: RuleMeta = {\n id: \"java-rsa-sign\",\n title: \"Java RSA signature\",\n description: 'JCA Signature.getInstance(\"…withRSA\")',\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Classical RSA signing (Java/JCA) is forgeable by a quantum attacker.\",\n remediation: \"ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)\",\n};\nconst RULE_JAVA_EC_KEYGEN: RuleMeta = {\n id: \"java-ec-keygen\",\n title: \"Java EC key generation\",\n description: 'JCA KeyPairGenerator.getInstance(\"EC\")',\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"ECDH\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Generates a classical EC key pair (Java/JCA). EC keys feed BOTH ECDSA signatures and ECDH key agreement; the ECDH path is harvest-now-decrypt-later exposed.\",\n remediation:\n \"For key agreement: hybrid X25519MLKEM768 (ML-KEM-768). For signatures: ML-DSA-65 (FIPS 204).\",\n};\nconst RULE_JAVA_ECDSA_SIGN: RuleMeta = {\n id: \"java-ecdsa-sign\",\n title: \"Java ECDSA signature\",\n description: 'JCA Signature.getInstance(\"…withECDSA\")',\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"ECDSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Classical ECDSA signing (Java/JCA) is forgeable by a quantum attacker.\",\n remediation: \"ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)\",\n};\nconst RULE_JAVA_ECDH: RuleMeta = {\n id: \"java-ecdh\",\n title: \"Java ECDH key agreement\",\n description: 'JCA KeyAgreement.getInstance(\"ECDH\")',\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"ECDH\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Elliptic-curve Diffie-Hellman (Java/JCA) is broken by Shor's algorithm (harvest-now-decrypt-later).\",\n};\nconst RULE_JAVA_DSA: RuleMeta = {\n id: \"java-dsa\",\n title: \"Java DSA key/signature\",\n description: \"JCA DSA KeyPairGenerator / Signature\",\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"DSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Classical DSA (Java/JCA) is deprecated and forgeable by a quantum attacker.\",\n remediation: \"Rotate off DSA and migrate to ML-DSA-65 (FIPS 204).\",\n};\nconst RULE_JAVA_DH: RuleMeta = {\n id: \"java-dh\",\n title: \"Java Diffie-Hellman key exchange\",\n description: \"JCA DiffieHellman KeyPairGenerator / KeyAgreement\",\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"DH\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Finite-field Diffie-Hellman (Java/JCA) is broken by Shor's algorithm (harvest-now-decrypt-later).\",\n};\nconst RULE_JAVA_XDH: RuleMeta = {\n id: \"java-xdh\",\n title: \"Java X25519/X448 key agreement\",\n description: \"JCA XDH / X25519 / X448 (KeyPairGenerator / KeyAgreement)\",\n category: \"key-exchange\",\n severity: \"medium\",\n confidence: \"high\",\n algorithm: \"X25519\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"X25519/X448 (Java/JCA) is modern but still classical key agreement — harvest-now-decrypt-later.\",\n};\nconst RULE_JAVA_EDDSA: RuleMeta = {\n id: \"java-eddsa\",\n title: \"Java Ed25519/Ed448 signature\",\n description: \"JCA EdDSA / Ed25519 / Ed448\",\n category: \"signature\",\n severity: \"low\",\n confidence: \"high\",\n algorithm: \"EdDSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Ed25519/Ed448 (Java/JCA) is a modern but still classical signature scheme.\",\n};\n// BouncyCastle lightweight-API rules for bare (Kotlin-form) constructor calls.\n// Split by family so X448 and X25519 report their own algorithm string (java-xdh\n// lumps both under \"X25519\"). Severity/CWE copied from the JCA siblings above.\nconst RULE_JAVA_BC_X448: RuleMeta = {\n id: \"java-bc-x448\",\n title: \"Java/Kotlin X448 key agreement (BouncyCastle lightweight API)\",\n description: \"BouncyCastle X448KeyPairGenerator / X448Agreement / X448PrivateKeyParameters\",\n category: \"key-exchange\",\n severity: \"medium\",\n confidence: \"high\",\n algorithm: \"X448\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"X448 (Java/Kotlin, BouncyCastle lightweight API) is modern but still classical key agreement — harvest-now-decrypt-later.\",\n};\nconst RULE_JAVA_BC_X25519: RuleMeta = {\n id: \"java-bc-x25519\",\n title: \"Java/Kotlin X25519 key agreement (BouncyCastle lightweight API)\",\n description: \"BouncyCastle X25519KeyPairGenerator / X25519Agreement\",\n category: \"key-exchange\",\n severity: \"medium\",\n confidence: \"high\",\n algorithm: \"X25519\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"X25519 (Java/Kotlin, BouncyCastle lightweight API) is modern but still classical key agreement — harvest-now-decrypt-later.\",\n};\nconst RULE_JAVA_BC_EDDSA: RuleMeta = {\n id: \"java-bc-eddsa\",\n title: \"Java/Kotlin Ed25519/Ed448 signature (BouncyCastle lightweight API)\",\n description:\n \"BouncyCastle Ed448KeyPairGenerator / Ed448Signer / Ed25519KeyPairGenerator / Ed25519Signer\",\n category: \"signature\",\n severity: \"low\",\n confidence: \"high\",\n algorithm: \"EdDSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Ed25519/Ed448 (Java/Kotlin, BouncyCastle lightweight API) is a modern but still classical signature scheme.\",\n};\nconst RULE_JAVA_TLS_LEGACY: RuleMeta = {\n id: \"java-tls-legacy-version\",\n title: \"Legacy SSL/TLS version requested\",\n description: 'SSLContext.getInstance(\"SSL\" | \"SSLv3\" | \"TLSv1\")',\n category: \"tls\",\n severity: \"medium\",\n confidence: \"high\",\n hndl: false,\n cwe: CWE_WEAK_STRENGTH,\n message: \"SSL/SSLv3/TLS 1.0 are deprecated and insecure (Java/JSSE); require TLS 1.3.\",\n remediation: 'Use SSLContext.getInstance(\"TLSv1.3\") and prefer PQC-hybrid key exchange.',\n};\nconst RULE_JAVA_TLS_NOVERIFY: RuleMeta = {\n id: \"java-tls-hostname-verification-disabled\",\n title: \"TLS hostname verification disabled\",\n description: \"NoopHostnameVerifier / ALLOW_ALL_HOSTNAME_VERIFIER\",\n category: \"tls\",\n severity: \"high\",\n confidence: \"high\",\n hndl: false,\n cwe: CWE_CERT_VALIDATION,\n message: \"An all-trusting hostname verifier (Java) disables TLS hostname checking (MITM risk).\",\n remediation: \"Remove the all-trusting verifier; rely on the default hostname verifier.\",\n};\nconst RULE_JAVA_JWT_ALG: RuleMeta = {\n id: \"java-jwt-alg\",\n title: \"Java identifier-form JWT/JOSE algorithm\",\n description: \"jjwt SignatureAlgorithm.RS/PS/ES* / auth0 Algorithm.RSA*/ECDSA*\",\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"unknown\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"A classical JWT/JOSE signature algorithm (Java, identifier form) is used, forgeable by a quantum attacker.\",\n remediation: \"ML-DSA-65 (FIPS 204); track IETF PQC JOSE/COSE algorithms\",\n};\n\n/**\n * Classify a `<factory>.getInstance(\"<alg>\")` pair into a rule, or null when the\n * algorithm is not classical asymmetric crypto (AES, HMAC, PBKDF2, hashes, …).\n * `alg` is normalised to upper-case with any Cipher transformation suffix\n * (`RSA/ECB/OAEPPadding` → `RSA`) stripped.\n */\nfunction classifyGetInstance(factory: string, rawAlg: string): RuleMeta | null {\n const alg = rawAlg.split(\"/\")[0].trim().toUpperCase();\n const isSignature = factory === \"Signature\";\n\n if (alg.includes(\"ECDSA\")) return RULE_JAVA_ECDSA_SIGN;\n if (alg.includes(\"ECDH\")) return RULE_JAVA_ECDH;\n if (alg === \"EC\") return isSignature ? RULE_JAVA_ECDSA_SIGN : RULE_JAVA_EC_KEYGEN;\n if (alg.includes(\"ED25519\") || alg.includes(\"ED448\") || alg.includes(\"EDDSA\"))\n return RULE_JAVA_EDDSA;\n if (alg.includes(\"X25519\") || alg.includes(\"X448\") || alg === \"XDH\") return RULE_JAVA_XDH;\n // RSASSA-PSS is an RSA *signature* scheme, not encryption/KEM. The string\n // contains \"RSA\", so it must be caught here — BEFORE the generic RSA branch\n // below, which would otherwise (mis)classify it as HNDL-exposed RSA\n // encryption (java-rsa / hndl:true). Signatures are hndl:false. (Fixes F8.)\n if (alg.includes(\"PSS\")) return RULE_JAVA_RSA_SIGN;\n if (alg.includes(\"RSA\")) return isSignature ? RULE_JAVA_RSA_SIGN : RULE_JAVA_RSA;\n if (alg.includes(\"DSA\")) return RULE_JAVA_DSA; // ECDSA already handled above\n if (alg.includes(\"DH\") || alg.includes(\"DIFFIEHELLMAN\")) return RULE_JAVA_DH;\n return null;\n}\n\n/** BouncyCastle lightweight-API class name → rule. */\nconst BC_CLASS_RULES: Record<string, RuleMeta> = {\n RSAKeyPairGenerator: RULE_JAVA_RSA,\n DSAKeyPairGenerator: RULE_JAVA_DSA,\n ECKeyPairGenerator: RULE_JAVA_EC_KEYGEN,\n ECDSASigner: RULE_JAVA_ECDSA_SIGN,\n Ed25519Signer: RULE_JAVA_EDDSA,\n Ed448Signer: RULE_JAVA_EDDSA,\n X25519Agreement: RULE_JAVA_XDH,\n X448Agreement: RULE_JAVA_XDH,\n ECDHBasicAgreement: RULE_JAVA_ECDH,\n DHBasicAgreement: RULE_JAVA_DH,\n X25519KeyPairGenerator: RULE_JAVA_XDH,\n Ed25519KeyPairGenerator: RULE_JAVA_EDDSA,\n RSAEngine: RULE_JAVA_RSA,\n OAEPEncoding: RULE_JAVA_RSA,\n};\n\n/** BouncyCastle lightweight-API bare-constructor class name → family rule. */\nconst BC_CURVE_CLASS_RULES: Record<string, RuleMeta> = {\n X448KeyPairGenerator: RULE_JAVA_BC_X448,\n X448Agreement: RULE_JAVA_BC_X448,\n X448PrivateKeyParameters: RULE_JAVA_BC_X448,\n X25519KeyPairGenerator: RULE_JAVA_BC_X25519,\n X25519Agreement: RULE_JAVA_BC_X25519,\n Ed448KeyPairGenerator: RULE_JAVA_BC_EDDSA,\n Ed448Signer: RULE_JAVA_BC_EDDSA,\n Ed25519KeyPairGenerator: RULE_JAVA_BC_EDDSA,\n Ed25519Signer: RULE_JAVA_BC_EDDSA,\n};\n\n/** Detects classical asymmetric crypto in Java / Kotlin (JCA + BouncyCastle). */\nexport const javaDetector: Detector = {\n id: \"java-crypto\",\n description:\n \"Classical asymmetric crypto on the JVM — Java/Kotlin/Scala (JCA getInstance + BouncyCastle)\",\n scope: \"source\",\n language: \"java\",\n rules: [\n RULE_JAVA_RSA,\n RULE_JAVA_RSA_SIGN,\n RULE_JAVA_EC_KEYGEN,\n RULE_JAVA_ECDSA_SIGN,\n RULE_JAVA_ECDH,\n RULE_JAVA_DSA,\n RULE_JAVA_DH,\n RULE_JAVA_XDH,\n RULE_JAVA_EDDSA,\n RULE_JAVA_BC_X448,\n RULE_JAVA_BC_X25519,\n RULE_JAVA_BC_EDDSA,\n RULE_JAVA_TLS_LEGACY,\n RULE_JAVA_TLS_NOVERIFY,\n RULE_JAVA_JWT_ALG,\n ],\n appliesTo: (f) => hasExtension(f, JAVA_EXTENSIONS),\n detect({ file, content }): Finding[] {\n const findings: Finding[] = [];\n\n eachMatch(RE_JAVA_GETINSTANCE, content, (m) => {\n const rule = classifyGetInstance(m[1], m[2]);\n if (!rule) return; // symmetric / hashing algorithm — not our concern.\n findings.push(\n findingFromRule(rule, { file, content, index: m.index, matchLength: m[0].length }),\n );\n });\n\n eachMatch(RE_JAVA_BC, content, (m) => {\n const rule = BC_CLASS_RULES[m[1]];\n if (!rule) return;\n findings.push(\n findingFromRule(rule, { file, content, index: m.index, matchLength: m[0].length }),\n );\n });\n\n // BouncyCastle lightweight-API classes as a bare constructor call (Kotlin\n // form, no `new`). RE_JAVA_BC_CURVE's negative lookbehind excludes the\n // `new <Class>(` form already handled above, so this only adds the missed\n // 448/25519 Kotlin-style matches — no double-counting.\n eachMatch(RE_JAVA_BC_CURVE, content, (m) => {\n const rule = BC_CURVE_CLASS_RULES[m[1]];\n if (!rule) return;\n findings.push(\n findingFromRule(rule, { file, content, index: m.index, matchLength: m[0].length }),\n );\n });\n\n // Legacy SSL/TLS protocol version requested from SSLContext.\n eachMatch(RE_JAVA_TLS_LEGACY, content, (m) => {\n findings.push(\n findingFromRule(RULE_JAVA_TLS_LEGACY, {\n file,\n content,\n index: m.index,\n matchLength: m[0].length,\n }),\n );\n });\n\n // All-trusting hostname verifier — disables TLS hostname verification.\n eachMatch(RE_JAVA_TLS_NOVERIFY, content, (m) => {\n findings.push(\n findingFromRule(RULE_JAVA_TLS_NOVERIFY, {\n file,\n content,\n index: m.index,\n matchLength: m[0].length,\n }),\n );\n });\n\n // Identifier-form JWT/JOSE signature algorithms (jjwt / auth0).\n eachMatch(RE_JAVA_JWT_ALG, content, (m) => {\n findings.push(\n findingFromRule(RULE_JAVA_JWT_ALG, {\n file,\n content,\n index: m.index,\n matchLength: m[0].length,\n }),\n );\n });\n\n return findings;\n },\n};\n"]}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Config detector: classical KEY-MANAGEMENT (JWE) algorithms in JOSE. This is
3
+ * distinct from the JWS signature side (RS256/ES256, handled elsewhere) and from
4
+ * the JWK key-material detector: here we flag the `alg` values that wrap a
5
+ * content-encryption key with classical asymmetric crypto, because the encrypted
6
+ * payload is CONFIDENTIALITY — harvest-now-decrypt-later exposed. A JWE token
7
+ * captured today (from a log, an audit trail, a stored assertion) is decryptable
8
+ * once the wrapping key falls to a CRQC.
9
+ *
10
+ * Covered `alg` (RFC 7518 §4) values:
11
+ * - `RSA-OAEP`, `RSA-OAEP-256`, `RSA1_5` → RSA key encryption.
12
+ * - `ECDH-ES`, `ECDH-ES+A128KW`, … → classical EC Diffie-Hellman key agreement.
13
+ *
14
+ * These exact strings are JOSE identifiers, so a content-level match is precise;
15
+ * the detector applies to any file (config, JSON, source) after a fast reject.
16
+ */
17
+ import type { Detector } from "../types.js";
18
+ /** Detects classical JWE key-management (`alg`) values in JOSE tokens/config. */
19
+ export declare const joseDetector: Detector;
20
+ //# sourceMappingURL=jose.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jose.d.ts","sourceRoot":"","sources":["../../src/detectors/jose.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAqB,MAAM,aAAa,CAAC;AAgD/D,iFAAiF;AACjF,eAAO,MAAM,YAAY,EAAE,QA4B1B,CAAC"}
@@ -0,0 +1,62 @@
1
+ import { DOC_EXTENSIONS, eachMatch, findingFromRule, hasExtension } from "../detect-utils.js";
2
+ import { CWE_BROKEN_CRYPTO } from "../cwe.js";
3
+ const JOSE_RULES = [
4
+ {
5
+ re: /"alg"\s*:\s*"RSA(?:-OAEP(?:-256)?|1_5)"/g,
6
+ meta: {
7
+ id: "jose-jwe-rsa",
8
+ title: "JWE RSA key wrapping",
9
+ description: 'JWE "alg" of RSA-OAEP / RSA-OAEP-256 / RSA1_5 (RFC 7518)',
10
+ category: "kem",
11
+ severity: "high",
12
+ confidence: "high",
13
+ algorithm: "RSA",
14
+ hndl: true,
15
+ cwe: CWE_BROKEN_CRYPTO,
16
+ message: "JWE wraps the content-encryption key with classical RSA (RSA-OAEP/RSA1_5); the encrypted payload is harvest-now-decrypt-later exposed.",
17
+ remediation: "Plan migration to a post-quantum KEM (ML-KEM-768) for key wrapping as JOSE/COSE PQ algorithms are standardised.",
18
+ },
19
+ },
20
+ {
21
+ re: /"alg"\s*:\s*"ECDH-ES(?:\+A\d{3}KW)?"/g,
22
+ meta: {
23
+ id: "jose-jwe-ecdh",
24
+ title: "JWE ECDH-ES key agreement",
25
+ description: 'JWE "alg" of ECDH-ES / ECDH-ES+A*KW (RFC 7518)',
26
+ category: "key-exchange",
27
+ severity: "high",
28
+ confidence: "high",
29
+ algorithm: "ECDH",
30
+ hndl: true,
31
+ cwe: CWE_BROKEN_CRYPTO,
32
+ message: "JWE derives the content-encryption key via classical ECDH-ES; the encrypted payload is harvest-now-decrypt-later exposed.",
33
+ remediation: "Plan migration to hybrid post-quantum key agreement (X25519MLKEM768) as JOSE PQ algorithms are standardised.",
34
+ },
35
+ },
36
+ ];
37
+ /** Detects classical JWE key-management (`alg`) values in JOSE tokens/config. */
38
+ export const joseDetector = {
39
+ id: "jose-jwe-keymgmt",
40
+ description: "Classical JWE key-management algorithms (RSA-OAEP, ECDH-ES) — confidentiality, HNDL",
41
+ scope: "config",
42
+ language: "any",
43
+ rules: JOSE_RULES.map((r) => r.meta),
44
+ // Prose examples (a README showing `"alg":"RSA-OAEP"`) are not JOSE config.
45
+ appliesTo: (f) => !hasExtension(f, DOC_EXTENSIONS),
46
+ detect({ file, content }) {
47
+ // Fast reject: no JOSE key-management alg token present.
48
+ if (!content.includes("RSA-OAEP") &&
49
+ !content.includes("RSA1_5") &&
50
+ !content.includes("ECDH-ES")) {
51
+ return [];
52
+ }
53
+ const findings = [];
54
+ for (const rule of JOSE_RULES) {
55
+ eachMatch(rule.re, content, (m) => {
56
+ findings.push(findingFromRule(rule.meta, { file, content, index: m.index, matchLength: m[0].length }));
57
+ });
58
+ }
59
+ return findings;
60
+ },
61
+ };
62
+ //# sourceMappingURL=jose.js.map
@@ -0,0 +1 @@
1
+ {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,YAAY,CAAC,CAAC,EAAE,cAAc,CAAC;IAClD,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE;QACtB,yDAAyD;QACzD,IACE,CAAC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC;YAC7B,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAC3B,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,EAC5B,CAAC;YACD,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,MAAM,QAAQ,GAAc,EAAE,CAAC;QAC/B,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;YAC9B,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;gBAChC,QAAQ,CAAC,IAAI,CACX,eAAe,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CACxF,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC","sourcesContent":["/**\n * Config detector: classical KEY-MANAGEMENT (JWE) algorithms in JOSE. This is\n * distinct from the JWS signature side (RS256/ES256, handled elsewhere) and from\n * the JWK key-material detector: here we flag the `alg` values that wrap a\n * content-encryption key with classical asymmetric crypto, because the encrypted\n * payload is CONFIDENTIALITY — harvest-now-decrypt-later exposed. A JWE token\n * captured today (from a log, an audit trail, a stored assertion) is decryptable\n * once the wrapping key falls to a CRQC.\n *\n * Covered `alg` (RFC 7518 §4) values:\n * - `RSA-OAEP`, `RSA-OAEP-256`, `RSA1_5` → RSA key encryption.\n * - `ECDH-ES`, `ECDH-ES+A128KW`, … → classical EC Diffie-Hellman key agreement.\n *\n * These exact strings are JOSE identifiers, so a content-level match is precise;\n * the detector applies to any file (config, JSON, source) after a fast reject.\n */\nimport type { Detector, Finding, RuleMeta } from \"../types.js\";\nimport { DOC_EXTENSIONS, eachMatch, findingFromRule, hasExtension } from \"../detect-utils.js\";\nimport { CWE_BROKEN_CRYPTO } from \"../cwe.js\";\n\ninterface JoseRule {\n re: RegExp;\n meta: RuleMeta;\n}\n\nconst JOSE_RULES: JoseRule[] = [\n {\n re: /\"alg\"\\s*:\\s*\"RSA(?:-OAEP(?:-256)?|1_5)\"/g,\n meta: {\n id: \"jose-jwe-rsa\",\n title: \"JWE RSA key wrapping\",\n description: 'JWE \"alg\" of RSA-OAEP / RSA-OAEP-256 / RSA1_5 (RFC 7518)',\n category: \"kem\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"JWE wraps the content-encryption key with classical RSA (RSA-OAEP/RSA1_5); the encrypted payload is harvest-now-decrypt-later exposed.\",\n remediation:\n \"Plan migration to a post-quantum KEM (ML-KEM-768) for key wrapping as JOSE/COSE PQ algorithms are standardised.\",\n },\n },\n {\n re: /\"alg\"\\s*:\\s*\"ECDH-ES(?:\\+A\\d{3}KW)?\"/g,\n meta: {\n id: \"jose-jwe-ecdh\",\n title: \"JWE ECDH-ES key agreement\",\n description: 'JWE \"alg\" of ECDH-ES / ECDH-ES+A*KW (RFC 7518)',\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"ECDH\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"JWE derives the content-encryption key via classical ECDH-ES; the encrypted payload is harvest-now-decrypt-later exposed.\",\n remediation:\n \"Plan migration to hybrid post-quantum key agreement (X25519MLKEM768) as JOSE PQ algorithms are standardised.\",\n },\n },\n];\n\n/** Detects classical JWE key-management (`alg`) values in JOSE tokens/config. */\nexport const joseDetector: Detector = {\n id: \"jose-jwe-keymgmt\",\n description:\n \"Classical JWE key-management algorithms (RSA-OAEP, ECDH-ES) — confidentiality, HNDL\",\n scope: \"config\",\n language: \"any\",\n rules: JOSE_RULES.map((r) => r.meta),\n // Prose examples (a README showing `\"alg\":\"RSA-OAEP\"`) are not JOSE config.\n appliesTo: (f) => !hasExtension(f, DOC_EXTENSIONS),\n detect({ file, content }): Finding[] {\n // Fast reject: no JOSE key-management alg token present.\n if (\n !content.includes(\"RSA-OAEP\") &&\n !content.includes(\"RSA1_5\") &&\n !content.includes(\"ECDH-ES\")\n ) {\n return [];\n }\n const findings: Finding[] = [];\n for (const rule of JOSE_RULES) {\n eachMatch(rule.re, content, (m) => {\n findings.push(\n findingFromRule(rule.meta, { file, content, index: m.index, matchLength: m[0].length }),\n );\n });\n }\n return findings;\n },\n};\n"]}
@@ -0,0 +1,25 @@
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
+ * Keying EC/OKP off `crv` (present in every EC/OKP JWK) rather than `kty` avoids
14
+ * double-counting a single key, and `"kty"`/`"crv"` are specific enough to RFC
15
+ * 7517 that the false-positive risk on ordinary JSON is low.
16
+ *
17
+ * HNDL: RSA and (EC)DH / X25519 / X448 key agreement are harvest-now-decrypt-later
18
+ * exposed (hndl:true); EdDSA signing keys are hndl:false but forgeable. A JWKS is
19
+ * usually PUBLIC keys, so severity is medium — the exposure is a classical key
20
+ * pair, not necessarily an embedded secret.
21
+ */
22
+ import type { Detector } from "../types.js";
23
+ /** Detects classical JSON Web Key (JWK/JWKS) material in any JSON/text file. */
24
+ export declare const jwkDetector: Detector;
25
+ //# sourceMappingURL=jwk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwk.d.ts","sourceRoot":"","sources":["../../src/detectors/jwk.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAqB,MAAM,aAAa,CAAC;AAgF/D,gFAAgF;AAChF,eAAO,MAAM,WAAW,EAAE,QAyBzB,CAAC"}
@@ -0,0 +1,95 @@
1
+ import { eachMatch, findingFromRule } from "../detect-utils.js";
2
+ import { CWE_BROKEN_CRYPTO } from "../cwe.js";
3
+ const JWK_RULES = [
4
+ {
5
+ re: /"kty"\s*:\s*"RSA"/g,
6
+ meta: {
7
+ id: "jwk-rsa",
8
+ title: "RSA JSON Web Key (JWK)",
9
+ description: 'JWK with "kty":"RSA" (RFC 7518)',
10
+ category: "certificate",
11
+ severity: "medium",
12
+ confidence: "high",
13
+ algorithm: "RSA",
14
+ hndl: true,
15
+ cwe: CWE_BROKEN_CRYPTO,
16
+ message: "RSA JSON Web Key (JWK); classical RSA, not quantum-safe.",
17
+ remediation: "Re-issue with PQC keys (ML-KEM-768 for encryption, ML-DSA-65 for signatures).",
18
+ },
19
+ },
20
+ {
21
+ re: /"crv"\s*:\s*"(?:P-256K?|P-384|P-521|secp256k1)"/g,
22
+ meta: {
23
+ id: "jwk-ec",
24
+ title: "EC JSON Web Key (JWK)",
25
+ description: 'JWK with an "crv" naming a NIST/secp curve (RFC 7518)',
26
+ category: "key-exchange",
27
+ severity: "medium",
28
+ confidence: "high",
29
+ algorithm: "ECDH",
30
+ hndl: true,
31
+ cwe: CWE_BROKEN_CRYPTO,
32
+ message: "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.",
33
+ remediation: "For key agreement: hybrid X25519MLKEM768 (ML-KEM-768). For signatures: ML-DSA-65 (FIPS 204).",
34
+ },
35
+ },
36
+ {
37
+ re: /"crv"\s*:\s*"Ed(?:25519|448)"/g,
38
+ meta: {
39
+ id: "jwk-eddsa",
40
+ title: "EdDSA JSON Web Key (JWK)",
41
+ description: 'JWK OKP key with "crv":"Ed25519"/"Ed448" (RFC 8037)',
42
+ category: "signature",
43
+ severity: "low",
44
+ confidence: "high",
45
+ algorithm: "EdDSA",
46
+ hndl: false,
47
+ cwe: CWE_BROKEN_CRYPTO,
48
+ message: "EdDSA (Ed25519/Ed448) JSON Web Key (JWK); classical and forgeable by a quantum attacker.",
49
+ remediation: "ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205).",
50
+ },
51
+ },
52
+ {
53
+ re: /"crv"\s*:\s*"X(?:25519|448)"/g,
54
+ meta: {
55
+ id: "jwk-xdh",
56
+ title: "X25519/X448 JSON Web Key (JWK)",
57
+ description: 'JWK OKP key with "crv":"X25519"/"X448" (RFC 8037)',
58
+ category: "key-exchange",
59
+ severity: "medium",
60
+ confidence: "high",
61
+ algorithm: "X25519",
62
+ hndl: true,
63
+ cwe: CWE_BROKEN_CRYPTO,
64
+ message: "X25519/X448 JSON Web Key (JWK); modern but classical key agreement, and harvest-now-decrypt-later exposed.",
65
+ remediation: "Migrate key agreement to hybrid X25519MLKEM768 (ML-KEM-768).",
66
+ },
67
+ },
68
+ ];
69
+ /** Detects classical JSON Web Key (JWK/JWKS) material in any JSON/text file. */
70
+ export const jwkDetector = {
71
+ id: "jwk-material",
72
+ description: "Classical key material in JSON Web Keys (JWK / JWKS)",
73
+ scope: "config",
74
+ language: "any",
75
+ rules: JWK_RULES.map((r) => r.meta),
76
+ appliesTo: () => true,
77
+ detect({ file, content }) {
78
+ // Fast reject: a JWK always has one of these two members.
79
+ if (!content.includes('"kty"') && !content.includes('"crv"'))
80
+ return [];
81
+ const findings = [];
82
+ for (const rule of JWK_RULES) {
83
+ eachMatch(rule.re, content, (m) => {
84
+ findings.push(findingFromRule(rule.meta, {
85
+ file,
86
+ content,
87
+ index: m.index,
88
+ matchLength: m[0].length,
89
+ }));
90
+ });
91
+ }
92
+ return findings;
93
+ },
94
+ };
95
+ //# sourceMappingURL=jwk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwk.js","sourceRoot":"","sources":["../../src/detectors/jwk.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAO9C,MAAM,SAAS,GAAc;IAC3B;QACE,EAAE,EAAE,oBAAoB;QACxB,IAAI,EAAE;YACJ,EAAE,EAAE,SAAS;YACb,KAAK,EAAE,wBAAwB;YAC/B,WAAW,EAAE,iCAAiC;YAC9C,QAAQ,EAAE,aAAa;YACvB,QAAQ,EAAE,QAAQ;YAClB,UAAU,EAAE,MAAM;YAClB,SAAS,EAAE,KAAK;YAChB,IAAI,EAAE,IAAI;YACV,GAAG,EAAE,iBAAiB;YACtB,OAAO,EAAE,0DAA0D;YACnE,WAAW,EAAE,+EAA+E;SAC7F;KACF;IACD;QACE,EAAE,EAAE,kDAAkD;QACtD,IAAI,EAAE;YACJ,EAAE,EAAE,QAAQ;YACZ,KAAK,EAAE,uBAAuB;YAC9B,WAAW,EAAE,uDAAuD;YACpE,QAAQ,EAAE,cAAc;YACxB,QAAQ,EAAE,QAAQ;YAClB,UAAU,EAAE,MAAM;YAClB,SAAS,EAAE,MAAM;YACjB,IAAI,EAAE,IAAI;YACV,GAAG,EAAE,iBAAiB;YACtB,OAAO,EACL,gKAAgK;YAClK,WAAW,EACT,8FAA8F;SACjG;KACF;IACD;QACE,EAAE,EAAE,gCAAgC;QACpC,IAAI,EAAE;YACJ,EAAE,EAAE,WAAW;YACf,KAAK,EAAE,0BAA0B;YACjC,WAAW,EAAE,qDAAqD;YAClE,QAAQ,EAAE,WAAW;YACrB,QAAQ,EAAE,KAAK;YACf,UAAU,EAAE,MAAM;YAClB,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K,EAAE,CAAC,CAAC,KAAK;oBACd,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM;iBACzB,CAAC,CACH,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC","sourcesContent":["/**\n * Config detector: classical key material in JSON Web Keys (JWK / JWKS, RFC 7517\n * / 7518). JWKs appear in `.json` / `.jwks` files, OIDC discovery documents, and\n * config — a real key-material surface the source packs (which look at *code*)\n * and the PEM detector (which looks at PEM markers) both miss.\n *\n * Detection keys off the JWK's distinctive JSON fields:\n * - `\"kty\":\"RSA\"` → classical RSA key.\n * - `\"crv\":\"P-256\"|\"P-384\"|\"P-521\"|…` → classical EC key (ECDSA + ECDH).\n * - `\"crv\":\"Ed25519\"|\"Ed448\"` → EdDSA signing key.\n * - `\"crv\":\"X25519\"|\"X448\"` → classical Montgomery-curve key agreement.\n *\n * Keying EC/OKP off `crv` (present in every EC/OKP JWK) rather than `kty` avoids\n * double-counting a single key, and `\"kty\"`/`\"crv\"` are specific enough to RFC\n * 7517 that the false-positive risk on ordinary JSON is low.\n *\n * HNDL: RSA and (EC)DH / X25519 / X448 key agreement are harvest-now-decrypt-later\n * exposed (hndl:true); EdDSA signing keys are hndl:false but forgeable. A JWKS is\n * usually PUBLIC keys, so severity is medium — the exposure is a classical key\n * pair, not necessarily an embedded secret.\n */\nimport type { Detector, Finding, RuleMeta } from \"../types.js\";\nimport { eachMatch, findingFromRule } from \"../detect-utils.js\";\nimport { CWE_BROKEN_CRYPTO } from \"../cwe.js\";\n\ninterface JwkRule {\n re: RegExp;\n meta: RuleMeta;\n}\n\nconst JWK_RULES: JwkRule[] = [\n {\n re: /\"kty\"\\s*:\\s*\"RSA\"/g,\n meta: {\n id: \"jwk-rsa\",\n title: \"RSA JSON Web Key (JWK)\",\n description: 'JWK with \"kty\":\"RSA\" (RFC 7518)',\n category: \"certificate\",\n severity: \"medium\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"RSA JSON Web Key (JWK); classical RSA, not quantum-safe.\",\n remediation: \"Re-issue with PQC keys (ML-KEM-768 for encryption, ML-DSA-65 for signatures).\",\n },\n },\n {\n re: /\"crv\"\\s*:\\s*\"(?:P-256K?|P-384|P-521|secp256k1)\"/g,\n meta: {\n id: \"jwk-ec\",\n title: \"EC JSON Web Key (JWK)\",\n description: 'JWK with an \"crv\" naming a NIST/secp curve (RFC 7518)',\n category: \"key-exchange\",\n severity: \"medium\",\n confidence: \"high\",\n algorithm: \"ECDH\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"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.\",\n remediation:\n \"For key agreement: hybrid X25519MLKEM768 (ML-KEM-768). For signatures: ML-DSA-65 (FIPS 204).\",\n },\n },\n {\n re: /\"crv\"\\s*:\\s*\"Ed(?:25519|448)\"/g,\n meta: {\n id: \"jwk-eddsa\",\n title: \"EdDSA JSON Web Key (JWK)\",\n description: 'JWK OKP key with \"crv\":\"Ed25519\"/\"Ed448\" (RFC 8037)',\n category: \"signature\",\n severity: \"low\",\n confidence: \"high\",\n algorithm: \"EdDSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"EdDSA (Ed25519/Ed448) JSON Web Key (JWK); classical and forgeable by a quantum attacker.\",\n remediation: \"ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205).\",\n },\n },\n {\n re: /\"crv\"\\s*:\\s*\"X(?:25519|448)\"/g,\n meta: {\n id: \"jwk-xdh\",\n title: \"X25519/X448 JSON Web Key (JWK)\",\n description: 'JWK OKP key with \"crv\":\"X25519\"/\"X448\" (RFC 8037)',\n category: \"key-exchange\",\n severity: \"medium\",\n confidence: \"high\",\n algorithm: \"X25519\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"X25519/X448 JSON Web Key (JWK); modern but classical key agreement, and harvest-now-decrypt-later exposed.\",\n remediation: \"Migrate key agreement to hybrid X25519MLKEM768 (ML-KEM-768).\",\n },\n },\n];\n\n/** Detects classical JSON Web Key (JWK/JWKS) material in any JSON/text file. */\nexport const jwkDetector: Detector = {\n id: \"jwk-material\",\n description: \"Classical key material in JSON Web Keys (JWK / JWKS)\",\n scope: \"config\",\n language: \"any\",\n rules: JWK_RULES.map((r) => r.meta),\n appliesTo: () => true,\n detect({ file, content }): Finding[] {\n // Fast reject: a JWK always has one of these two members.\n if (!content.includes('\"kty\"') && !content.includes('\"crv\"')) return [];\n const findings: Finding[] = [];\n for (const rule of JWK_RULES) {\n eachMatch(rule.re, content, (m) => {\n findings.push(\n findingFromRule(rule.meta, {\n file,\n content,\n index: m.index,\n matchLength: m[0].length,\n }),\n );\n });\n }\n return findings;\n },\n};\n"]}