cbomly 0.2.0__py3-none-any.whl
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.
- cbomly/__init__.py +3 -0
- cbomly/__main__.py +5 -0
- cbomly/algorithms.py +218 -0
- cbomly/cbom.py +216 -0
- cbomly/cbom_names.py +35 -0
- cbomly/cli.py +191 -0
- cbomly/detect/__init__.py +1 -0
- cbomly/detect/deps.py +81 -0
- cbomly/detect/keys.py +319 -0
- cbomly/detect/services.py +69 -0
- cbomly/detect/source.py +358 -0
- cbomly/findings.py +29 -0
- cbomly/inventory.py +150 -0
- cbomly/packs/au.toml +45 -0
- cbomly/packs/baseline.toml +110 -0
- cbomly/packs/ca.toml +61 -0
- cbomly/packs/eu.toml +117 -0
- cbomly/packs/india.toml +102 -0
- cbomly/packs/jp.toml +44 -0
- cbomly/packs/pci-dss.toml +55 -0
- cbomly/packs/sg.toml +45 -0
- cbomly/packs/uk.toml +47 -0
- cbomly/packs/us-cnsa2.toml +97 -0
- cbomly/packs/us-fda.toml +63 -0
- cbomly/packs/us.toml +145 -0
- cbomly/report.py +188 -0
- cbomly/rules.py +235 -0
- cbomly/sbom.py +54 -0
- cbomly/scanner.py +77 -0
- cbomly/upload.py +96 -0
- cbomly-0.2.0.dist-info/METADATA +202 -0
- cbomly-0.2.0.dist-info/RECORD +37 -0
- cbomly-0.2.0.dist-info/WHEEL +5 -0
- cbomly-0.2.0.dist-info/entry_points.txt +2 -0
- cbomly-0.2.0.dist-info/licenses/LICENSE +202 -0
- cbomly-0.2.0.dist-info/licenses/NOTICE +4 -0
- cbomly-0.2.0.dist-info/top_level.txt +1 -0
cbomly/detect/source.py
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
"""Find crypto API calls in source code and config files.
|
|
2
|
+
|
|
3
|
+
This is a pattern-based detector: it looks for the well-known function and
|
|
4
|
+
class names each language uses for crypto (for example Java's
|
|
5
|
+
KeyPairGenerator.getInstance("RSA") or Python's rsa.generate_private_key).
|
|
6
|
+
It is fast and works on any codebase without building it, at the cost of
|
|
7
|
+
some false positives. Each pattern carries a confidence level.
|
|
8
|
+
|
|
9
|
+
A named group "p" in a pattern captures a parameter (key size, curve, hash).
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import re
|
|
15
|
+
from dataclasses import dataclass
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
from ..findings import Finding
|
|
19
|
+
|
|
20
|
+
LANGS = {
|
|
21
|
+
"py": {".py", ".pyi"},
|
|
22
|
+
"java": {".java", ".kt", ".kts", ".scala", ".groovy"},
|
|
23
|
+
"go": {".go"},
|
|
24
|
+
"js": {".js", ".mjs", ".cjs", ".ts", ".tsx", ".jsx"},
|
|
25
|
+
"c": {".c", ".h", ".cc", ".cpp", ".cxx", ".hpp", ".hh", ".m", ".mm"},
|
|
26
|
+
"cs": {".cs"},
|
|
27
|
+
"rb": {".rb"},
|
|
28
|
+
"php": {".php"},
|
|
29
|
+
"rs": {".rs"},
|
|
30
|
+
"swift": {".swift"},
|
|
31
|
+
"config": {".conf", ".cfg", ".cnf", ".ini", ".yaml", ".yml", ".toml", ".properties",
|
|
32
|
+
".xml", ".json", ".env", ".tf", ".hcl"},
|
|
33
|
+
}
|
|
34
|
+
CODE = set().union(*(v for k, v in LANGS.items() if k != "config"))
|
|
35
|
+
ALL = CODE | LANGS["config"]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@dataclass(frozen=True)
|
|
39
|
+
class Pattern:
|
|
40
|
+
algorithm: str
|
|
41
|
+
regex: re.Pattern
|
|
42
|
+
langs: frozenset[str]
|
|
43
|
+
function: str | None = None
|
|
44
|
+
confidence: str = "high"
|
|
45
|
+
params: str | None = None # fixed params when not captured
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def P(alg, rx, langs, function=None, confidence="high", params=None, flags=0):
|
|
49
|
+
exts = set()
|
|
50
|
+
for lang in langs.split():
|
|
51
|
+
exts |= ALL if lang == "any" else CODE if lang == "code" else LANGS[lang]
|
|
52
|
+
return Pattern(alg, re.compile(rx, flags), frozenset(exts), function, confidence, params)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
I = re.IGNORECASE
|
|
56
|
+
Q = r"""["']""" # a quote
|
|
57
|
+
|
|
58
|
+
PATTERNS: list[Pattern] = [
|
|
59
|
+
# ---------------- Python (cryptography, pycryptodome, stdlib) ----
|
|
60
|
+
P("rsa", r"rsa\.generate_private_key\([^)]*?key_size\s*=\s*(?P<p>\d+)", "py", "keygen"),
|
|
61
|
+
P("rsa", r"rsa\.generate_private_key\(", "py", "keygen"),
|
|
62
|
+
P("rsa", r"\bRSA\.(?:generate|import_key|importKey)\(\s*(?P<p>\d{3,5})?", "py", "keygen"),
|
|
63
|
+
P("rsa", r"\bPKCS1_OAEP\.new\(|\bpadding\.OAEP\(", "py", "encrypt"),
|
|
64
|
+
P("rsa-sig", r"\bpkcs1_15\.new\(|\bpadding\.PSS\(|\bpadding\.PKCS1v15\(", "py", "sign"),
|
|
65
|
+
P("ec", r"\bec\.(?P<p>SECP\d+[RK]1)\b", "py"),
|
|
66
|
+
P("ecdsa", r"\bec\.ECDSA\(|\bDSS\.new\(", "py", "sign"),
|
|
67
|
+
P("ecdh", r"\bec\.ECDH\(\)", "py", "keyderive"),
|
|
68
|
+
P("ed25519", r"\bEd25519Private(?:Key)?\b", "py", "sign"),
|
|
69
|
+
P("x25519", r"\bX25519Private(?:Key)?\b", "py", "keyderive"),
|
|
70
|
+
P("dsa", r"\bdsa\.generate_private_key\(|from Crypto\.PublicKey import DSA", "py", "keygen"),
|
|
71
|
+
P("dh", r"\bdh\.generate_parameters\(", "py", "keygen"),
|
|
72
|
+
P("md5", r"\bhashlib\.md5\(|hashlib\.new\(\s*" + Q + r"md5", "py", "digest"),
|
|
73
|
+
P("sha1", r"\bhashlib\.sha1\(|hashlib\.new\(\s*" + Q + r"sha1", "py", "digest"),
|
|
74
|
+
P("md5", r"\bhashes\.MD5\(|\bMD5\.new\(", "py", "digest"),
|
|
75
|
+
P("sha1", r"\bhashes\.SHA1\(|\bSHA1\.new\(", "py", "digest"),
|
|
76
|
+
P("3des", r"\balgorithms\.TripleDES\(|\bDES3\.new\(", "py", "encrypt"),
|
|
77
|
+
P("des", r"\bDES\.new\(", "py", "encrypt"),
|
|
78
|
+
P("rc4", r"\balgorithms\.ARC4\(|\bARC4\.new\(", "py", "encrypt"),
|
|
79
|
+
P("ecb", r"\bmodes\.ECB\(|AES\.MODE_ECB", "py", "encrypt"),
|
|
80
|
+
|
|
81
|
+
# ---------------- Java / Kotlin (JCA, Bouncy Castle) --------------
|
|
82
|
+
P("rsa", r"KeyPairGenerator\.getInstance\(\s*\"RSA\"", "java", "keygen"),
|
|
83
|
+
P("ec", r"KeyPairGenerator\.getInstance\(\s*\"EC(?:DSA)?\"", "java", "keygen"),
|
|
84
|
+
P("dsa", r"KeyPairGenerator\.getInstance\(\s*\"DSA\"", "java", "keygen"),
|
|
85
|
+
P("dh", r"KeyPairGenerator\.getInstance\(\s*\"(?:DH|DiffieHellman)\"", "java", "keygen"),
|
|
86
|
+
P("ed25519", r"KeyPairGenerator\.getInstance\(\s*\"Ed25519\"", "java", "keygen"),
|
|
87
|
+
P("rsa", r"\.initialize\(\s*(?P<p>(?:512|768|1024|2048|3072|4096|8192))\s*[,)]", "java", "keygen", "medium"),
|
|
88
|
+
P("rsa-sig", r"Signature\.getInstance\(\s*\"(?P<p>(?:SHA|MD)\d*)with(?:RSA|RSA/PSS)\"", "java", "sign"),
|
|
89
|
+
P("rsa-sig", r"Signature\.getInstance\(\s*\"RSASSA-PSS\"", "java", "sign"),
|
|
90
|
+
P("ecdsa", r"Signature\.getInstance\(\s*\"(?P<p>SHA\d*)withECDSA\"", "java", "sign"),
|
|
91
|
+
P("dsa", r"Signature\.getInstance\(\s*\"SHA\d*withDSA\"", "java", "sign"),
|
|
92
|
+
P("ed25519", r"Signature\.getInstance\(\s*\"Ed25519\"", "java", "sign"),
|
|
93
|
+
P("rsa", r"Cipher\.getInstance\(\s*\"RSA", "java", "encrypt"),
|
|
94
|
+
P("3des", r"Cipher\.getInstance\(\s*\"(?:DESede|TripleDES)", "java", "encrypt"),
|
|
95
|
+
P("des", r"Cipher\.getInstance\(\s*\"DES[/\"]", "java", "encrypt"),
|
|
96
|
+
P("rc4", r"Cipher\.getInstance\(\s*\"(?:RC4|ARCFOUR)", "java", "encrypt"),
|
|
97
|
+
P("ecb", r"Cipher\.getInstance\(\s*\"AES/ECB|Cipher\.getInstance\(\s*\"AES\"\s*\)", "java", "encrypt"),
|
|
98
|
+
P("ecdh", r"KeyAgreement\.getInstance\(\s*\"ECDH\"", "java", "keyderive"),
|
|
99
|
+
P("dh", r"KeyAgreement\.getInstance\(\s*\"(?:DH|DiffieHellman)\"", "java", "keyderive"),
|
|
100
|
+
P("x25519", r"KeyAgreement\.getInstance\(\s*\"X25519\"", "java", "keyderive"),
|
|
101
|
+
P("md5", r"MessageDigest\.getInstance\(\s*\"MD5\"", "java", "digest"),
|
|
102
|
+
P("sha1", r"MessageDigest\.getInstance\(\s*\"SHA-?1\"", "java", "digest"),
|
|
103
|
+
P("ec", r"ECGenParameterSpec\(\s*\"(?P<p>[\w-]+)\"", "java"),
|
|
104
|
+
|
|
105
|
+
# ---------------- Go ----------------------------------------------
|
|
106
|
+
P("rsa", r"\brsa\.GenerateKey\([^,]+,\s*(?P<p>\d+)\)", "go", "keygen"),
|
|
107
|
+
P("rsa", r"\brsa\.(?:GenerateKey|EncryptOAEP|EncryptPKCS1v15|DecryptOAEP)\(", "go", "encrypt"),
|
|
108
|
+
P("rsa-sig", r"\brsa\.(?:SignPKCS1v15|SignPSS|VerifyPKCS1v15|VerifyPSS)\(", "go", "sign"),
|
|
109
|
+
P("ecdsa", r"\becdsa\.(?:GenerateKey|Sign|SignASN1|Verify|VerifyASN1)\(", "go", "sign"),
|
|
110
|
+
P("ec", r"\belliptic\.(?P<p>P\d{3})\(\)", "go"),
|
|
111
|
+
P("ecdh", r"\becdh\.(?P<p>P\d{3})\(\)", "go", "keyderive"),
|
|
112
|
+
P("x25519", r"\becdh\.X25519\(\)|curve25519\.X25519\(", "go", "keyderive"),
|
|
113
|
+
P("ed25519", r"\bed25519\.(?:GenerateKey|Sign|Verify|NewKeyFromSeed)\(", "go", "sign"),
|
|
114
|
+
P("dsa", r"\"crypto/dsa\"", "go"),
|
|
115
|
+
P("md5", r"\bmd5\.(?:New|Sum)\(", "go", "digest"),
|
|
116
|
+
P("sha1", r"\bsha1\.(?:New|Sum)\(", "go", "digest"),
|
|
117
|
+
P("3des", r"\bdes\.NewTripleDESCipher\(", "go", "encrypt"),
|
|
118
|
+
P("des", r"\bdes\.NewCipher\(", "go", "encrypt"),
|
|
119
|
+
P("rc4", r"\brc4\.NewCipher\(", "go", "encrypt"),
|
|
120
|
+
P("ml-kem", r"\bmlkem\.(?:GenerateKey|NewEncapsulationKey|NewDecapsulationKey)(?P<p>768|1024)\(", "go", "keygen"),
|
|
121
|
+
P("hybrid-kem", r"\btls\.X25519MLKEM768\b", "go", "keyderive"),
|
|
122
|
+
P("x25519", r"\btls\.X25519\b", "go", "keyderive", "medium"),
|
|
123
|
+
P("ec", r"\btls\.CurveP(?P<p>256|384|521)\b", "go", "keyderive", "medium"),
|
|
124
|
+
|
|
125
|
+
# ---------------- JavaScript / TypeScript (Node, WebCrypto, libs) --
|
|
126
|
+
P("rsa", r"generateKeyPair(?:Sync)?\(\s*" + Q + r"rsa(?:-pss)?" + Q + r"(?:[^)]*?modulusLength\s*:\s*(?P<p>\d+))?", "js", "keygen"),
|
|
127
|
+
P("ec", r"generateKeyPair(?:Sync)?\(\s*" + Q + r"ec" + Q + r"(?:[^)]*?namedCurve\s*:\s*" + Q + r"(?P<p>[\w-]+))?", "js", "keygen"),
|
|
128
|
+
P("ed25519", r"generateKeyPair(?:Sync)?\(\s*" + Q + r"ed25519" + Q, "js", "keygen"),
|
|
129
|
+
P("x25519", r"generateKeyPair(?:Sync)?\(\s*" + Q + r"x25519" + Q, "js", "keygen"),
|
|
130
|
+
P("dsa", r"generateKeyPair(?:Sync)?\(\s*" + Q + r"dsa" + Q, "js", "keygen"),
|
|
131
|
+
P("dh", r"\bcreateDiffieHellman(?:Group)?\(", "js", "keyderive"),
|
|
132
|
+
P("ecdh", r"\bcreateECDH\(\s*" + Q + r"(?P<p>[\w-]+)", "js", "keyderive"),
|
|
133
|
+
P("rsa", r"\bpublicEncrypt\(|\bprivateDecrypt\(", "js", "encrypt", "medium"),
|
|
134
|
+
P("rsa", r"name\s*:\s*" + Q + r"RSA-OAEP" + Q + r"(?:[^}]*?modulusLength\s*:\s*(?P<p>\d+))?", "js", "encrypt"),
|
|
135
|
+
P("rsa-sig", r"name\s*:\s*" + Q + r"(?:RSASSA-PKCS1-v1_5|RSA-PSS)" + Q, "js", "sign"),
|
|
136
|
+
P("ecdsa", r"name\s*:\s*" + Q + r"ECDSA" + Q, "js", "sign"),
|
|
137
|
+
P("ecdh", r"name\s*:\s*" + Q + r"ECDH" + Q, "js", "keyderive"),
|
|
138
|
+
P("rsa", r"\bforge\.pki\.rsa\.|\bnew\s+NodeRSA\(", "js", "keygen"),
|
|
139
|
+
P("md5", r"createHash\(\s*" + Q + r"md5" + Q, "js", "digest"),
|
|
140
|
+
P("sha1", r"createHash\(\s*" + Q + r"sha1" + Q, "js", "digest"),
|
|
141
|
+
P("3des", r"createCipheriv\(\s*" + Q + r"des-ede3", "js", "encrypt"),
|
|
142
|
+
P("des", r"createCipheriv\(\s*" + Q + r"des-(?:cbc|ecb)" + Q, "js", "encrypt"),
|
|
143
|
+
P("rc4", r"createCipheriv\(\s*" + Q + r"rc4", "js", "encrypt"),
|
|
144
|
+
P("ecb", r"createCipheriv\(\s*" + Q + r"aes-\d+-ecb", "js", "encrypt"),
|
|
145
|
+
|
|
146
|
+
# ---------------- C / C++ (OpenSSL, libsodium) ---------------------
|
|
147
|
+
P("rsa", r"\bRSA_generate_key(?:_ex)?\s*\(\s*[^,]+,\s*(?P<p>\d+)", "c", "keygen"),
|
|
148
|
+
P("rsa", r"\bRSA_generate_key(?:_ex)?\s*\(|\bEVP_PKEY_RSA\b|\bRSA_public_encrypt\s*\(", "c", "keygen"),
|
|
149
|
+
P("rsa", r"\bEVP_RSA_gen\s*\(\s*(?P<p>\d+)", "c", "keygen"),
|
|
150
|
+
P("rsa-sig", r"\bRSA_sign\s*\(", "c", "sign"),
|
|
151
|
+
P("ec", r"\bEC_KEY_new_by_curve_name\s*\(\s*(?P<p>NID_\w+)|\bEVP_PKEY_EC\b", "c", "keygen"),
|
|
152
|
+
P("ecdsa", r"\bECDSA_(?:do_)?sign\s*\(", "c", "sign"),
|
|
153
|
+
P("ecdh", r"\bECDH_compute_key\s*\(", "c", "keyderive"),
|
|
154
|
+
P("ed25519", r"\bEVP_PKEY_ED25519\b|\bcrypto_sign_(?:ed25519_)?keypair\s*\(", "c", "sign"),
|
|
155
|
+
P("x25519", r"\bEVP_PKEY_X25519\b|\bcrypto_(?:box|kx)_keypair\s*\(|\bcrypto_scalarmult\s*\(", "c", "keyderive"),
|
|
156
|
+
P("dh", r"\bDH_new\s*\(|\bDH_generate_parameters(?:_ex)?\s*\(|\bEVP_PKEY_DH\b", "c", "keyderive"),
|
|
157
|
+
P("dsa", r"\bDSA_new\s*\(|\bEVP_PKEY_DSA\b", "c", "sign"),
|
|
158
|
+
P("md5", r"\bEVP_md5\s*\(|\bMD5_Init\s*\(|\bMD5\s*\(", "c", "digest"),
|
|
159
|
+
P("sha1", r"\bEVP_sha1\s*\(|\bSHA1_Init\s*\(|\bSHA1\s*\(", "c", "digest"),
|
|
160
|
+
P("3des", r"\bEVP_des_ede3\w*\s*\(", "c", "encrypt"),
|
|
161
|
+
P("des", r"\bEVP_des_(?:cbc|ecb|cfb|ofb)\s*\(|\bDES_set_key\w*\s*\(", "c", "encrypt"),
|
|
162
|
+
P("rc4", r"\bEVP_rc4\s*\(|\bRC4_set_key\s*\(", "c", "encrypt"),
|
|
163
|
+
P("ecb", r"\bEVP_aes_\d+_ecb\s*\(", "c", "encrypt"),
|
|
164
|
+
P("ml-kem", r"\bOQS_KEM_alg_(?:ml_kem|kyber)_?(?P<p>\d+)|\bEVP_PKEY_ML_KEM|\"ML-KEM-(?P<p2>\d+)\"", "c", "keygen"),
|
|
165
|
+
P("ml-dsa", r"\bOQS_SIG_alg_(?:ml_dsa|dilithium)_?(?P<p>\d+)|\"ML-DSA-\d+\"", "c", "sign"),
|
|
166
|
+
|
|
167
|
+
# ---------------- C# / .NET ---------------------------------------
|
|
168
|
+
P("rsa", r"\bRSA\.Create\(\s*(?P<p>\d+)?|\bnew\s+RSACryptoServiceProvider\(\s*(?P<p2>\d+)?", "cs", "keygen"),
|
|
169
|
+
P("ecdsa", r"\bECDsa\.Create\(|\bECDsaCng\b", "cs", "sign"),
|
|
170
|
+
P("ecdh", r"\bECDiffieHellman\.Create\(", "cs", "keyderive"),
|
|
171
|
+
P("dsa", r"\bDSA\.Create\(|\bDSACryptoServiceProvider\b", "cs", "sign"),
|
|
172
|
+
P("md5", r"\bMD5\.(?:Create|HashData)\(|\bMD5CryptoServiceProvider\b", "cs", "digest"),
|
|
173
|
+
P("sha1", r"\bSHA1\.(?:Create|HashData)\(|\bSHA1Managed\b", "cs", "digest"),
|
|
174
|
+
P("3des", r"\bTripleDES\.Create\(", "cs", "encrypt"),
|
|
175
|
+
P("des", r"\bDES\.Create\(", "cs", "encrypt"),
|
|
176
|
+
P("ecb", r"CipherMode\.ECB", "cs", "encrypt"),
|
|
177
|
+
|
|
178
|
+
# ---------------- Ruby / PHP / Rust / Swift -----------------------
|
|
179
|
+
P("rsa", r"OpenSSL::PKey::RSA\.(?:new|generate)\(\s*(?P<p>\d+)?", "rb", "keygen"),
|
|
180
|
+
P("ec", r"OpenSSL::PKey::EC\.generate\(\s*" + Q + r"(?P<p>[\w-]+)", "rb", "keygen"),
|
|
181
|
+
P("md5", r"Digest::MD5|OpenSSL::Digest::MD5", "rb", "digest"),
|
|
182
|
+
P("sha1", r"Digest::SHA1|OpenSSL::Digest::SHA1", "rb", "digest"),
|
|
183
|
+
P("rsa", r"\bopenssl_pkey_new\(|OPENSSL_KEYTYPE_RSA", "php", "keygen"),
|
|
184
|
+
P("ec", r"OPENSSL_KEYTYPE_EC", "php", "keygen"),
|
|
185
|
+
P("md5", r"\bmd5\(", "php", "digest", "medium"),
|
|
186
|
+
P("sha1", r"\bsha1\(", "php", "digest", "medium"),
|
|
187
|
+
P("rsa", r"\bRsaPrivateKey::new\(\s*&mut\s+\w+,\s*(?P<p>\d+)|\bRsaPrivateKey::new\(", "rs", "keygen"),
|
|
188
|
+
P("ecdsa", r"\bp256::ecdsa::|\bp384::ecdsa::|\bk256::ecdsa::", "rs", "sign"),
|
|
189
|
+
P("ed25519", r"\bed25519_dalek::", "rs", "sign"),
|
|
190
|
+
P("x25519", r"\bx25519_dalek::", "rs", "keyderive"),
|
|
191
|
+
P("ml-kem", r"\bml_kem::|\bpqcrypto_kyber::", "rs", "keygen"),
|
|
192
|
+
P("ml-dsa", r"\bml_dsa::|\bpqcrypto_dilithium::", "rs", "sign"),
|
|
193
|
+
P("ecdsa", r"\bP256\.Signing\.|\bP384\.Signing\.", "swift", "sign"),
|
|
194
|
+
P("ed25519", r"\bCurve25519\.Signing\.", "swift", "sign"),
|
|
195
|
+
P("x25519", r"\bCurve25519\.KeyAgreement\.", "swift", "keyderive"),
|
|
196
|
+
P("md5", r"\bInsecure\.MD5\b", "swift", "digest"),
|
|
197
|
+
P("sha1", r"\bInsecure\.SHA1\b", "swift", "digest"),
|
|
198
|
+
|
|
199
|
+
# ---------------- JWT algorithm names (any code or config) --------
|
|
200
|
+
P("rsa-sig", r"(?<![\w-])" + Q + r"(?P<p>RS(?:256|384|512))" + Q, "code config", "sign", "medium"),
|
|
201
|
+
P("rsa-sig", r"(?<![\w-])" + Q + r"(?P<p>PS(?:256|384|512))" + Q, "code config", "sign", "medium"),
|
|
202
|
+
P("ecdsa", r"(?<![\w-])" + Q + r"(?P<p>ES(?:256K?|384|512))" + Q, "code config", "sign", "medium"),
|
|
203
|
+
|
|
204
|
+
# ---------------- Post-quantum names anywhere ---------------------
|
|
205
|
+
P("ml-kem", r"\bML[-_]?KEM[-_]?(?P<p>512|768|1024)\b|\bKyber[-_]?(?P<p2>512|768|1024)\b", "any", "keygen", "medium", flags=I),
|
|
206
|
+
P("ml-dsa", r"\bML[-_]?DSA[-_]?(?P<p>44|65|87)\b|\bDilithium[-_]?(?P<p2>2|3|5)\b", "any", "sign", "medium", flags=I),
|
|
207
|
+
P("slh-dsa", r"\bSLH[-_]?DSA\b|\bSPHINCS\+?", "any", "sign", "medium", flags=I),
|
|
208
|
+
P("hybrid-kem", r"\bX25519MLKEM768\b|\bX25519Kyber768\b", "any", "keyderive", "high", flags=I),
|
|
209
|
+
|
|
210
|
+
# ---------------- Safe crypto (inventoried, not flagged) ----------
|
|
211
|
+
# AES: key size in group p (128/192/256) maps to aes-128/192/256; mode in group m.
|
|
212
|
+
P("aes", r"\balgorithms\.AES(?:256|128)?\(|\bAES\.new\([^)]*?MODE_(?P<m>[A-Z]+)|\bAES(?P<m2>GCM|CCM|OCB3|SIV)\(", "py", "encrypt"),
|
|
213
|
+
P("aes", r"Cipher\.getInstance\(\s*\"AES(?:_(?P<p>128|192|256))?/(?P<m>[A-Z]+)", "java", "encrypt"),
|
|
214
|
+
P("aes", r"KeyGenerator\.getInstance\(\s*\"AES\"|SecretKeySpec\([^)]*\"AES\"", "java", "keygen"),
|
|
215
|
+
P("aes", r"\baes\.NewCipher\(", "go", "encrypt"),
|
|
216
|
+
P("aes", r"createCipheriv\(\s*" + Q + r"aes-(?P<p>128|192|256)-(?P<m>[a-z]+)", "js", "encrypt", flags=I),
|
|
217
|
+
P("aes", r"name\s*:\s*" + Q + r"AES-(?P<m>GCM|CBC|CTR|KW)" + Q + r"(?:[^}]*?length\s*:\s*(?P<p>128|192|256))?", "js", "encrypt"),
|
|
218
|
+
P("aes", r"\bEVP_aes_(?P<p>128|192|256)_(?P<m>gcm|cbc|ctr|ccm|ocb|xts|cfb\d*|ofb|wrap)\b", "c", "encrypt"),
|
|
219
|
+
P("aes", r"\bAes(?:Gcm|Ccm)?\.Create\(|\bnew\s+Aes(?P<m>Gcm|Ccm)\(", "cs", "encrypt"),
|
|
220
|
+
P("aes", r"\baes_gcm::|\baes::Aes(?P<p>128|192|256)\b", "rs", "encrypt"),
|
|
221
|
+
P("aes", r"\bAES\.(?P<m>GCM)\.", "swift", "encrypt"),
|
|
222
|
+
P("aes", r"OpenSSL::Cipher\.new\(\s*" + Q + r"aes-(?P<p>128|192|256)-(?P<m>[a-z]+)", "rb", "encrypt", flags=I),
|
|
223
|
+
P("aes", r"openssl_encrypt\([^)]*" + Q + r"aes-(?P<p>128|192|256)-(?P<m>[a-z]+)", "php", "encrypt", flags=I),
|
|
224
|
+
P("aes", r"\bTLS_AES_(?P<p>128|256)_GCM_SHA\d+\b|\b(?:ECDHE-\w+-)?AES(?P<p2>128|256)-GCM-SHA\d+\b", "config code", "encrypt", "medium"),
|
|
225
|
+
P("chacha20", r"\bChaCha20Poly1305\b|\bChaCha20\.new\(|\bchacha20poly1305\.New(?:X)?\(|" + Q + r"chacha20-poly1305" + Q + r"|"
|
|
226
|
+
r"\bEVP_chacha20_poly1305\b|\bcrypto_aead_(?:x)?chacha20poly1305|\bChaChaPoly\b|\bTLS_CHACHA20_POLY1305_SHA256\b",
|
|
227
|
+
"any", "encrypt"),
|
|
228
|
+
P("sha256", r"\bhashlib\.sha256\(|\bhashes\.SHA256\b|\bSHA256\.new\(|hashlib\.new\(\s*" + Q + r"sha256", "py", "digest"),
|
|
229
|
+
P("sha384", r"\bhashlib\.sha384\(|\bhashes\.SHA384\b|\bSHA384\.new\(", "py", "digest"),
|
|
230
|
+
P("sha512", r"\bhashlib\.sha512\(|\bhashes\.SHA512\b|\bSHA512\.new\(", "py", "digest"),
|
|
231
|
+
P("sha3", r"\bhashlib\.sha3_(?P<p>224|256|384|512)\(|\bhashes\.SHA3_(?P<p2>224|256|384|512)\b", "py", "digest"),
|
|
232
|
+
P("blake2", r"\bhashlib\.blake2[bs]\(|\bhashes\.BLAKE2[bs]\(", "py", "digest"),
|
|
233
|
+
P("sha256", r"^\s*from\s+hashlib\s+import\s+[^\n]*\bsha256\b", "py", "digest", "medium", flags=re.MULTILINE),
|
|
234
|
+
P("sha512", r"^\s*from\s+hashlib\s+import\s+[^\n]*\bsha512\b", "py", "digest", "medium", flags=re.MULTILINE),
|
|
235
|
+
P("hmac", r"^\s*(?:from\s+hmac\s+import|import\s+hmac\b)", "py", "tag", "medium", flags=re.MULTILINE),
|
|
236
|
+
P("sha256", r"MessageDigest\.getInstance\(\s*\"SHA-?256\"", "java", "digest"),
|
|
237
|
+
P("sha384", r"MessageDigest\.getInstance\(\s*\"SHA-?384\"", "java", "digest"),
|
|
238
|
+
P("sha512", r"MessageDigest\.getInstance\(\s*\"SHA-?512\"", "java", "digest"),
|
|
239
|
+
P("sha3", r"MessageDigest\.getInstance\(\s*\"SHA3-(?P<p>224|256|384|512)\"", "java", "digest"),
|
|
240
|
+
P("sha256", r"\bsha256\.(?:New|Sum256)\(", "go", "digest"),
|
|
241
|
+
P("sha384", r"\bsha512\.(?:New384|Sum384)\(", "go", "digest"),
|
|
242
|
+
P("sha512", r"\bsha512\.(?:New|Sum512)\(", "go", "digest"),
|
|
243
|
+
P("sha3", r"\bsha3\.(?:New|Sum)(?P<p>224|256|384|512)\(", "go", "digest"),
|
|
244
|
+
P("sha256", r"createHash\(\s*" + Q + r"sha256" + Q + r"|digest\(\s*" + Q + r"SHA-256" + Q, "js", "digest"),
|
|
245
|
+
P("sha384", r"createHash\(\s*" + Q + r"sha384" + Q + r"|digest\(\s*" + Q + r"SHA-384" + Q, "js", "digest"),
|
|
246
|
+
P("sha512", r"createHash\(\s*" + Q + r"sha512" + Q + r"|digest\(\s*" + Q + r"SHA-512" + Q, "js", "digest"),
|
|
247
|
+
P("sha3", r"createHash\(\s*" + Q + r"sha3-(?P<p>224|256|384|512)" + Q, "js", "digest"),
|
|
248
|
+
P("sha256", r"\bEVP_sha256\s*\(|\bSHA256(?:_Init)?\s*\(", "c", "digest"),
|
|
249
|
+
P("sha384", r"\bEVP_sha384\s*\(|\bSHA384(?:_Init)?\s*\(", "c", "digest"),
|
|
250
|
+
P("sha512", r"\bEVP_sha512\s*\(|\bSHA512(?:_Init)?\s*\(", "c", "digest"),
|
|
251
|
+
P("sha3", r"\bEVP_sha3_(?P<p>224|256|384|512)\s*\(", "c", "digest"),
|
|
252
|
+
P("blake2", r"\bcrypto_generichash\w*\s*\(|\bEVP_blake2[bs]\d*\s*\(", "c", "digest"),
|
|
253
|
+
P("sha256", r"\bSHA256\.(?:Create|HashData)\(", "cs", "digest"),
|
|
254
|
+
P("sha384", r"\bSHA384\.(?:Create|HashData)\(", "cs", "digest"),
|
|
255
|
+
P("sha512", r"\bSHA512\.(?:Create|HashData)\(", "cs", "digest"),
|
|
256
|
+
P("sha256", r"\bsha2::Sha256\b|\bSHA256\.hash\(|Digest::SHA256|OpenSSL::Digest::SHA256", "rs swift rb", "digest"),
|
|
257
|
+
P("sha512", r"\bsha2::Sha512\b|\bSHA512\.hash\(|Digest::SHA512", "rs swift rb", "digest"),
|
|
258
|
+
P("sha256", r"\bhash(?:_hmac)?\(\s*" + Q + r"sha256" + Q, "php", "digest"),
|
|
259
|
+
P("hmac", r"\bhmac\.(?:new|HMAC|digest)\(|\bHMAC\.new\(|\bhashes\.HMAC\b|\bhmac\.HMAC\(", "py", "tag"),
|
|
260
|
+
P("hmac", r"Mac\.getInstance\(\s*\"Hmac(?P<p>SHA\d+|SHA3-\d+)\"", "java", "tag"),
|
|
261
|
+
P("hmac", r"\bhmac\.New\(", "go", "tag"),
|
|
262
|
+
P("hmac", r"\bcreateHmac\(|name\s*:\s*" + Q + r"HMAC" + Q, "js", "tag"),
|
|
263
|
+
P("hmac", r"\bHMAC(?:_Init_ex)?\s*\(|\bEVP_MAC_fetch\([^)]*\"HMAC\"", "c", "tag"),
|
|
264
|
+
P("hmac", r"\bHMACSHA(?P<p>256|384|512)\b", "cs", "tag"),
|
|
265
|
+
P("hmac", r"\bhmac::Hmac\b|\bHMAC<|OpenSSL::HMAC|\bhash_hmac\(", "rs swift rb php", "tag"),
|
|
266
|
+
P("pbkdf2", r"\bPBKDF2HMAC\(|\bpbkdf2_hmac\(|\bPBKDF2\(|\bpbkdf2(?:Sync)?\(|\bpbkdf2\.Key\(|PBKDF2WithHmac\w+|"
|
|
267
|
+
r"\bPKCS5_PBKDF2_HMAC\w*\s*\(|\bRfc2898DeriveBytes\b|\bpbkdf2::|name\s*:\s*" + Q + r"PBKDF2" + Q, "code", "keyderive"),
|
|
268
|
+
P("hkdf", r"\bHKDF(?:Expand)?\(|\bhkdf(?:Sync)?\(|\bhkdf\.(?:New|Extract|Expand|Key)\(|\bEVP_PKEY_HKDF\b|\bHKDF\.|"
|
|
269
|
+
r"\bhkdf::Hkdf\b|\bHKDF<|name\s*:\s*" + Q + r"HKDF" + Q, "code", "keyderive"),
|
|
270
|
+
P("scrypt", r"\bScrypt\(|\bhashlib\.scrypt\(|\bscrypt(?:Sync)?\(|\bscrypt\.Key\(|\bEVP_PBE_scrypt\s*\(", "code", "keyderive"),
|
|
271
|
+
P("argon2", r"\bargon2\.(?:IDKey|Key)\(|\bArgon2(?:id)?\b|\bargon2::|\bcrypto_pwhash(?:_str)?\s*\(|PASSWORD_ARGON2", "code", "keyderive"),
|
|
272
|
+
P("bcrypt", r"\bbcrypt\.(?:hashpw|gensalt|hash|hashSync|GenerateFromPassword)\(|\bBCrypt\.\w+\(|\bpassword_hash\(", "code", "keyderive"),
|
|
273
|
+
P("csprng", r"\bsecrets\.(?:token_\w+|randbelow|choice)\(|\bos\.urandom\(|\bSystemRandom\(|\bget_random_bytes\(", "py", "generate"),
|
|
274
|
+
P("csprng", r"\bnew\s+SecureRandom\(|\bSecureRandom\.getInstance\w*\(", "java", "generate"),
|
|
275
|
+
P("csprng", r"\"crypto/rand\"", "go", "generate"),
|
|
276
|
+
P("csprng", r"\brandomBytes\(|\bgetRandomValues\(|\brandomUUID\(", "js", "generate"),
|
|
277
|
+
P("csprng", r"\bRAND_(?:priv_)?bytes\s*\(|\brandombytes_buf\s*\(|\bgetrandom\s*\(", "c", "generate"),
|
|
278
|
+
P("csprng", r"\bRandomNumberGenerator\.(?:Create|GetBytes|Fill|GetInt32)\(", "cs", "generate"),
|
|
279
|
+
P("csprng", r"\bOsRng\b|\bSecRandomCopyBytes\(|\bSecureRandom\.\w+|\brandom_bytes\(", "rs swift rb php", "generate"),
|
|
280
|
+
|
|
281
|
+
# ---------------- TLS / SSH config --------------------------------
|
|
282
|
+
P("tls1.0", r"(?:ssl_protocols|SSLProtocol|protocols?|min_?version|MinVersion)\W[^\n]*\bTLSv?1(?:\.0)?\b(?![.\d])", "config c go", None, "medium", flags=I),
|
|
283
|
+
P("tls1.0", r"\btls\.VersionTLS10\b|\bTLSv1_method\s*\(|\bSSLProtocols\.Tls\b(?!\d)", "code", None, "high"),
|
|
284
|
+
P("tls1.1", r"(?:ssl_protocols|SSLProtocol|protocols?|min_?version|MinVersion)\W[^\n]*\bTLSv?1\.1\b", "config c go", None, "medium", flags=I),
|
|
285
|
+
P("tls1.1", r"\btls\.VersionTLS11\b|\bTLSv1_1_method\s*\(|\bSSLProtocols\.Tls11\b", "code", None, "high"),
|
|
286
|
+
P("sslv3", r"\bSSLv3\b|\bSSLv3_method\s*\(", "any", None, "medium"),
|
|
287
|
+
P("rsa", r"\b(?:ECDHE|DHE)?-?RSA-AES\d+-(?:GCM-)?SHA\d*\b|\bTLS_RSA_WITH_\w+", "config code", "keyderive", "medium"),
|
|
288
|
+
P("ecdh", r"\bECDHE-(?:RSA|ECDSA)-\w+|\bTLS_ECDHE_\w+", "config code", "keyderive", "medium"),
|
|
289
|
+
P("rc4", r"\b(?:TLS_\w*_RC4_\w+|RC4-(?:SHA|MD5))\b", "config code", "encrypt", "medium"),
|
|
290
|
+
P("3des", r"\b(?:TLS_\w*_3DES_\w+|DES-CBC3-SHA)\b", "config code", "encrypt", "medium"),
|
|
291
|
+
]
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def scan_text(rel_path: str, text: str, ext: str) -> list[Finding]:
|
|
295
|
+
"""Run every pattern that applies to this file type over its text."""
|
|
296
|
+
out: list[Finding] = []
|
|
297
|
+
seen: set[tuple[str, int]] = set() # (algorithm, line): one finding per line per algorithm
|
|
298
|
+
line_starts = None
|
|
299
|
+
for pat in PATTERNS:
|
|
300
|
+
if ext not in pat.langs:
|
|
301
|
+
continue
|
|
302
|
+
for m in pat.regex.finditer(text):
|
|
303
|
+
if line_starts is None:
|
|
304
|
+
line_starts = [0] + [i + 1 for i, c in enumerate(text) if c == "\n"]
|
|
305
|
+
line = _line_of(line_starts, m.start())
|
|
306
|
+
gd = m.groupdict()
|
|
307
|
+
params = gd.get("p") or gd.get("p2") or pat.params
|
|
308
|
+
mode = gd.get("m") or gd.get("m2")
|
|
309
|
+
alg = pat.algorithm
|
|
310
|
+
if alg == "aes" and params in ("128", "192", "256"):
|
|
311
|
+
alg, params = f"aes-{params}", None
|
|
312
|
+
key = (alg, line)
|
|
313
|
+
if key in seen:
|
|
314
|
+
# keep the richer version (with params) if a later pattern found one
|
|
315
|
+
if params:
|
|
316
|
+
for f in out:
|
|
317
|
+
if (f.algorithm, f.line) == key and not f.params:
|
|
318
|
+
f.params = params
|
|
319
|
+
continue
|
|
320
|
+
seen.add(key)
|
|
321
|
+
snippet = text[line_starts[line - 1]:].split("\n", 1)[0].strip()[:200]
|
|
322
|
+
out.append(Finding(
|
|
323
|
+
algorithm=alg, file=rel_path, line=line, snippet=snippet,
|
|
324
|
+
detector="source", confidence=pat.confidence, params=_norm_params(alg, params),
|
|
325
|
+
function=pat.function, extra={"mode": mode.lower()} if mode else {},
|
|
326
|
+
))
|
|
327
|
+
return out
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
def _line_of(starts: list[int], pos: int) -> int:
|
|
331
|
+
lo, hi = 0, len(starts) - 1
|
|
332
|
+
while lo < hi:
|
|
333
|
+
mid = (lo + hi + 1) // 2
|
|
334
|
+
if starts[mid] <= pos:
|
|
335
|
+
lo = mid
|
|
336
|
+
else:
|
|
337
|
+
hi = mid - 1
|
|
338
|
+
return lo + 1
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
_CURVE_NAMES = {
|
|
342
|
+
"secp256r1": "P-256", "prime256v1": "P-256", "p-256": "P-256", "p256": "P-256", "nid_x9_62_prime256v1": "P-256",
|
|
343
|
+
"secp384r1": "P-384", "p-384": "P-384", "p384": "P-384", "nid_secp384r1": "P-384",
|
|
344
|
+
"secp521r1": "P-521", "p-521": "P-521", "p521": "P-521", "nid_secp521r1": "P-521",
|
|
345
|
+
"secp256k1": "secp256k1", "nid_secp256k1": "secp256k1",
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
def _norm_params(alg: str, p: str | None) -> str | None:
|
|
350
|
+
if not p:
|
|
351
|
+
return None
|
|
352
|
+
if alg in ("ec", "ecdh", "ecdsa"):
|
|
353
|
+
return _CURVE_NAMES.get(p.lower(), p)
|
|
354
|
+
return p
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
def applies_to(path: Path) -> bool:
|
|
358
|
+
return path.suffix.lower() in ALL
|
cbomly/findings.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""The shared data model: one Finding per place crypto was seen."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import asdict, dataclass, field
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass
|
|
9
|
+
class Finding:
|
|
10
|
+
algorithm: str # id from algorithms.CATALOG
|
|
11
|
+
file: str # path relative to the scan root
|
|
12
|
+
line: int | None = None
|
|
13
|
+
snippet: str = ""
|
|
14
|
+
detector: str = "source" # source | key-file | certificate | dependency | cdxgen
|
|
15
|
+
confidence: str = "medium" # high | medium | low
|
|
16
|
+
params: str | None = None # e.g. "2048", "P-256", "SHA-1"
|
|
17
|
+
function: str | None = None # CycloneDX cryptoFunctions value: keygen, sign, encrypt...
|
|
18
|
+
material: str | None = None # for keys/certs: private-key | public-key | certificate
|
|
19
|
+
extra: dict = field(default_factory=dict)
|
|
20
|
+
|
|
21
|
+
@property
|
|
22
|
+
def key_bits(self) -> int | None:
|
|
23
|
+
if self.params and self.params.isdigit():
|
|
24
|
+
return int(self.params)
|
|
25
|
+
return None
|
|
26
|
+
|
|
27
|
+
def to_dict(self) -> dict:
|
|
28
|
+
d = asdict(self)
|
|
29
|
+
return {k: v for k, v in d.items() if v not in (None, "", {})}
|
cbomly/inventory.py
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"""The crypto inventory: algorithms, certificates, keys and protocols.
|
|
2
|
+
|
|
3
|
+
Findings say "this was seen at file:line". The inventory groups them into
|
|
4
|
+
the assets a CBOM lists, each with one status a buyer can read:
|
|
5
|
+
|
|
6
|
+
broken unsafe today (MD5, SHA-1 signatures, DES, RC4, TLS 1.0)
|
|
7
|
+
deprecated being phased out (Triple DES, DSA)
|
|
8
|
+
quantum-vulnerable safe today, broken by a future quantum computer
|
|
9
|
+
weakened weakened by quantum attacks but usable (AES-128)
|
|
10
|
+
safe fine today and against quantum attacks
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
from collections import OrderedDict
|
|
16
|
+
from datetime import UTC, datetime
|
|
17
|
+
|
|
18
|
+
from . import algorithms
|
|
19
|
+
from .cbom_names import display_name
|
|
20
|
+
from .findings import Finding
|
|
21
|
+
|
|
22
|
+
STATUS_ORDER = ["broken", "deprecated", "quantum-vulnerable", "weakened", "safe"]
|
|
23
|
+
STATUS_LABEL = {
|
|
24
|
+
"broken": "Broken",
|
|
25
|
+
"deprecated": "Deprecated",
|
|
26
|
+
"quantum-vulnerable": "Quantum-vulnerable",
|
|
27
|
+
"weakened": "Weakened by quantum",
|
|
28
|
+
"safe": "Safe",
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def status_of(alg_id: str, key_bits: int | None = None) -> str:
|
|
33
|
+
a = algorithms.get(alg_id)
|
|
34
|
+
if a.classical == "broken":
|
|
35
|
+
return "broken"
|
|
36
|
+
if alg_id in ("rsa", "rsa-sig", "dh") and key_bits is not None and key_bits < 2048:
|
|
37
|
+
return "broken"
|
|
38
|
+
if a.classical == "deprecated":
|
|
39
|
+
return "deprecated"
|
|
40
|
+
if a.quantum == "vulnerable":
|
|
41
|
+
return "quantum-vulnerable"
|
|
42
|
+
if a.quantum == "reduced":
|
|
43
|
+
return "weakened"
|
|
44
|
+
return "safe"
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def worst(statuses) -> str:
|
|
48
|
+
s = [x for x in statuses if x]
|
|
49
|
+
return min(s, key=STATUS_ORDER.index) if s else "safe"
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _expired(not_after: str | None, now: datetime) -> bool | None:
|
|
53
|
+
if not not_after:
|
|
54
|
+
return None
|
|
55
|
+
return datetime.fromisoformat(not_after) < now
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def build(findings: list[Finding], now: datetime | None = None) -> dict:
|
|
59
|
+
"""Return {"algorithms": [...], "certificates": [...], "keys": [...], "protocols": [...]}."""
|
|
60
|
+
now = now or datetime.now(UTC)
|
|
61
|
+
algs: OrderedDict[str, dict] = OrderedDict()
|
|
62
|
+
protocols: OrderedDict[str, dict] = OrderedDict()
|
|
63
|
+
certs: OrderedDict[tuple, dict] = OrderedDict()
|
|
64
|
+
keys: list[dict] = []
|
|
65
|
+
|
|
66
|
+
for f in sorted(findings, key=lambda f: (display_name(f), f.file, f.line or 0)):
|
|
67
|
+
a = algorithms.get(f.algorithm)
|
|
68
|
+
name = display_name(f)
|
|
69
|
+
target = protocols if a.asset_type == "protocol" else algs
|
|
70
|
+
entry = target.setdefault(name, {
|
|
71
|
+
"name": name, "algorithm": f.algorithm, "primitive": a.primitive, "params": f.params,
|
|
72
|
+
"status": status_of(f.algorithm, f.key_bits), "replacement": a.replacement,
|
|
73
|
+
"functions": set(), "places": [],
|
|
74
|
+
})
|
|
75
|
+
if f.function:
|
|
76
|
+
entry["functions"].add(f.function)
|
|
77
|
+
entry["places"].append({"file": f.file, "line": f.line, "confidence": f.confidence})
|
|
78
|
+
|
|
79
|
+
for f in findings:
|
|
80
|
+
if f.material in ("private-key", "public-key"):
|
|
81
|
+
keys.append({
|
|
82
|
+
"name": f"{display_name(f)} {f.material.replace('-', ' ')}",
|
|
83
|
+
"type": f.material, "algorithm": display_name(f), "size": f.key_bits,
|
|
84
|
+
"curve": f.params if f.algorithm in ("ec", "ecdsa", "ecdh") else None,
|
|
85
|
+
"status": status_of(f.algorithm, f.key_bits), "file": f.file, "line": f.line,
|
|
86
|
+
"encrypted": "encrypted" in (f.extra.get("note") or ""),
|
|
87
|
+
})
|
|
88
|
+
elif f.material in ("certificate", "certificate-signature"):
|
|
89
|
+
c = certs.setdefault((f.file, f.line), {
|
|
90
|
+
"subject": f.extra.get("subject"), "issuer": f.extra.get("issuer"),
|
|
91
|
+
"not_before": f.extra.get("not_before"), "not_after": f.extra.get("not_after"),
|
|
92
|
+
"expired": _expired(f.extra.get("not_after"), now),
|
|
93
|
+
"public_key": None, "key_size": None, "signature": None, "statuses": [],
|
|
94
|
+
"file": f.file, "line": f.line,
|
|
95
|
+
})
|
|
96
|
+
c["statuses"].append(status_of(f.algorithm, f.key_bits))
|
|
97
|
+
if f.material == "certificate":
|
|
98
|
+
c["public_key"] = display_name(f)
|
|
99
|
+
c["key_size"] = f.key_bits
|
|
100
|
+
elif f.algorithm not in ("sha1", "md5"):
|
|
101
|
+
c["signature"] = display_name(f)
|
|
102
|
+
|
|
103
|
+
cert_list = []
|
|
104
|
+
for c in certs.values():
|
|
105
|
+
c["status"] = worst(c.pop("statuses"))
|
|
106
|
+
c["self_signed"] = bool(c["subject"]) and c["subject"] == c["issuer"]
|
|
107
|
+
cert_list.append(c)
|
|
108
|
+
|
|
109
|
+
def finish(d):
|
|
110
|
+
out = []
|
|
111
|
+
for e in d.values():
|
|
112
|
+
e["functions"] = sorted(e["functions"])
|
|
113
|
+
out.append(e)
|
|
114
|
+
return out
|
|
115
|
+
|
|
116
|
+
return {"algorithms": finish(algs), "certificates": cert_list, "keys": keys, "protocols": finish(protocols)}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def counts(inv: dict) -> dict:
|
|
120
|
+
by_status = {s: 0 for s in STATUS_ORDER}
|
|
121
|
+
for e in inv["algorithms"] + inv["protocols"]:
|
|
122
|
+
by_status[e["status"]] += 1
|
|
123
|
+
return {"algorithms": len(inv["algorithms"]), "certificates": len(inv["certificates"]),
|
|
124
|
+
"keys": len(inv["keys"]), "protocols": len(inv["protocols"]), "by_status": by_status}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
KIND_LABEL = {"kms": "Key management", "hsm": "Hardware security module", "secrets": "Secret store",
|
|
128
|
+
"ca": "Certificate authority", "certificates": "Certificate service", "library": "Crypto library"}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def vendors(inv: dict, libs: list[dict], services: list[dict]) -> list[dict]:
|
|
132
|
+
"""Who supplies the crypto: library makers, certificate issuers and key/HSM services."""
|
|
133
|
+
out: OrderedDict[tuple, dict] = OrderedDict()
|
|
134
|
+
|
|
135
|
+
def add(vendor, what, kind, where):
|
|
136
|
+
e = out.setdefault((vendor, what), {"vendor": vendor, "what": what, "kind": kind, "where": []})
|
|
137
|
+
if where and where not in e["where"]:
|
|
138
|
+
e["where"].append(where)
|
|
139
|
+
|
|
140
|
+
for lib in libs:
|
|
141
|
+
what = f"{lib.get('component') or lib['library']} {lib.get('version') or ''}".strip()
|
|
142
|
+
add(lib.get("vendor") or "Unknown", what, "library", lib.get("purl"))
|
|
143
|
+
for c in inv["certificates"]:
|
|
144
|
+
issuer = c.get("issuer") or "Unknown issuer"
|
|
145
|
+
what = "Self-signed certificate" if c.get("self_signed") else "Certificate issuer"
|
|
146
|
+
add("Self-signed (no CA)" if c.get("self_signed") else issuer, what, "ca",
|
|
147
|
+
f"{c['file']}:{c['line']}" if c.get("line") else c["file"])
|
|
148
|
+
for s in services:
|
|
149
|
+
add(s["vendor"], s["service"], s["kind"], f"{s['file']}:{s['line']}")
|
|
150
|
+
return list(out.values())
|
cbomly/packs/au.toml
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Australia rule pack: ASD Information Security Manual (ISM) post-quantum guidance.
|
|
2
|
+
#
|
|
3
|
+
# REVIEW STATUS: draft (checked 2026-11-29 against ASD's "Planning for post-quantum cryptography",
|
|
4
|
+
# September 2025). The ISM control numbers and approved parameter sets were not re-checked.
|
|
5
|
+
|
|
6
|
+
[pack]
|
|
7
|
+
id = "au"
|
|
8
|
+
name = "Australia: ASD Information Security Manual, post-quantum transition"
|
|
9
|
+
version = "2026.11-draft"
|
|
10
|
+
jurisdiction = "AU"
|
|
11
|
+
extends = ["baseline"]
|
|
12
|
+
review_status = "draft"
|
|
13
|
+
summary = "For vendors selling to Australian government and organisations that follow the ISM."
|
|
14
|
+
|
|
15
|
+
[references.asd-planning-pqc]
|
|
16
|
+
title = "Planning for post-quantum cryptography"
|
|
17
|
+
issuer = "Australian Signals Directorate (ASD), Australian Cyber Security Centre"
|
|
18
|
+
date = "2025-09-22"
|
|
19
|
+
url = "https://www.cyber.gov.au/business-government/secure-design/planning-for-post-quantum-cryptography"
|
|
20
|
+
status = "guidance backed by the ISM. Refined plan by end of 2026; transition started (critical systems first) by end of 2028; transition complete and traditional asymmetric crypto no longer used by end of 2030. Recommends a CBOM for the inventory."
|
|
21
|
+
|
|
22
|
+
[references.asd-ism]
|
|
23
|
+
title = "Information Security Manual (ISM), Guidelines for cryptography"
|
|
24
|
+
issuer = "ASD"
|
|
25
|
+
date = "2025"
|
|
26
|
+
url = "https://www.cyber.gov.au/ism"
|
|
27
|
+
status = "framework for government; ASD-approved algorithms and parameter sets (not re-checked for this pack)"
|
|
28
|
+
|
|
29
|
+
[[rules]]
|
|
30
|
+
id = "AU-PQC-001"
|
|
31
|
+
title = "Traditional asymmetric crypto: stop using it by end of 2030"
|
|
32
|
+
severity = "high"
|
|
33
|
+
match = { quantum = ["vulnerable"] }
|
|
34
|
+
message = "The ISM recommends ceasing use of traditional asymmetric cryptography (RSA, DH, ECDH, ECDSA) by the end of 2030, the earliest national deadline among Five Eyes countries. Critical systems should start moving by the end of 2028."
|
|
35
|
+
action = "Plan to replace each item with an ASD-approved post-quantum algorithm by 2030. ASD does not recommend (but does not prohibit) hybrid schemes, so plan for pure ML-KEM and ML-DSA as the end state."
|
|
36
|
+
references = ["asd-planning-pqc", "asd-ism"]
|
|
37
|
+
due = "End of 2030 (critical systems start by end of 2028)"
|
|
38
|
+
|
|
39
|
+
[[checks]]
|
|
40
|
+
id = "AU-CBOM-001"
|
|
41
|
+
title = "Cryptographic inventory (CBOM) produced"
|
|
42
|
+
severity = "medium"
|
|
43
|
+
type = "crypto-inventory"
|
|
44
|
+
references = ["asd-planning-pqc"]
|
|
45
|
+
message = "ASD names a cryptographic bill of materials (CBOM) as an effective way to inventory cryptographic dependencies, the first step of its plan."
|