Skip to content

Commit

Permalink
Upgrade to CycloneDX 1.0.6 spec
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Leonard <[email protected]>
  • Loading branch information
andrew-m-leonard committed Oct 10, 2024
1 parent 736790d commit f0d731b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
14 changes: 10 additions & 4 deletions cyclonedx-lib/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
<property name="openkeystore-version" value="1.0.0"/>

<!-- When retrieving sbom dependency jars with default settings, we will look here. -->
<property name="sbom_dependency_default_location" value="https://ci.adoptium.net/view/all/job/build.getDependency/467/artifact/sbom_dependencies"/>
<property name="sbom_dependency_default_location" value="https://ci.adoptium.net/view/all/job/build.getDependency/469/artifact/sbom_dependencies"/>

<!-- classpath for running application -->
<property name="classpath" value="build/jar/temurin-gen-sbom.jar:build/jar/cyclonedx-core-java.jar:build/jar/jackson-core.jar:build/jar/jackson-dataformat-xml.jar:build/jar/jackson-databind.jar:build/jar/jackson-annotations.jar:build/jar/json-schema.jar:build/jar/commons-codec.jar:build/jar/commons-io.jar:build/jar/github-package-url.jar:build/jar/webpki.org-libext-1.00.jar:build/jar/temurin-sign-sbom.jar"/>
<property name="classpath" value="build/jar/temurin-gen-sbom.jar:build/jar/cyclonedx-core-java.jar:build/jar/jackson-core.jar:build/jar/jackson-dataformat-xml.jar:build/jar/jackson-databind.jar:build/jar/jackson-annotations.jar:build/jar/json-schema.jar:build/jar/commons-codec.jar:build/jar/commons-io.jar:build/jar/github-package-url.jar:build/jar/webpki.org-libext-1.00.jar:build/jar/temurin-sign-sbom.jar:build/jar/commons-collections4.jar"/>

<target name="dep-checks">
<available file="build/jar/cyclonedx-core-java.jar" property="cyclonedx_available"/>
Expand All @@ -38,6 +38,7 @@
<available file="build/jar/json-schema.jar" property="json-schema_available"/>
<available file="build/jar/commons-codec.jar" property="commons-codec_available"/>
<available file="build/jar/commons-io.jar" property="commons-io_available"/>
<available file="build/jar/commons-collections4.jar" property="commons-collections4_available"/>
<available file="build/jar/github-package-url.jar" property="github-package-url_available"/>
<available file="build/webpki.org-libext-1.00.jar" property="openkeystore_available"/>
</target>
Expand Down Expand Up @@ -65,7 +66,7 @@
</move>
</target>

<target name="build-sign-sbom" depends="dep-checks, clone-and-build-openkeystore, download-cyclonedx, download-jackson-core, download-jackson-dataformat-xml, download-jackson-databind, download-jackson-annotations, download-json-schema, download-commons-codec, download-commons-io, download-github-package-url, compile-sign-sbom, jar-sign-sbom">
<target name="build-sign-sbom" depends="dep-checks, clone-and-build-openkeystore, download-cyclonedx, download-jackson-core, download-jackson-dataformat-xml, download-jackson-databind, download-jackson-annotations, download-json-schema, download-commons-codec, download-commons-io, download-commons-collections4, download-github-package-url, compile-sign-sbom, jar-sign-sbom">
<echo message="Building cyclonedx-lib TemurinSignSBOM"/>
</target>

Expand Down Expand Up @@ -114,12 +115,17 @@
<download-file-with-default-options destfile="commons-io.jar"/>
</target>

<target name="download-commons-collections4" unless="commons-collections4_available">
<echo message="Downloading commons-collections4"/>
<download-file-with-default-options destfile="commons-collections4.jar"/>
</target>

<target name="download-github-package-url" unless="github-package-url_available">
<echo message="Downloading github-package-url"/>
<download-file-with-default-options destfile="github-package-url.jar"/>
</target>

<target name="build" depends="dep-checks, download-cyclonedx, download-jackson-core, download-jackson-dataformat-xml, download-jackson-databind, download-jackson-annotations, download-json-schema, download-commons-codec, download-commons-io, download-github-package-url, compile, jar">
<target name="build" depends="dep-checks, download-cyclonedx, download-jackson-core, download-jackson-dataformat-xml, download-jackson-databind, download-jackson-annotations, download-json-schema, download-commons-codec, download-commons-io, download-commons-collections4, download-github-package-url, compile, jar">
<echo message="Building cyclonedx-lib"/>
</target>

Expand Down
35 changes: 28 additions & 7 deletions cyclonedx-lib/sign_src/TemurinSignSBOM.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ********************************************************************************
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2023,2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) with this work for additional
* information regarding copyright ownership.
Expand All @@ -15,11 +15,13 @@

package temurin.sbom;

import org.cyclonedx.BomGeneratorFactory;
import org.cyclonedx.exception.GeneratorException;
import org.cyclonedx.generators.json.BomJsonGenerator;
import org.cyclonedx.CycloneDxSchema;
import org.cyclonedx.generators.json.BomJsonGenerator;
import org.cyclonedx.model.Bom;
import org.cyclonedx.parsers.JsonParser;
import org.cyclonedx.Version;

import org.webpki.json.JSONAsymKeySigner;
import org.webpki.json.JSONObjectReader;
Expand Down Expand Up @@ -113,7 +115,13 @@ static Bom signSBOM(final String jsonFile, final String pemFile) {
if (bom == null) {
return null;
}
String sbomDataToSign = generateBomJson(bom);
String sbomDataToSign;
try {
sbomDataToSign = generateBomJson(bom);
} catch (GeneratorException e) {
LOGGER.log(Level.SEVERE, "Exception generating BOM", e);
return null;
}

// Read the private key
KeyPair signingKey = PEMDecoder.getKeyPair(Files.readAllBytes(Paths.get(pemFile)));
Expand All @@ -132,15 +140,22 @@ static Bom signSBOM(final String jsonFile, final String pemFile) {
}
}

static String generateBomJson(final Bom bom) {
BomJsonGenerator bomGen = BomGeneratorFactory.createJson(CycloneDxSchema.Version.VERSION_14, bom);
static String generateBomJson(final Bom bom) throws GeneratorException {
BomJsonGenerator bomGen = new BomJsonGenerator(bom, Version.VERSION_16);
String json = bomGen.toJsonString();
return json;
}

static boolean writeJSONfile(final Bom bom, final String fileName) {
// Creates testJson.json file
String json = generateBomJson(bom);
String json;
try {
json = generateBomJson(bom);
} catch (GeneratorException e) {
LOGGER.log(Level.SEVERE, "Exception generating BOM", e);
return false;
}

try (FileWriter file = new FileWriter(fileName)) {
file.write(json);
return true;
Expand All @@ -164,7 +179,13 @@ static boolean verifySignature(final String jsonFile, final String publicKeyFile
try {
// Read the JSON file to be verified
Bom bom = readJSONfile(jsonFile);
String signedSbomData = generateBomJson(bom);
String signedSbomData;
try {
signedSbomData = generateBomJson(bom);
} catch (GeneratorException e) {
LOGGER.log(Level.SEVERE, "Exception generating BOM", e);
return false;
}

// Parse JSON
JSONObjectReader reader = JSONParser.parse(signedSbomData);
Expand Down
2 changes: 1 addition & 1 deletion cyclonedx-lib/src/temurin/sbom/TemurinGenSBOM.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ********************************************************************************
* Copyright (c) 2021 Contributors to the Eclipse Foundation
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) with this work for additional
* information regarding copyright ownership.
Expand Down

0 comments on commit f0d731b

Please sign in to comment.