Skip to content

Commit d776d52

Browse files
authored
fix: support other versions of cyclonedx (#45)
1 parent dc8b880 commit d776d52

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/cve_bin_tool.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import glob
55
import json
6+
import re
67
import subprocess
78
import tempfile
89
from pathlib import Path
@@ -197,13 +198,17 @@ def sbom_finder(directory):
197198
"bomFormat" in json_data
198199
and "specVersion" in json_data
199200
and json_data["bomFormat"] == "CycloneDX"
200-
and json_data["specVersion"] == "1.3"
201201
):
202-
sboms.append({"file": file, "type": "cyclonedx"})
202+
try:
203+
spec_version = float(json_data["specVersion"])
204+
except Exception:
205+
spec_version = 0
206+
if spec_version >= 1.3 and spec_version <= 1.5:
207+
sboms.append({"file": file, "type": "cyclonedx"})
203208
elif file.endswith(".xml"):
204209
with open(file) as fd:
205210
data = fd.read()
206-
if data.find("cyclonedx.org/schema/bom/1.3") != -1:
211+
if re.search(r"cyclonedx\.org\/schema\/bom\/1\.[3-5]", data):
207212
sboms.append({"file": file, "type": "cyclonedx"})
208213
elif (
209214
data.find("standards.iso.org/iso/19770/-2/2015/schema.xsd")

test/sbom/cyclonedx_test.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<bom xmlns="http://cyclonedx.org/schema/bom/1.3"
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.4"
33
serialNumber="urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79"
44
version="1">
55
<components>
@@ -24,4 +24,4 @@
2424
<version>2.11.1</version>
2525
</component>
2626
</components>
27-
</bom>
27+
</bom>

test/sbom/cyclonedx_test2.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"bomFormat": "CycloneDX",
3-
"specVersion": "1.3",
3+
"specVersion": "1.5",
44
"serialNumber": "urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79",
55
"version": 1,
66
"components": [
@@ -46,4 +46,4 @@
4646
"description": "On board firmware"
4747
}
4848
]
49-
}
49+
}

0 commit comments

Comments
 (0)