Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support for CycloneDX v1.6 #576

Merged
merged 34 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
41ca1e0
added draft v1.6 schemas and boilerplate for v1.6
madpah Apr 3, 2024
8132c3e
re-generated test snapshots for v1.6
madpah Apr 3, 2024
240dfaa
note `bom.metadata.manufacture` as deprecated
madpah Apr 3, 2024
6192ed8
work on `bom.metadata` for v1.6
madpah Apr 3, 2024
6227c08
Deprecated `.component.author`. Added `.component.authors` and `.comp…
madpah Apr 3, 2024
af7b92b
work to add `.component.omniborid` - but tests deserialisation tests …
madpah Apr 3, 2024
fdece59
work to get deserialization tests passing
madpah Apr 3, 2024
0398051
chore(deps): bump `py-serializable` to >=1.0.3 to resolve issues with…
madpah Apr 4, 2024
875a338
imports tidied
madpah Apr 4, 2024
ee80ea3
properly added `.component.swhid`
madpah Apr 5, 2024
1e71dc3
add `.component.cryptoProperties` - with test failures for SchemaVers…
madpah Apr 5, 2024
96a6dc9
typing and bandit ignores
madpah Apr 5, 2024
b23df1f
coding standards
madpah Apr 5, 2024
14f699f
test filtering
madpah Apr 5, 2024
a3e09d1
coding standards
madpah Apr 5, 2024
f504daa
additional tests to increase code coverage
madpah Apr 5, 2024
71e4bc6
corrected CryptoMode enum
madpah Apr 5, 2024
d294620
coding standards
madpah Apr 5, 2024
318d723
Added `address` to `organizationalEntity`
madpah Apr 8, 2024
1327558
Added `address` to `organizationalEntity`
madpah Apr 8, 2024
abebd4f
raise `UserWarning` in `.component.version` has length > 1024
madpah Apr 8, 2024
5c97c2d
coding standards and typing
madpah Apr 8, 2024
ddd7847
add `acknowledgement` to `LicenseExpression` (#582)
madpah Apr 8, 2024
0a2ca2c
more proper way to filter test cases
madpah Apr 9, 2024
0449de2
update schema to published versions
madpah Apr 9, 2024
289e81a
fetch schema 1.6 JSON
jkowalleck Apr 9, 2024
618a292
fetch test data for CDX 1.6
jkowalleck Apr 9, 2024
e0184cc
reformat
jkowalleck Apr 9, 2024
e10ffee
reformat
jkowalleck Apr 9, 2024
62c1d9a
refactor
jkowalleck Apr 9, 2024
0843234
style
jkowalleck Apr 9, 2024
b4a133a
refactor
jkowalleck Apr 9, 2024
42c6f25
docs
jkowalleck Apr 9, 2024
27833f7
chore(release): 7.0.0-alpha.1
Apr 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions cyclonedx/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
SchemaVersion1Dot3,
SchemaVersion1Dot4,
SchemaVersion1Dot5,
SchemaVersion1Dot6,
)


Expand Down Expand Up @@ -508,10 +509,12 @@ class ExternalReferenceType(str, Enum):
CODIFIED_INFRASTRUCTURE = 'codified-infrastructure' # Only supported in >= 1.5
COMPONENT_ANALYSIS_REPORT = 'component-analysis-report' # Only supported in >= 1.5
CONFIGURATION = 'configuration' # Only supported in >= 1.5
DIGITAL_SIGNATURE = 'digital-signature' # Only supported in >= 1.6
DISTRIBUTION = 'distribution'
DISTRIBUTION_INTAKE = 'distribution-intake' # Only supported in >= 1.5
DOCUMENTATION = 'documentation'
DYNAMIC_ANALYSIS_REPORT = 'dynamic-analysis-report' # Only supported in >= 1.5
ELECTRONIC_SIGNATURE = 'electronic-signature' # Only supported in >= 1.6
EVIDENCE = 'evidence' # Only supported in >= 1.5
EXPLOITABILITY_STATEMENT = 'exploitability-statement' # Only supported in >= 1.5
FORMULATION = 'formulation' # Only supported in >= 1.5
Expand All @@ -525,11 +528,13 @@ class ExternalReferenceType(str, Enum):
POAM = 'poam' # Only supported in >= 1.5
QUALITY_METRICS = 'quality-metrics' # Only supported in >= 1.5
RELEASE_NOTES = 'release-notes' # Only supported in >= 1.4
RFC_9166 = 'rfc-9116' # Only supported in >= 1.6
RISK_ASSESSMENT = 'risk-assessment' # Only supported in >= 1.5
RUNTIME_ANALYSIS_REPORT = 'runtime-analysis-report' # Only supported in >= 1.5
SECURITY_CONTACT = 'security-contact' # Only supported in >= 1.5
STATIC_ANALYSIS_REPORT = 'static-analysis-report' # Only supported in >= 1.5
SOCIAL = 'social'
SOURCE_DISTRIBUTION = 'source-distribution' # Only supported in >= 1.6
SCM = 'vcs'
SUPPORT = 'support'
THREAT_MODEL = 'threat-model' # Only supported in >= 1.5
Expand Down Expand Up @@ -591,6 +596,12 @@ class _ExternalReferenceSerializationHelper(serializable.helpers.BaseHelper):
ExternalReferenceType.CODIFIED_INFRASTRUCTURE,
ExternalReferenceType.POAM,
}
__CASES[SchemaVersion1Dot6] = __CASES[SchemaVersion1Dot5] | {
ExternalReferenceType.SOURCE_DISTRIBUTION,
ExternalReferenceType.ELECTRONIC_SIGNATURE,
ExternalReferenceType.DIGITAL_SIGNATURE,
ExternalReferenceType.RFC_9166,
}

@classmethod
def __normalize(cls, extref: ExternalReferenceType, view: Type[serializable.ViewType]) -> str:
Expand Down
14 changes: 11 additions & 3 deletions cyclonedx/model/bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,28 @@ class BomMetaData:

def __init__(self, *, tools: Optional[Iterable[Tool]] = None,
authors: Optional[Iterable[OrganizationalContact]] = None, component: Optional[Component] = None,
manufacture: Optional[OrganizationalEntity] = None,
supplier: Optional[OrganizationalEntity] = None,
licenses: Optional[Iterable[License]] = None,
properties: Optional[Iterable[Property]] = None,
timestamp: Optional[datetime] = None) -> None:
timestamp: Optional[datetime] = None,
# Deprecated as of v1.6
manufacture: Optional[OrganizationalEntity] = None) -> None:
self.timestamp = timestamp or _get_now_utc()
self.tools = tools or [] # type:ignore[assignment]
self.authors = authors or [] # type:ignore[assignment]
self.component = component
self.manufacture = manufacture
self.supplier = supplier
self.licenses = licenses or [] # type:ignore[assignment]
self.properties = properties or [] # type:ignore[assignment]

self.manufacture = manufacture
if manufacture:
warn(
"`bom.metadata.manufacture` is deprecated from CycloneDX v1.6 onwards. "
"Please use `bom.metadata.component.manufacturer` instead.",
DeprecationWarning)


if not tools:
self.tools.add(ThisTool)

Expand Down
5 changes: 5 additions & 0 deletions cyclonedx/model/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
SchemaVersion1Dot3,
SchemaVersion1Dot4,
SchemaVersion1Dot5,
SchemaVersion1Dot6,
)
from ..serialization import BomRefHelper, LicenseRepositoryHelper, PackageUrl
from . import (
Expand Down Expand Up @@ -341,6 +342,7 @@ class ComponentType(str, Enum):
# see `_ComponentTypeSerializationHelper.__CASES` for view/case map
APPLICATION = 'application'
CONTAINER = 'container' # Only supported in >= 1.2
CRYPTOGRAPHIC_ASSET = 'cryptographic-asset' # Only supported in >= 1.6
DATA = 'data' # Only supported in >= 1.5
DEVICE = 'device'
DEVICE_DRIVER = 'device-driver' # Only supported in >= 1.5
Expand Down Expand Up @@ -379,6 +381,9 @@ class _ComponentTypeSerializationHelper(serializable.helpers.BaseHelper):
ComponentType.MACHINE_LEARNING_MODEL,
ComponentType.PLATFORM,
}
__CASES[SchemaVersion1Dot6] = __CASES[SchemaVersion1Dot5] | {
ComponentType.CRYPTOGRAPHIC_ASSET,
}

@classmethod
def __normalize(cls, ct: ComponentType, view: Type[serializable.ViewType]) -> Optional[str]:
Expand Down
8 changes: 8 additions & 0 deletions cyclonedx/output/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
SchemaVersion1Dot3,
SchemaVersion1Dot4,
SchemaVersion1Dot5,
SchemaVersion1Dot6,
)
from . import BaseOutput, BomRefDiscriminator

Expand Down Expand Up @@ -124,7 +125,14 @@ def _get_schema_uri(self) -> str:
return 'http://cyclonedx.org/schema/bom-1.5.schema.json'


class JsonV1Dot6(Json, SchemaVersion1Dot6):

def _get_schema_uri(self) -> str:
return 'http://cyclonedx.org/schema/bom-1.6.schema.json'


BY_SCHEMA_VERSION: Dict[SchemaVersion, Type[Json]] = {
SchemaVersion.V1_6: JsonV1Dot6,
SchemaVersion.V1_5: JsonV1Dot5,
SchemaVersion.V1_4: JsonV1Dot4,
SchemaVersion.V1_3: JsonV1Dot3,
Expand Down
6 changes: 6 additions & 0 deletions cyclonedx/output/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
SchemaVersion1Dot3,
SchemaVersion1Dot4,
SchemaVersion1Dot5,
SchemaVersion1Dot6,
)
from . import BaseOutput, BomRefDiscriminator

Expand Down Expand Up @@ -119,7 +120,12 @@ class XmlV1Dot5(Xml, SchemaVersion1Dot5):
pass


class XmlV1Dot6(Xml, SchemaVersion1Dot6):
pass


BY_SCHEMA_VERSION: Dict[SchemaVersion, Type[Xml]] = {
SchemaVersion.V1_6: XmlV1Dot6,
SchemaVersion.V1_5: XmlV1Dot5,
SchemaVersion.V1_4: XmlV1Dot4,
SchemaVersion.V1_3: XmlV1Dot3,
Expand Down
1 change: 1 addition & 0 deletions cyclonedx/schema/_res/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
}

BOM_JSON_STRICT: Dict[SchemaVersion, Optional[str]] = {
SchemaVersion.V1_6: BOM_JSON[SchemaVersion.V1_6],
# >= v1.4 is already strict - no special file here
SchemaVersion.V1_5: BOM_JSON[SchemaVersion.V1_5],
SchemaVersion.V1_4: BOM_JSON[SchemaVersion.V1_4],
Expand Down
2 changes: 1 addition & 1 deletion cyclonedx/schema/_res/bom-1.6.SNAPSHOT.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ limitations under the License.
vc:maxVersion="1.1"
version="1.6.0">

<xs:import namespace="http://cyclonedx.org/schema/spdx" schemaLocation="http://cyclonedx.org/schema/spdx"/>
<xs:import namespace="http://cyclonedx.org/schema/spdx" schemaLocation="spdx.SNAPSHOT.xsd"/>

<xs:annotation>
<xs:documentation>
Expand Down
20 changes: 20 additions & 0 deletions tests/_data/snapshots/enum_ComponentScope-1.6.json.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"components": [
{
"name": "dummy-EXCLUDED",
"type": "library"
},
{
"name": "dummy-OPTIONAL",
"type": "library"
},
{
"name": "dummy-REQUIRED",
"type": "library"
}
],
"version": 1,
"$schema": "http://cyclonedx.org/schema/bom-1.6.schema.json",
"bomFormat": "CycloneDX",
"specVersion": "1.6"
}
14 changes: 14 additions & 0 deletions tests/_data/snapshots/enum_ComponentScope-1.6.xml.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" ?>
<bom xmlns="http://cyclonedx.org/schema/bom/1.6" version="1">
<components>
<component type="library">
<name>dummy-EXCLUDED</name>
</component>
<component type="library">
<name>dummy-OPTIONAL</name>
</component>
<component type="library">
<name>dummy-REQUIRED</name>
</component>
</components>
</bom>
60 changes: 60 additions & 0 deletions tests/_data/snapshots/enum_ComponentType-1.6.json.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"components": [
{
"name": "dummy APPLICATION",
"type": "application"
},
{
"name": "dummy CONTAINER",
"type": "container"
},
{
"name": "dummy CRYPTOGRAPHIC_ASSET",
"type": "cryptographic-asset"
},
{
"name": "dummy DATA",
"type": "data"
},
{
"name": "dummy DEVICE",
"type": "device"
},
{
"name": "dummy DEVICE_DRIVER",
"type": "device-driver"
},
{
"name": "dummy FILE",
"type": "file"
},
{
"name": "dummy FIRMWARE",
"type": "firmware"
},
{
"name": "dummy FRAMEWORK",
"type": "framework"
},
{
"name": "dummy LIBRARY",
"type": "library"
},
{
"name": "dummy MACHINE_LEARNING_MODEL",
"type": "machine-learning-model"
},
{
"name": "dummy OPERATING_SYSTEM",
"type": "operating-system"
},
{
"name": "dummy PLATFORM",
"type": "platform"
}
],
"version": 1,
"$schema": "http://cyclonedx.org/schema/bom-1.6.schema.json",
"bomFormat": "CycloneDX",
"specVersion": "1.6"
}
44 changes: 44 additions & 0 deletions tests/_data/snapshots/enum_ComponentType-1.6.xml.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" ?>
<bom xmlns="http://cyclonedx.org/schema/bom/1.6" version="1">
<components>
<component type="application">
<name>dummy APPLICATION</name>
</component>
<component type="container">
<name>dummy CONTAINER</name>
</component>
<component type="cryptographic-asset">
<name>dummy CRYPTOGRAPHIC_ASSET</name>
</component>
<component type="data">
<name>dummy DATA</name>
</component>
<component type="device">
<name>dummy DEVICE</name>
</component>
<component type="device-driver">
<name>dummy DEVICE_DRIVER</name>
</component>
<component type="file">
<name>dummy FILE</name>
</component>
<component type="firmware">
<name>dummy FIRMWARE</name>
</component>
<component type="framework">
<name>dummy FRAMEWORK</name>
</component>
<component type="library">
<name>dummy LIBRARY</name>
</component>
<component type="machine-learning-model">
<name>dummy MACHINE_LEARNING_MODEL</name>
</component>
<component type="operating-system">
<name>dummy OPERATING_SYSTEM</name>
</component>
<component type="platform">
<name>dummy PLATFORM</name>
</component>
</components>
</bom>
6 changes: 6 additions & 0 deletions tests/_data/snapshots/enum_DataFlow-1.6.json.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": 1,
"$schema": "http://cyclonedx.org/schema/bom-1.6.schema.json",
"bomFormat": "CycloneDX",
"specVersion": "1.6"
}
2 changes: 2 additions & 0 deletions tests/_data/snapshots/enum_DataFlow-1.6.xml.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" ?>
<bom xmlns="http://cyclonedx.org/schema/bom/1.6" version="1"/>
12 changes: 12 additions & 0 deletions tests/_data/snapshots/enum_Encoding-1.6.json.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"components": [
{
"name": "dummy",
"type": "library"
}
],
"version": 1,
"$schema": "http://cyclonedx.org/schema/bom-1.6.schema.json",
"bomFormat": "CycloneDX",
"specVersion": "1.6"
}
8 changes: 8 additions & 0 deletions tests/_data/snapshots/enum_Encoding-1.6.xml.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" ?>
<bom xmlns="http://cyclonedx.org/schema/bom/1.6" version="1">
<components>
<component type="library">
<name>dummy</name>
</component>
</components>
</bom>
12 changes: 12 additions & 0 deletions tests/_data/snapshots/enum_ExternalReferenceType-1.1.xml.bin
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
<reference type="other">
<url>tests/CONFIGURATION</url>
</reference>
<reference type="other">
<url>tests/DIGITAL_SIGNATURE</url>
</reference>
<reference type="distribution">
<url>tests/DISTRIBUTION</url>
</reference>
Expand All @@ -50,6 +53,9 @@
<reference type="other">
<url>tests/DYNAMIC_ANALYSIS_REPORT</url>
</reference>
<reference type="other">
<url>tests/ELECTRONIC_SIGNATURE</url>
</reference>
<reference type="other">
<url>tests/EVIDENCE</url>
</reference>
Expand Down Expand Up @@ -92,6 +98,9 @@
<reference type="other">
<url>tests/RELEASE_NOTES</url>
</reference>
<reference type="other">
<url>tests/RFC_9166</url>
</reference>
<reference type="other">
<url>tests/RISK_ASSESSMENT</url>
</reference>
Expand All @@ -104,6 +113,9 @@
<reference type="social">
<url>tests/SOCIAL</url>
</reference>
<reference type="other">
<url>tests/SOURCE_DISTRIBUTION</url>
</reference>
<reference type="other">
<url>tests/STATIC_ANALYSIS_REPORT</url>
</reference>
Expand Down
Loading
Loading