Goal
Produce a cryptographic inventory of a codebase:- a findings file with every place your code (and, optionally, your dependencies) uses cryptography
- a CycloneDX 1.7 Cryptography Bill of Materials (CBOM) to share with security, compliance, or customers
- two short reports: the quantum-vulnerable public-key algorithms you will have to migrate, and any broken algorithms you should remove now
When to use it
- You are planning a migration to post-quantum cryptography and need to know where your code uses RSA, elliptic-curve, and Diffie-Hellman algorithms.
- A customer or a framework asks for a cryptographic inventory or a CBOM.
- You want to stop new uses of broken algorithms such as MD5, SHA-1, DES, or RC4.
Prerequisites
- Docker, to run the Crypto Finder image, which includes the scanning engine. To run Crypto Finder without Docker, install the binary and OpenGrep as described in Installation.
SCANOSS_API_KEY, used to download the SCANOSS-maintained detection rulesjq
The script
Save this asci/crypto-inventory.sh and run it from the repository root.
What each step does
- Scan. Crypto Finder detects the languages in the repository, downloads the matching
SCANOSS detection rules (cached for 7 days), and runs them. The script mounts the repository
read-only.
--excludekeeps the script’s own output folder out of the scan.--error-format jsonprints any failure as one JSON object with a stablecode, which is easier to read in CI logs and to parse. - Convert.
convertturns the findings into a CycloneDX 1.7 CBOM and validates it against the CycloneDX schema. The CBOM includes only findings with complete metadata, so it can list fewer assets than the findings file. - Inventory. The script counts the findings per algorithm family, such as
AES,SHA-2, orECDSA. - Post-quantum report. The script lists every use of a public-key family that a large quantum computer
could break: RSA (including
RSASSA-PKCS1,RSASSA-PSS,RSAES-OAEP, andRSAES-PKCS1), DSA, ECDSA, ECDH, ECIES, EdDSA, and finite-field Diffie-Hellman. These are the uses to replace with post-quantum algorithms such asML-KEMandML-DSA, which Crypto Finder also reports. - Gate. The script lists uses of broken algorithms and fails the build if it finds any.
What the output means
A sample of
quantum-vulnerable.tsv:
How it fails the pipeline
Crypto Finder also has
--fail-on-findings, which exits 1 when it finds any
cryptography. That is useful to keep cryptography out of a component that must not have any.
For an inventory it is too broad, because almost every codebase uses some cryptography, so this
recipe filters the findings with jq instead. With --error-format json, a failure caused by
--fail-on-findings has the code findings_detected, so you can tell it apart from a tool
error.Include your dependencies
In most projects, the bulk of the cryptography is in third-party libraries. To scan your dependencies as well, use thelatest-deps image, which includes the language toolchains needed to resolve them, and add
--scan-dependencies:
"source": "dependency" and a dependency_info object with the module and
version. The post-quantum report above already labels them. See
Dependency scanning for reachability and
call-chain analysis, which tells you whether your code reaches a dependency’s cryptography.
Scan only what a pull request changed
To check a pull request for new broken algorithms without re-reporting the whole codebase, scope detection to the changed files:crypto-findings.json. Crypto Finder checks only the listed
files, but it still reads the rest of the repository, so the results for those files match a full
scan.
--detect-paths-from needs the default OpenGrep scanner.
Keep the inventory over time
- Run the full script on a schedule or on each release, and store the outputs with the release.
- Compare
families.txtandquantum-vulnerable.tsvbetween runs to track migration progress. - Pin the image to a version tag in CI rather than
latest, so a new release cannot change your inventory without a code change.