Dependency provenance and SBOM
What you will learn
Every dependency is code that may run with your application’s privileges. A software bill of materials (SBOM) records components and relationships; provenance records where and how an artifact was built. Neither alone establishes that a release is trustworthy.
- Identify direct, transitive and build-time dependencies.
- Distinguish integrity, publisher identity and vulnerability evidence.
- Verify a signature and reject a mismatched repository policy.
Plain Java 21: save each example as Main.java in a fresh directory, compile with javac --release 21 Main.java, then run java Main. Trusted local fixtures only. No network or third-party dependency is needed.
Select an approved repository
public class Main { static boolean approved(String group,String repository) { if (group == null || repository == null) return false; return switch(group) { case "example.internal" -> repository.equals("private-approved"); case "example.public" -> repository.equals("public-approved"); default -> false; }; } public static void main(String[] args) throws Exception { System.out.println(approved("example.internal","private-approved")); System.out.println(approved("example.internal","public-approved")); }}Expected output:
truefalseAn exact coordinate-group policy prevents accidental selection of the wrong source in this model. Actual build-tool repository resolution needs integration tests.
Inventory the resolved build
A declared dependency is not necessarily the version selected by Maven or Gradle. Review the resolved tree, plugins, annotation processors, wrappers and packaged runtime contents. mvn dependency:tree and gradle dependencies are source-reviewed commands; only run approved builds because plugins and scripts can execute code. Capture a versioned SBOM (CycloneDX or SPDX) for the exact artifact digest. Include component identifiers, versions and dependency relationships; reconcile shaded and bundled code. A list of names alone is not a complete SBOM. The companion inventory is deliberately a small custom teaching format, not a standards-conformant SBOM.
Repository and artifact trust
Use controlled HTTPS repositories, explicit version constraints and reviewed lock or resolution evidence. Maven mirrors and checksum policy can constrain retrieval; Gradle dependency verification can pin trusted checksums and signing keys. Never blindly accept new checksums generated from an untrusted download. Restrict internal coordinates to the intended source. A SHA-256 digest detects a change relative to a trusted expected digest; a digital signature also binds bytes to possession of a signing key. Verify signer identity, authorized scope, key lifecycle and provenance separately. Do not trust a key delivered alongside an untrusted artifact without independent verification.
Release workflow
Build → inventory → scan → sign/attest → verify against trusted policy → approve → promote identical bytes. A valid signature can accompany vulnerable code. Use protected signing infrastructure in production; the local example generates an ephemeral key and never exports a private key. Reject stale or missing evidence, investigate mismatches, and keep a traceable exception process.
Verify a release signature
import java.security.*;public class Main { static byte[] sign(PrivateKey key,byte[] data) throws GeneralSecurityException { Signature s=Signature.getInstance("Ed25519"); s.initSign(key); s.update(data); return s.sign(); } static boolean verify(PublicKey key,byte[] data,byte[] sig) throws GeneralSecurityException { Signature s=Signature.getInstance("Ed25519"); s.initVerify(key); s.update(data); return s.verify(sig); } public static void main(String[] args) throws Exception { var pair=KeyPairGenerator.getInstance("Ed25519").generateKeyPair(); byte[] artifact="catalog-v1".getBytes(java.nio.charset.StandardCharsets.UTF_8); byte[] signature=sign(pair.getPrivate(),artifact); System.out.println(verify(pair.getPublic(),artifact,signature)); byte[] changed="catalog-v2".getBytes(java.nio.charset.StandardCharsets.UTF_8); System.out.println(verify(pair.getPublic(),changed,signature)); }}Expected output:
truefalseFresh random keys are intentionally not printed. The boolean results are deterministic under normal JDK behavior. This verifies bytes, not real publisher identity.
Inventory a transitive component
public class Main { static void walk(String id,java.util.Map<String,java.util.List<String>> graph,java.util.Set<String> found) { if(!found.add(id)) return; for(String next:graph.getOrDefault(id,java.util.List.of())) walk(next,graph,found); } public static void main(String[] args) throws Exception { var graph=java.util.Map.of("app",java.util.List.of("api"),"api",java.util.List.of("codec"),"codec",java.util.List.<String>of()); var found=new java.util.TreeSet<String>(); walk("app",graph,found); System.out.println(found); }}Expected output:
[api, app, codec]A three-node synthetic graph shows why indirect dependencies matter. A production inventory needs versions, artifact identities, completeness and bounded traversal.
Common mistakes
Do not equate a checksum with trusted provenance, an SBOM with a scan, or a verified signature with safe behavior. Do not disable repository verification to make a build pass.
Practice
Test the repository policy for an unknown group and for the public group using its approved repository. Print false then true.
Expected output:
falsetrueCompare with the manual review criteria.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Dependency provenance and SBOM — knowledge check
Java security and software supply-chain reasoning.
What does an SBOM describe?
What must a signature verifier trust independently?
Which dependencies deserve review?
What does matching a digest establish?
What if repository verification fails?