Skip to content

Commit beb35f5

Browse files
authored
feat: add cyclonedx.model.crypto.ProtocolProperties.crypto_refs (#767)
Signed-off-by: Indivar Mishra <[email protected]>
1 parent 2a87f50 commit beb35f5

15 files changed

+402
-2
lines changed

cyclonedx/model/crypto.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -1309,11 +1309,13 @@ def __init__(
13091309
version: Optional[str] = None,
13101310
cipher_suites: Optional[Iterable[ProtocolPropertiesCipherSuite]] = None,
13111311
ikev2_transform_types: Optional[Ikev2TransformTypes] = None,
1312+
crypto_refs: Optional[Iterable[BomRef]] = None,
13121313
) -> None:
13131314
self.type = type
13141315
self.version = version
13151316
self.cipher_suites = cipher_suites or [] # type:ignore[assignment]
13161317
self.ikev2_transform_types = ikev2_transform_types
1318+
self.crypto_refs = crypto_refs or [] # type:ignore[assignment]
13171319

13181320
@property
13191321
@serializable.xml_sequence(10)
@@ -1376,13 +1378,37 @@ def ikev2_transform_types(self) -> Optional[Ikev2TransformTypes]:
13761378
def ikev2_transform_types(self, ikev2_transform_types: Optional[Ikev2TransformTypes]) -> None:
13771379
self._ikev2_transform_types = ikev2_transform_types
13781380

1381+
@property
1382+
@serializable.xml_array(serializable.XmlArraySerializationType.FLAT, 'cryptoRef')
1383+
@serializable.json_name('cryptoRefArray')
1384+
def crypto_refs(self) -> 'SortedSet[BomRef]':
1385+
"""
1386+
A list of protocol-related cryptographic assets.
1387+
1388+
Returns:
1389+
`Iterable[BomRef]`
1390+
"""
1391+
return self._crypto_refs
1392+
1393+
@crypto_refs.setter
1394+
def crypto_refs(self, crypto_refs: Iterable[BomRef]) -> None:
1395+
self._crypto_refs = SortedSet(crypto_refs)
1396+
13791397
def __eq__(self, other: object) -> bool:
13801398
if isinstance(other, ProtocolProperties):
13811399
return hash(other) == hash(self)
13821400
return False
13831401

13841402
def __hash__(self) -> int:
1385-
return hash((self.type, self.version, tuple(self.cipher_suites), self.ikev2_transform_types))
1403+
return hash(
1404+
(
1405+
self.type,
1406+
self.version,
1407+
tuple(self.cipher_suites),
1408+
self.ikev2_transform_types,
1409+
tuple(self.crypto_refs)
1410+
)
1411+
)
13861412

13871413
def __repr__(self) -> str:
13881414
return f'<ProtocolProperties type={self.type}, version={self.version}>'

tests/_data/models.py

+28
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,33 @@ def get_bom_for_issue_328_components() -> Bom:
708708
return bom
709709

710710

711+
def get_bom_for_issue_692_components() -> Bom:
712+
"""regression test for issue #692
713+
see https://github.com/CycloneDX/cyclonedx-python-lib/issues/692
714+
"""
715+
bom = _make_bom()
716+
717+
comp_root = Component(type=ComponentType.APPLICATION,
718+
name='my application', version='1', bom_ref='my-project')
719+
comp_test = Component(
720+
name='comp_test',
721+
type=ComponentType.APPLICATION,
722+
bom_ref='crypto/protocol/test',
723+
crypto_properties=CryptoProperties(
724+
asset_type=CryptoAssetType.PROTOCOL,
725+
protocol_properties=ProtocolProperties(
726+
type=ProtocolPropertiesType.TLS,
727+
version='1.2',
728+
crypto_refs=[BomRef(value='for-test')]
729+
),
730+
oid='1.3.18.0.2.32.104',
731+
))
732+
bom.metadata.component = comp_root
733+
bom.register_dependency(comp_root, [comp_test])
734+
bom.components = [comp_test]
735+
return bom
736+
737+
711738
def get_component_setuptools_complete(include_pedigree: bool = True) -> Component:
712739
component = get_component_setuptools_simple(bom_ref='my-specific-bom-ref-for-dings')
713740
component.supplier = get_org_entity_1()
@@ -1449,4 +1476,5 @@ def get_bom_with_definitions_and_detailed_standards() -> Bom:
14491476
get_bom_with_lifecycles,
14501477
get_bom_with_definitions_standards,
14511478
get_bom_with_definitions_and_detailed_standards,
1479+
get_bom_for_issue_692_components,
14521480
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" ?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.0" version="1">
3+
<components>
4+
<component type="application">
5+
<name>comp_test</name>
6+
<version/>
7+
<modified>false</modified>
8+
</component>
9+
</components>
10+
</bom>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" ?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.1" serialNumber="urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac" version="1">
3+
<components>
4+
<component type="application" bom-ref="crypto/protocol/test">
5+
<name>comp_test</name>
6+
<version/>
7+
</component>
8+
</components>
9+
</bom>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"components": [
3+
{
4+
"bom-ref": "crypto/protocol/test",
5+
"name": "comp_test",
6+
"type": "application",
7+
"version": ""
8+
}
9+
],
10+
"dependencies": [
11+
{
12+
"ref": "crypto/protocol/test"
13+
},
14+
{
15+
"dependsOn": [
16+
"crypto/protocol/test"
17+
],
18+
"ref": "my-project"
19+
}
20+
],
21+
"metadata": {
22+
"component": {
23+
"bom-ref": "my-project",
24+
"name": "my application",
25+
"type": "application",
26+
"version": "1"
27+
},
28+
"timestamp": "2023-01-07T13:44:32.312678+00:00"
29+
},
30+
"serialNumber": "urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac",
31+
"version": 1,
32+
"$schema": "http://cyclonedx.org/schema/bom-1.2b.schema.json",
33+
"bomFormat": "CycloneDX",
34+
"specVersion": "1.2"
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" ?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.2" serialNumber="urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac" version="1">
3+
<metadata>
4+
<timestamp>2023-01-07T13:44:32.312678+00:00</timestamp>
5+
<component type="application" bom-ref="my-project">
6+
<name>my application</name>
7+
<version>1</version>
8+
</component>
9+
</metadata>
10+
<components>
11+
<component type="application" bom-ref="crypto/protocol/test">
12+
<name>comp_test</name>
13+
<version/>
14+
</component>
15+
</components>
16+
<dependencies>
17+
<dependency ref="crypto/protocol/test"/>
18+
<dependency ref="my-project">
19+
<dependency ref="crypto/protocol/test"/>
20+
</dependency>
21+
</dependencies>
22+
</bom>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"components": [
3+
{
4+
"bom-ref": "crypto/protocol/test",
5+
"name": "comp_test",
6+
"type": "application",
7+
"version": ""
8+
}
9+
],
10+
"dependencies": [
11+
{
12+
"ref": "crypto/protocol/test"
13+
},
14+
{
15+
"dependsOn": [
16+
"crypto/protocol/test"
17+
],
18+
"ref": "my-project"
19+
}
20+
],
21+
"metadata": {
22+
"component": {
23+
"bom-ref": "my-project",
24+
"name": "my application",
25+
"type": "application",
26+
"version": "1"
27+
},
28+
"timestamp": "2023-01-07T13:44:32.312678+00:00"
29+
},
30+
"serialNumber": "urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac",
31+
"version": 1,
32+
"$schema": "http://cyclonedx.org/schema/bom-1.3a.schema.json",
33+
"bomFormat": "CycloneDX",
34+
"specVersion": "1.3"
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" ?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.3" serialNumber="urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac" version="1">
3+
<metadata>
4+
<timestamp>2023-01-07T13:44:32.312678+00:00</timestamp>
5+
<component type="application" bom-ref="my-project">
6+
<name>my application</name>
7+
<version>1</version>
8+
</component>
9+
</metadata>
10+
<components>
11+
<component type="application" bom-ref="crypto/protocol/test">
12+
<name>comp_test</name>
13+
<version/>
14+
</component>
15+
</components>
16+
<dependencies>
17+
<dependency ref="crypto/protocol/test"/>
18+
<dependency ref="my-project">
19+
<dependency ref="crypto/protocol/test"/>
20+
</dependency>
21+
</dependencies>
22+
</bom>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"components": [
3+
{
4+
"bom-ref": "crypto/protocol/test",
5+
"name": "comp_test",
6+
"type": "application"
7+
}
8+
],
9+
"dependencies": [
10+
{
11+
"ref": "crypto/protocol/test"
12+
},
13+
{
14+
"dependsOn": [
15+
"crypto/protocol/test"
16+
],
17+
"ref": "my-project"
18+
}
19+
],
20+
"metadata": {
21+
"component": {
22+
"bom-ref": "my-project",
23+
"name": "my application",
24+
"type": "application",
25+
"version": "1"
26+
},
27+
"timestamp": "2023-01-07T13:44:32.312678+00:00"
28+
},
29+
"serialNumber": "urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac",
30+
"version": 1,
31+
"$schema": "http://cyclonedx.org/schema/bom-1.4.schema.json",
32+
"bomFormat": "CycloneDX",
33+
"specVersion": "1.4"
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" ?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.4" serialNumber="urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac" version="1">
3+
<metadata>
4+
<timestamp>2023-01-07T13:44:32.312678+00:00</timestamp>
5+
<component type="application" bom-ref="my-project">
6+
<name>my application</name>
7+
<version>1</version>
8+
</component>
9+
</metadata>
10+
<components>
11+
<component type="application" bom-ref="crypto/protocol/test">
12+
<name>comp_test</name>
13+
</component>
14+
</components>
15+
<dependencies>
16+
<dependency ref="crypto/protocol/test"/>
17+
<dependency ref="my-project">
18+
<dependency ref="crypto/protocol/test"/>
19+
</dependency>
20+
</dependencies>
21+
</bom>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"components": [
3+
{
4+
"bom-ref": "crypto/protocol/test",
5+
"name": "comp_test",
6+
"type": "application"
7+
}
8+
],
9+
"dependencies": [
10+
{
11+
"ref": "crypto/protocol/test"
12+
},
13+
{
14+
"dependsOn": [
15+
"crypto/protocol/test"
16+
],
17+
"ref": "my-project"
18+
}
19+
],
20+
"metadata": {
21+
"component": {
22+
"bom-ref": "my-project",
23+
"name": "my application",
24+
"type": "application",
25+
"version": "1"
26+
},
27+
"timestamp": "2023-01-07T13:44:32.312678+00:00"
28+
},
29+
"properties": [
30+
{
31+
"name": "key1",
32+
"value": "val1"
33+
},
34+
{
35+
"name": "key2",
36+
"value": "val2"
37+
}
38+
],
39+
"serialNumber": "urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac",
40+
"version": 1,
41+
"$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json",
42+
"bomFormat": "CycloneDX",
43+
"specVersion": "1.5"
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" ?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.5" serialNumber="urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac" version="1">
3+
<metadata>
4+
<timestamp>2023-01-07T13:44:32.312678+00:00</timestamp>
5+
<component type="application" bom-ref="my-project">
6+
<name>my application</name>
7+
<version>1</version>
8+
</component>
9+
</metadata>
10+
<components>
11+
<component type="application" bom-ref="crypto/protocol/test">
12+
<name>comp_test</name>
13+
</component>
14+
</components>
15+
<dependencies>
16+
<dependency ref="crypto/protocol/test"/>
17+
<dependency ref="my-project">
18+
<dependency ref="crypto/protocol/test"/>
19+
</dependency>
20+
</dependencies>
21+
<properties>
22+
<property name="key1">val1</property>
23+
<property name="key2">val2</property>
24+
</properties>
25+
</bom>

0 commit comments

Comments
 (0)