@hardkeel/benthic 0.0.0-stage → 1.0.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/CHANGELOG.md +121 -0
- package/LICENSE +92 -0
- package/NOTICE +16 -0
- package/README.md +424 -2
- package/action.yml +54 -0
- package/dist/agility.js +80 -0
- package/dist/badge.js +62 -0
- package/dist/baseline.js +81 -0
- package/dist/cbom-diff.js +273 -0
- package/dist/cbom.js +418 -0
- package/dist/cli.js +834 -0
- package/dist/cloud-aws-services.js +375 -0
- package/dist/cloud-aws.js +354 -0
- package/dist/cloud-azure-services.js +73 -0
- package/dist/cloud-azure.js +144 -0
- package/dist/cloud-common.js +242 -0
- package/dist/cloud-gcp-services.js +90 -0
- package/dist/cloud-gcp.js +150 -0
- package/dist/comments.js +138 -0
- package/dist/community-rules.js +37 -0
- package/dist/community.js +30 -0
- package/dist/deps.js +406 -0
- package/dist/der.js +571 -0
- package/dist/evidence-cli.js +235 -0
- package/dist/evidence-live.js +109 -0
- package/dist/evidence.js +512 -0
- package/dist/ignore.js +90 -0
- package/dist/image.js +1224 -0
- package/dist/infra.js +635 -0
- package/dist/inventory.js +277 -0
- package/dist/map-activity.js +24 -0
- package/dist/map-areas.js +60 -0
- package/dist/map-cloud-keys.js +110 -0
- package/dist/map-cloud.js +34 -0
- package/dist/map-ct.js +107 -0
- package/dist/map-host.js +335 -0
- package/dist/map-network.js +520 -0
- package/dist/map-people.js +79 -0
- package/dist/map-rank.js +70 -0
- package/dist/map-report.js +304 -0
- package/dist/map-run.js +327 -0
- package/dist/map-sarif.js +61 -0
- package/dist/map-signin.js +247 -0
- package/dist/map-types.js +19 -0
- package/dist/map-web.js +666 -0
- package/dist/native.js +168 -0
- package/dist/policy.js +221 -0
- package/dist/pqc.js +46 -0
- package/dist/profile.js +65 -0
- package/dist/project.js +928 -0
- package/dist/prose.js +159 -0
- package/dist/protocols.js +207 -0
- package/dist/registry.js +326 -0
- package/dist/report.js +190 -0
- package/dist/rules.js +230 -0
- package/dist/sarif-common.js +30 -0
- package/dist/sarif.js +114 -0
- package/dist/scan.js +601 -0
- package/dist/score.js +124 -0
- package/dist/secrets.js +192 -0
- package/dist/share-config.js +129 -0
- package/dist/share-lists.js +19 -0
- package/dist/share.js +125 -0
- package/dist/sonar.js +83 -0
- package/dist/structure.js +218 -0
- package/dist/suites.js +402 -0
- package/dist/tls-check.js +122 -0
- package/dist/types.js +4 -0
- package/dist/walk.js +78 -0
- package/dist/yaml.js +173 -0
- package/package.json +73 -4
package/dist/prose.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// SPDX-License-Identifier: PolyForm-Shield-1.0.0
|
|
2
|
+
// Copyright 2026 Hard Keel (https://hardkeel.com)
|
|
3
|
+
// Text that names an algorithm without using it: sentences in strings, translation catalogs, and the
|
|
4
|
+
// rows of a detection table (a scanner's own list of what to look for, or a list of findings).
|
|
5
|
+
// "Your files are protected with ML-KEM-768" is a label shown to people; { name: "ECDH", severity: "high" }
|
|
6
|
+
// is a rule that looks for ECDH. Neither runs any encryption.
|
|
7
|
+
// Translation folders and catalog formats.
|
|
8
|
+
export const LOCALE_PATH = /(^|\/)(locales?|i18n|l10n|translations?|nls)\/|\.(po|pot|xliff|xlf|ftl|strings|arb|resx)$/i;
|
|
9
|
+
// Catalogs named for their language: en.json, de-DE.json, pt_BR.yml, messages.fr.json, strings-es.properties.
|
|
10
|
+
const LANGS = "ar|bg|bn|ca|cs|da|de|el|en|es|et|fa|fi|fr|he|hi|hr|hu|id|it|ja|ko|lt|lv|ms|nb|nl|nn|no|pl|pt|ro|ru|sk|sl|sr|sv|sw|ta|th|tr|uk|ur|vi|zh";
|
|
11
|
+
const LANG_FILE = new RegExp(`(^|/)(?:(?:messages|strings|translations?|lang|locale|i18n)[._-])?(?:${LANGS})(?:[-_][A-Za-z]{2,4})?\\.(json|ya?ml|properties|toml)$`, "i");
|
|
12
|
+
const DATA_FILE = /\.(json|ya?ml|properties|toml)$/i;
|
|
13
|
+
/** A word of a sentence: letters, perhaps with the punctuation that ends a word. */
|
|
14
|
+
const WORD = /^[A-Za-z][a-z]+[.,;:!?)"']*$/;
|
|
15
|
+
/**
|
|
16
|
+
* Whether a file is a translation catalog: by its folder or name, or a data file whose values are
|
|
17
|
+
* mostly sentences.
|
|
18
|
+
*/
|
|
19
|
+
export function isTranslationFile(path, lines) {
|
|
20
|
+
if (LOCALE_PATH.test(path) || LANG_FILE.test(path))
|
|
21
|
+
return true;
|
|
22
|
+
if (!DATA_FILE.test(path))
|
|
23
|
+
return false;
|
|
24
|
+
let values = 0;
|
|
25
|
+
let sentences = 0;
|
|
26
|
+
for (const line of lines.slice(0, 400)) {
|
|
27
|
+
const m = line.match(/^\s*["']?[\w.$-]+["']?\s*[:=]\s*["']?(.+?)["']?\s*,?\s*$/);
|
|
28
|
+
if (!m || /^[[{]$/.test(m[1]))
|
|
29
|
+
continue;
|
|
30
|
+
values++;
|
|
31
|
+
if (m[1].split(/\s+/).filter((w) => WORD.test(w)).length >= 3)
|
|
32
|
+
sentences++;
|
|
33
|
+
}
|
|
34
|
+
return values >= 8 && sentences / values >= 0.6;
|
|
35
|
+
}
|
|
36
|
+
/** The string literals on a line, as [start, end) of their contents. */
|
|
37
|
+
function stringsOn(text) {
|
|
38
|
+
const out = [];
|
|
39
|
+
let quote = null;
|
|
40
|
+
let from = 0;
|
|
41
|
+
for (let i = 0; i < text.length; i++) {
|
|
42
|
+
const c = text[i];
|
|
43
|
+
if (quote) {
|
|
44
|
+
if (c === "\\")
|
|
45
|
+
i++;
|
|
46
|
+
else if (c === quote) {
|
|
47
|
+
out.push([from, i]);
|
|
48
|
+
quote = null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else if (c === '"' || c === "`" || (c === "'" && !/[A-Za-z]/.test(text[i - 1] ?? ""))) {
|
|
52
|
+
quote = c;
|
|
53
|
+
from = i + 1;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* A sentence: three words or more. Not a command line (openssl genrsa -out key.pem 2048), and not
|
|
60
|
+
* fields inside one string, like a Go struct tag (json:"alg" jsonschema:"enum=ES256,...").
|
|
61
|
+
*/
|
|
62
|
+
function isSentence(s) {
|
|
63
|
+
if (/(^|\s)--?[A-Za-z]/.test(s) || /\w[:=]"/.test(s))
|
|
64
|
+
return false;
|
|
65
|
+
return s.split(/\s+/).filter((w) => WORD.test(w)).length >= 3;
|
|
66
|
+
}
|
|
67
|
+
const PLAIN_VALUE = /\.(ya?ml|properties|toml|ini|cfg|conf)$/i;
|
|
68
|
+
/**
|
|
69
|
+
* Whether the text at [start, end) on a line sits in a sentence: inside a string whose contents read
|
|
70
|
+
* as prose, or in a settings file, an unquoted value that does.
|
|
71
|
+
*/
|
|
72
|
+
export function inProse(text, start, end, path = "") {
|
|
73
|
+
for (const [s, e] of stringsOn(text)) {
|
|
74
|
+
if (e <= start || s >= end)
|
|
75
|
+
continue;
|
|
76
|
+
return isSentence(text.slice(s, e));
|
|
77
|
+
}
|
|
78
|
+
if (PLAIN_VALUE.test(path)) {
|
|
79
|
+
const m = text.match(/^\s*[\w.-]+\s*[:=]\s*/);
|
|
80
|
+
if (m && start >= m[0].length)
|
|
81
|
+
return isSentence(text.slice(m[0].length));
|
|
82
|
+
}
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
// A rating, as a detection rule or a finding carries one.
|
|
86
|
+
const RATING = /["']?\b(?:severity|risk[_-]?level|confidence|cwe(?:[_-]?id)?)\b["']?\s*[:=]\s*["']?(?:critical|high|medium|moderate|low|info|informational|warning|error|cwe-\d+|\d+)\b/i;
|
|
87
|
+
// A rating in a row of values: ("ECDH", re.compile(r"..."), "high").
|
|
88
|
+
const ROW_RATING = /,\s*["'](?:critical|high|medium|low)["']\s*[,)\]}]/i;
|
|
89
|
+
// What a rule looks for.
|
|
90
|
+
const DETECT = /["']?\b(?:pattern|patterns|regex|regexp|match|matcher|detect|detector|example|examples|needle|query)\b["']?\s*[:=]/i;
|
|
91
|
+
const REGEX_CTOR = /\bre\.compile\s*\(|\bnew\s+RegExp\s*\(|\bPattern\.compile\s*\(|\bregexp\.MustCompile\s*\(|\bRegex(?:::new)?\s*\(/;
|
|
92
|
+
// What names a rule or a finding.
|
|
93
|
+
const ID_KEY = /["']?\b(?:id|rule[_-]?id|ruleId|check[_-]?id)\b["']?\s*[:=]\s*["'][\w.:/-]+["']/i;
|
|
94
|
+
const TEXT_KEY = /["']?\b(?:description|message|remediation|title|summary)\b["']?\s*[:=]/i;
|
|
95
|
+
/**
|
|
96
|
+
* The record a line belongs to: the line itself, or the { ... } it sits in when that is a value in a
|
|
97
|
+
* list or a field (not a function body or a block of code), at most a dozen lines each way.
|
|
98
|
+
*/
|
|
99
|
+
function recordAround(lines, idx) {
|
|
100
|
+
let start = idx;
|
|
101
|
+
let depth = 0;
|
|
102
|
+
for (let j = idx - 1; j >= Math.max(0, idx - 12); j--) {
|
|
103
|
+
const l = lines[j];
|
|
104
|
+
for (let k = l.length - 1; k >= 0; k--) {
|
|
105
|
+
if (l[k] === "}")
|
|
106
|
+
depth--;
|
|
107
|
+
else if (l[k] === "{")
|
|
108
|
+
depth++;
|
|
109
|
+
if (depth > 0) {
|
|
110
|
+
// A record opens after [ , ( = : or at the start of its line; a block opens after ) or => or a keyword.
|
|
111
|
+
const before = l.slice(0, k).trimEnd();
|
|
112
|
+
if (before === "" || /[[,(=:]$/.test(before))
|
|
113
|
+
start = j;
|
|
114
|
+
j = -1;
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (start === idx)
|
|
120
|
+
return lines[idx];
|
|
121
|
+
let end = idx;
|
|
122
|
+
depth = 0;
|
|
123
|
+
for (let j = start; j <= Math.min(lines.length - 1, idx + 12); j++) {
|
|
124
|
+
for (const c of lines[j])
|
|
125
|
+
depth += c === "{" ? 1 : c === "}" ? -1 : 0;
|
|
126
|
+
end = j;
|
|
127
|
+
if (j >= idx && depth <= 0)
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
return lines.slice(start, end + 1).join("\n");
|
|
131
|
+
}
|
|
132
|
+
// A record is some of a file's lines joined with "\n", so it can only rate or look for something where
|
|
133
|
+
// the whole file, joined the same way, does. Most files do neither, and then no line needs a record.
|
|
134
|
+
const TABLE_HINT = new WeakMap();
|
|
135
|
+
function mayHoldTable(lines) {
|
|
136
|
+
let hint = TABLE_HINT.get(lines);
|
|
137
|
+
if (hint === undefined) {
|
|
138
|
+
const all = lines.join("\n");
|
|
139
|
+
hint = RATING.test(all) || ROW_RATING.test(all) || DETECT.test(all) || REGEX_CTOR.test(all);
|
|
140
|
+
TABLE_HINT.set(lines, hint);
|
|
141
|
+
}
|
|
142
|
+
return hint;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Whether a line is part of a detection rule or a finding: a record that rates something and says
|
|
146
|
+
* what it looks for or what it is, or one that says what to look for and names the rule.
|
|
147
|
+
*/
|
|
148
|
+
export function inDetectionTable(lines, idx) {
|
|
149
|
+
const line = lines[idx];
|
|
150
|
+
if (!line || !line.trim())
|
|
151
|
+
return false;
|
|
152
|
+
if (!mayHoldTable(lines))
|
|
153
|
+
return false;
|
|
154
|
+
const rec = recordAround(lines, idx);
|
|
155
|
+
const rated = RATING.test(rec) || ROW_RATING.test(rec);
|
|
156
|
+
const looks = DETECT.test(rec) || REGEX_CTOR.test(rec);
|
|
157
|
+
const named = ID_KEY.test(rec);
|
|
158
|
+
return (rated && (looks || named || TEXT_KEY.test(rec))) || (looks && named);
|
|
159
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
// SPDX-License-Identifier: PolyForm-Shield-1.0.0
|
|
2
|
+
// Copyright 2026 Hard Keel (https://hardkeel.com)
|
|
3
|
+
// Every protocol version, cipher suite and SSH algorithm a config file turns on, strong or weak.
|
|
4
|
+
// Findings name only what to fix; this lists everything in use, for an inventory a reviewer can sign
|
|
5
|
+
// (PCI DSS 12.3.3 asks for all of it). Cipher strings are expanded and named cloud policies looked up,
|
|
6
|
+
// so "HIGH:!aNULL" and "ELBSecurityPolicy-2016-08" become the suites they actually enable.
|
|
7
|
+
import { expandCipherString, namedPolicy, protocolVerdict, sshVerdict, suiteByName, suiteVerdict, TLS13_DEFAULT } from "./suites.js";
|
|
8
|
+
import { stripTrailingComment } from "./comments.js";
|
|
9
|
+
const VERSIONS = ["1.0", "1.1", "1.2", "1.3"];
|
|
10
|
+
/** A TLS or SSL version in any of the spellings configs use, as "1.2", "SSLv3", or null. */
|
|
11
|
+
export function tlsVersion(raw) {
|
|
12
|
+
const v = raw.trim().replace(/^["']|["']$/g, "");
|
|
13
|
+
if (/^SSLv?2$/i.test(v))
|
|
14
|
+
return "SSLv2";
|
|
15
|
+
if (/^SSLv?3$/i.test(v))
|
|
16
|
+
return "SSLv3";
|
|
17
|
+
// VersionTLS12 (Go), TLSv1_2 (Python, CloudFront), TLS1_2 (Azure), TLSv1.2, TLS-1-2, Tls12 (.NET), 1.2
|
|
18
|
+
const m = v.match(/(?:TLS|Tls)[-_ v.]?(?:Version)?[-_ ]?1(?:[-._]?([0-3])(?!\d))?/i) ?? v.match(/^(?:Version)?TLS1([0-3])$/i) ?? v.match(/^1[._]([0-3])$/);
|
|
19
|
+
if (m)
|
|
20
|
+
return `1.${m[1] ?? 0}`;
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
const fromMin = (min) => (min.startsWith("SSL") ? ["SSLv3", ...VERSIONS] : VERSIONS.filter((v) => v >= min));
|
|
24
|
+
const trimSetting = (s) => {
|
|
25
|
+
const t = s.trim().replace(/\s+/g, " ");
|
|
26
|
+
return t.length > 120 ? `${t.slice(0, 117)}...` : t;
|
|
27
|
+
};
|
|
28
|
+
function versionUse(v, file, line, setting) {
|
|
29
|
+
return { protocol: "tls", kind: "tls-version", name: v.startsWith("SSL") ? v : `TLS ${v}`, seen: "config", file, line, setting, ...protocolVerdict(v) };
|
|
30
|
+
}
|
|
31
|
+
function suiteUse(name, file, line, setting) {
|
|
32
|
+
const s = suiteByName(name);
|
|
33
|
+
if (!s)
|
|
34
|
+
return null;
|
|
35
|
+
return {
|
|
36
|
+
protocol: "tls",
|
|
37
|
+
kind: "tls-suite",
|
|
38
|
+
name: s.iana,
|
|
39
|
+
...(s.openssl !== s.iana ? { alias: s.openssl } : {}),
|
|
40
|
+
code: `0x${s.code.toString(16).toUpperCase().padStart(4, "0")}`,
|
|
41
|
+
seen: "config",
|
|
42
|
+
file,
|
|
43
|
+
line,
|
|
44
|
+
setting,
|
|
45
|
+
...suiteVerdict(s),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/** Apache/nginx/HAProxy protocol lists, with "all", "+" and "-" read the way Apache reads them. */
|
|
49
|
+
function protocolList(list) {
|
|
50
|
+
const on = new Set();
|
|
51
|
+
for (const t of list.split(/[\s,]+/).filter(Boolean)) {
|
|
52
|
+
const word = t.replace(/^[+!-]/, "");
|
|
53
|
+
const v = /^all$/i.test(word) ? null : tlsVersion(word);
|
|
54
|
+
const set = /^all$/i.test(word) ? ["SSLv3", ...VERSIONS] : v ? [v] : [];
|
|
55
|
+
for (const x of set)
|
|
56
|
+
(t.startsWith("-") || t.startsWith("!") ? on.delete(x) : on.add(x));
|
|
57
|
+
}
|
|
58
|
+
return [...on];
|
|
59
|
+
}
|
|
60
|
+
const PROTOCOL_LIST = /(?:^|[\s"'/])(ssl_protocols|SSLProtocol|ssl-protocols|ssl_protocol_list)["']?\s*[:=\s]\s*["']?([^;"'#\n]+)/i;
|
|
61
|
+
const CIPHER_LIST = /(?:^|[\s"'/])(ssl_ciphers|SSLCipherSuite|ssl-default-bind-ciphers|ssl-default-server-ciphers|ssl-ciphers|ssl_cipher_list)["']?\s*[:=\s]\s*["']?([^;"'#\n]+)/i;
|
|
62
|
+
const TLS13_LIST = /(?:Ciphersuites\s+|ssl-default-(?:bind|server)-ciphersuites\s+|SSLCipherSuite\s+TLSv1\.3\s+|ciphersuites\s*[:=]\s*["']?)([A-Z0-9_:]+)/i;
|
|
63
|
+
const MIN_KEY = /(?:^|[\s"'{,.(])(min_?tls_?version|minimum_tls_version|tls_min_version|min_tls|minimum_protocol_version|MinimumProtocolVersion|MinTlsVersion|MinimumTlsVersion|minimalTlsVersion|minTlsVersion|minVersion|MinVersion|minimum_version|ssl_minimum_version|ssl_min_protocol_version|ssl-min-ver|TLSMinimumVersion)["']?\s*[:=\s]\s*["']?(?:ssl\.TLSVersion\.|tls\.|TlsVersion\.|SslProtocols\.)?([A-Za-z0-9._-]+)/;
|
|
64
|
+
const POLICY_KEY = /(?:^|[\s"'{,/])(?:ssl_policy|ssl-policy|SslPolicy|security_policy|SecurityPolicy|policy_name|policyName|PolicyName|predefined_policy_name|tls_security_policy|TLSSecurityPolicy)["']?\s*[:=]\s*["']?((?:ELBSecurityPolicy-|AppGwSslPolicy)[A-Za-z0-9-]+)/;
|
|
65
|
+
const GCP_PROFILE = /^\s*["']?profile["']?\s*[:=]\s*["']?(COMPATIBLE|MODERN|RESTRICTED|FIPS_202205)\b/;
|
|
66
|
+
// Node: ciphers: "..."; Python: set_ciphers("..."); Java: setEnabledCipherSuites(...); Go: tls.TLS_ECDHE_...
|
|
67
|
+
const CODE_CIPHERS = /(?:\bciphers\s*:\s*|set_ciphers\(\s*)["'`]([^"'`]+)["'`]/;
|
|
68
|
+
const JAVA_SUITES = /setEnabledCipherSuites\(([^)]*)/;
|
|
69
|
+
const JAVA_PROTOCOLS = /setEnabledProtocols\(([^)]*)/;
|
|
70
|
+
const GO_SUITE = /\btls\.(TLS_[A-Z0-9_]+)\b/g;
|
|
71
|
+
const SSH_KEYS = { kexalgorithms: "kex", ciphers: "cipher", macs: "mac", hostkeyalgorithms: "hostkey" };
|
|
72
|
+
const SSH_KIND = { kex: "ssh-kex", cipher: "ssh-cipher", mac: "ssh-mac", hostkey: "ssh-hostkey" };
|
|
73
|
+
const isSshConfig = (path) => /(^|[\\/])(sshd?_config)(\.d[\\/][^\\/]+)?$|(^|[\\/])sshd?_config[^\\/]*\.conf$/i.test(path);
|
|
74
|
+
const isCode = (path) => /\.(js|mjs|cjs|ts|tsx|go|java|kt|py|cs)$/i.test(path);
|
|
75
|
+
const isConfig = (path) => /\.(conf|cfg|cnf|ini|toml|properties|tf|tfvars|hcl|ya?ml|json|template|env)$/i.test(path) || /(^|[\\/])(nginx|apache2?|httpd|haproxy)[^\\/]*$|(^|[\\/])sites-(available|enabled)[\\/]|(^|[\\/])\.htaccess$/i.test(path);
|
|
76
|
+
/** Everything a file turns on: TLS versions, TLS suites and SSH algorithms. */
|
|
77
|
+
export function findProtocols(path, content) {
|
|
78
|
+
if (content.includes("\u0000") || !(isSshConfig(path) || isCode(path) || isConfig(path)))
|
|
79
|
+
return [];
|
|
80
|
+
const out = [];
|
|
81
|
+
const seen = new Set();
|
|
82
|
+
const push = (u) => {
|
|
83
|
+
if (!u)
|
|
84
|
+
return;
|
|
85
|
+
const k = `${u.kind}|${u.name}|${u.line}`;
|
|
86
|
+
if (seen.has(k))
|
|
87
|
+
return;
|
|
88
|
+
seen.add(k);
|
|
89
|
+
out.push(u);
|
|
90
|
+
};
|
|
91
|
+
const lines = content.split(/\r?\n/);
|
|
92
|
+
const ssh = isSshConfig(path);
|
|
93
|
+
const code = isCode(path);
|
|
94
|
+
for (let i = 0; i < lines.length; i++) {
|
|
95
|
+
const raw = lines[i];
|
|
96
|
+
if (raw.length > 2000)
|
|
97
|
+
continue;
|
|
98
|
+
const t = stripTrailingComment(raw, path);
|
|
99
|
+
if (/^\s*(#|\/\/|;|\*)/.test(t))
|
|
100
|
+
continue;
|
|
101
|
+
const no = i + 1;
|
|
102
|
+
if (ssh) {
|
|
103
|
+
const m = t.match(/^\s*(KexAlgorithms|Ciphers|MACs|HostKeyAlgorithms)\s+(\S+)/i);
|
|
104
|
+
if (m) {
|
|
105
|
+
const list = SSH_KEYS[m[1].toLowerCase()];
|
|
106
|
+
// "+" adds to the OpenSSH defaults, "-" removes, "^" puts first: the names given are the ones to record.
|
|
107
|
+
const removing = m[2].startsWith("-");
|
|
108
|
+
if (removing)
|
|
109
|
+
continue;
|
|
110
|
+
for (const name of m[2].replace(/^[+^]/, "").split(",").filter(Boolean)) {
|
|
111
|
+
push({ protocol: "ssh", kind: SSH_KIND[list], name, seen: "config", file: path, line: no, setting: trimSetting(t), ...sshVerdict(list, name) });
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
const pl = t.match(PROTOCOL_LIST);
|
|
117
|
+
if (pl)
|
|
118
|
+
for (const v of protocolList(pl[2]))
|
|
119
|
+
push(versionUse(v, path, no, trimSetting(t)));
|
|
120
|
+
const mk = t.match(MIN_KEY);
|
|
121
|
+
if (mk && !(code && /^min_?tls$/i.test(mk[1]))) {
|
|
122
|
+
const v = tlsVersion(mk[2]);
|
|
123
|
+
if (v)
|
|
124
|
+
for (const x of fromMin(v))
|
|
125
|
+
push(versionUse(x, path, no, trimSetting(t)));
|
|
126
|
+
}
|
|
127
|
+
const cl = t.match(CIPHER_LIST);
|
|
128
|
+
const cc = code ? t.match(CODE_CIPHERS) : null;
|
|
129
|
+
const str = cl?.[2] ?? cc?.[1];
|
|
130
|
+
if (str && !/^\$|\{\{|\$\{/.test(str.trim())) {
|
|
131
|
+
// Apache lets SSLCipherSuite name a protocol first; that form is the TLS 1.3 list, read below.
|
|
132
|
+
if (!/^\s*TLSv1\.3\b/i.test(str))
|
|
133
|
+
for (const s of expandCipherString(str).suites)
|
|
134
|
+
push(suiteUse(s.openssl, path, no, trimSetting(t)));
|
|
135
|
+
}
|
|
136
|
+
const t13 = t.match(TLS13_LIST);
|
|
137
|
+
if (t13)
|
|
138
|
+
for (const n of t13[1].split(":").filter(Boolean))
|
|
139
|
+
push(suiteUse(n, path, no, trimSetting(t)));
|
|
140
|
+
const pol = t.match(POLICY_KEY);
|
|
141
|
+
if (pol)
|
|
142
|
+
addPolicy(pol[1], path, no, push);
|
|
143
|
+
const gp = /\.(tf|hcl|ya?ml|json)$/i.test(path) ? t.match(GCP_PROFILE) : null;
|
|
144
|
+
if (gp)
|
|
145
|
+
addPolicy(gp[1], path, no, push);
|
|
146
|
+
if (code) {
|
|
147
|
+
const js = t.match(JAVA_SUITES);
|
|
148
|
+
if (js)
|
|
149
|
+
for (const q of js[1].matchAll(/"([A-Z0-9_]+)"/g))
|
|
150
|
+
push(suiteUse(q[1], path, no, trimSetting(t)));
|
|
151
|
+
const jp = t.match(JAVA_PROTOCOLS);
|
|
152
|
+
if (jp)
|
|
153
|
+
for (const q of jp[1].matchAll(/"([A-Za-z0-9.]+)"/g)) {
|
|
154
|
+
const v = tlsVersion(q[1]);
|
|
155
|
+
if (v)
|
|
156
|
+
push(versionUse(v, path, no, trimSetting(t)));
|
|
157
|
+
}
|
|
158
|
+
if (/\.go$/i.test(path) && /CipherSuites/.test(lines.slice(Math.max(0, i - 3), i + 1).join("\n"))) {
|
|
159
|
+
for (const q of t.matchAll(GO_SUITE))
|
|
160
|
+
push(suiteUse(q[1], path, no, trimSetting(t)));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// TLS 1.3 turned on with no TLS 1.3 suites named: the library's defaults are in use, so list them.
|
|
165
|
+
const t13 = out.find((u) => u.kind === "tls-version" && u.name === "TLS 1.3" && u.seen === "config");
|
|
166
|
+
if (t13 && !out.some((u) => u.kind === "tls-suite" && /^TLS_(AES|CHACHA20)_/.test(u.name))) {
|
|
167
|
+
for (const u of tls13Defaults(path, t13.line, "TLS 1.3 default suites (none named in this file)"))
|
|
168
|
+
push(u);
|
|
169
|
+
}
|
|
170
|
+
return out;
|
|
171
|
+
}
|
|
172
|
+
function addPolicy(name, file, line, push) {
|
|
173
|
+
const p = namedPolicy(name);
|
|
174
|
+
if (!p)
|
|
175
|
+
return;
|
|
176
|
+
const setting = `${p.provider} policy ${name}`;
|
|
177
|
+
push({
|
|
178
|
+
protocol: "tls",
|
|
179
|
+
kind: "tls-policy",
|
|
180
|
+
name,
|
|
181
|
+
seen: "config",
|
|
182
|
+
file,
|
|
183
|
+
line,
|
|
184
|
+
setting,
|
|
185
|
+
strength: p.protocols.some((v) => v < "1.2") ? "weak" : "strong",
|
|
186
|
+
quantum: p.pq ? "safe" : "breakable",
|
|
187
|
+
why: p.suites.length
|
|
188
|
+
? `${p.protocols.length} protocol version${p.protocols.length === 1 ? "" : "s"} and ${p.suites.length} suites, listed below.${p.pq ? " Adds hybrid ML-KEM key exchange." : ""}`
|
|
189
|
+
: "The provider sets the suite list from the profile and the minimum TLS version; read it from the account with benthic cloud, or check the server live.",
|
|
190
|
+
source: p.source,
|
|
191
|
+
});
|
|
192
|
+
for (const v of p.protocols)
|
|
193
|
+
push(versionUse(v, file, line, setting));
|
|
194
|
+
for (const s of p.suites)
|
|
195
|
+
push(suiteUse(s, file, line, setting));
|
|
196
|
+
}
|
|
197
|
+
/** Suites a server negotiates by TLS 1.3 default when nothing names them. */
|
|
198
|
+
export function tls13Defaults(file, line, setting) {
|
|
199
|
+
return TLS13_DEFAULT.map((n) => suiteUse(n, file, line, setting)).filter((u) => !!u);
|
|
200
|
+
}
|
|
201
|
+
export function protocolUse(kind, name, where) {
|
|
202
|
+
if (kind === "tls-version")
|
|
203
|
+
return versionUse(name, where.file, where.line, where.setting);
|
|
204
|
+
if (kind === "tls-suite")
|
|
205
|
+
return suiteUse(name, where.file, where.line, where.setting);
|
|
206
|
+
return { protocol: "ssh", kind: SSH_KIND[kind], name, seen: "config", file: where.file, line: where.line, setting: where.setting, ...sshVerdict(kind, name) };
|
|
207
|
+
}
|