Skip to content

Commit 840a32c

Browse files
committed
dings
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
1 parent cadb83e commit 840a32c

5 files changed

Lines changed: 348 additions & 10 deletions

File tree

cyclonedx/model/crypto.py

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class CryptoPrimitive(str, Enum):
8080
KDF = 'kdf'
8181
KEM = 'kem'
8282
KEY_AGREE = 'key-agree'
83-
KEY_WRAP = 'key-wrap' # since CDX1.7key-wrap
83+
KEY_WRAP = 'key-wrap' # since CDX1.7
8484
MAC = 'mac'
8585
PKE = 'pke'
8686
SIGNATURE = 'signature'
@@ -190,13 +190,13 @@ class CryptoImplementationPlatform(str, Enum):
190190
ARMV8_M = 'armv8-m'
191191
ARMV9_A = 'armv9-a'
192192
ARMV9_M = 'armv9-m'
193-
GENERIC = 'generic' # TODO: move down
194193
PPC64 = 'ppc64'
195194
PPC64LE = 'ppc64le'
196195
S390X = 's390x'
197196
X86_32 = 'x86_32'
198197
X86_64 = 'x86_64'
199198
# --
199+
GENERIC = 'generic'
200200
OTHER = 'other'
201201
UNKNOWN = 'unknown'
202202

@@ -799,7 +799,7 @@ class RelatedCryptoMaterialType(str, Enum):
799799
SIGNATURE = 'signature'
800800
TAG = 'tag'
801801
TOKEN = 'token' # nosec
802-
802+
# --
803803
OTHER = 'other'
804804
UNKNOWN = 'unknown'
805805

@@ -1164,23 +1164,72 @@ class ProtocolPropertiesType(str, Enum):
11641164
See the CycloneDX Schema for hashType: https://cyclonedx.org/docs/1.7/xml/#type_cryptoPropertiesType
11651165
"""
11661166

1167+
DTLS = 'dtls' # since CDX1.7
1168+
EAP_AKA ='eap-aka' # since CDX1.7
1169+
EAP_AKA_PRIME ='eap-aka-prime' # since CDX1.7
1170+
FIVEG_AKA = '5g-aka' # since CDX1.7
11671171
IKE = 'ike'
11681172
IPSEC = 'ipsec'
1173+
PRINS = 'prins' # since CDX1.7
1174+
QUIC = 'quic' # since CDX1.7
11691175
SSH = 'ssh'
11701176
SSTP = 'sstp'
11711177
TLS = 'tls'
11721178
WPA = 'wpa'
1173-
# TODO: add 'eap-aka-prime'
1174-
# TODO: add '5g-aka'
1175-
# TODO: add 'dtls'
1176-
# TODO: add 'quic'
1177-
# TODO: add 'eap-aka'
1178-
# TODO: add 'prins'
1179-
1179+
# --
11801180
OTHER = 'other'
11811181
UNKNOWN = 'unknown'
11821182

11831183

1184+
class _ProtocolPropertiesTypeSerializationHelper(serializable.helpers.BaseHelper):
1185+
""" THIS CLASS IS NON-PUBLIC API """
1186+
1187+
__CASES: dict[type[serializable.ViewType], frozenset[ProtocolPropertiesType]] = dict()
1188+
__CASES[SchemaVersion1Dot6] = frozenset({
1189+
ProtocolPropertiesType.IKE,
1190+
ProtocolPropertiesType.IPSEC,
1191+
ProtocolPropertiesType.SSH,
1192+
ProtocolPropertiesType.SSTP,
1193+
ProtocolPropertiesType.TLS,
1194+
ProtocolPropertiesType.WPA,
1195+
ProtocolPropertiesType.OTHER,
1196+
ProtocolPropertiesType.UNKNOWN,
1197+
})
1198+
__CASES[SchemaVersion1Dot7] = __CASES[SchemaVersion1Dot6] | {
1199+
ProtocolPropertiesType.DTLS,
1200+
ProtocolPropertiesType.EAP_AKA,
1201+
ProtocolPropertiesType.EAP_AKA_PRIME,
1202+
ProtocolPropertiesType.PRINS,
1203+
ProtocolPropertiesType.QUIC,
1204+
}
1205+
1206+
@classmethod
1207+
def __normalize(cls, ppt: ProtocolPropertiesType, view: type[serializable.ViewType]) -> str:
1208+
return (
1209+
ppt
1210+
if ppt in cls.__CASES.get(view, ())
1211+
else ProtocolPropertiesType.OTHER
1212+
).value
1213+
1214+
@classmethod
1215+
def json_normalize(cls, o: Any, *,
1216+
view: Optional[type[serializable.ViewType]],
1217+
**__: Any) -> str:
1218+
assert view is not None
1219+
return cls.__normalize(o, view)
1220+
1221+
@classmethod
1222+
def xml_normalize(cls, o: Any, *,
1223+
view: Optional[type[serializable.ViewType]],
1224+
**__: Any) -> str:
1225+
assert view is not None
1226+
return cls.__normalize(o, view)
1227+
1228+
@classmethod
1229+
def deserialize(cls, o: Any) -> ProtocolPropertiesType:
1230+
return ProtocolPropertiesType(o)
1231+
1232+
11841233
@serializable.serializable_class(ignore_unknown_during_deserialization=True)
11851234
class ProtocolPropertiesCipherSuite:
11861235
"""
@@ -1450,6 +1499,7 @@ def __init__(
14501499
self.crypto_refs = crypto_refs or []
14511500

14521501
@property
1502+
@serializable.type_mapping(_ProtocolPropertiesTypeSerializationHelper)
14531503
@serializable.xml_sequence(10)
14541504
def type(self) -> Optional[ProtocolPropertiesType]:
14551505
"""

tests/_data/snapshots/enum_ProtocolPropertiesType-1.6.json.bin

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,49 @@
11
{
22
"components": [
3+
{
4+
"bom-ref": "dummy-PPT:DTLS",
5+
"cryptoProperties": {
6+
"assetType": "protocol",
7+
"protocolProperties": {
8+
"type": "other"
9+
}
10+
},
11+
"name": "ProtocolPropertiesType: DTLS",
12+
"type": "cryptographic-asset"
13+
},
14+
{
15+
"bom-ref": "dummy-PPT:EAP_AKA",
16+
"cryptoProperties": {
17+
"assetType": "protocol",
18+
"protocolProperties": {
19+
"type": "other"
20+
}
21+
},
22+
"name": "ProtocolPropertiesType: EAP_AKA",
23+
"type": "cryptographic-asset"
24+
},
25+
{
26+
"bom-ref": "dummy-PPT:EAP_AKA_PRIME",
27+
"cryptoProperties": {
28+
"assetType": "protocol",
29+
"protocolProperties": {
30+
"type": "other"
31+
}
32+
},
33+
"name": "ProtocolPropertiesType: EAP_AKA_PRIME",
34+
"type": "cryptographic-asset"
35+
},
36+
{
37+
"bom-ref": "dummy-PPT:FIVEG_AKA",
38+
"cryptoProperties": {
39+
"assetType": "protocol",
40+
"protocolProperties": {
41+
"type": "other"
42+
}
43+
},
44+
"name": "ProtocolPropertiesType: FIVEG_AKA",
45+
"type": "cryptographic-asset"
46+
},
347
{
448
"bom-ref": "dummy-PPT:IKE",
549
"cryptoProperties": {
@@ -33,6 +77,28 @@
3377
"name": "ProtocolPropertiesType: OTHER",
3478
"type": "cryptographic-asset"
3579
},
80+
{
81+
"bom-ref": "dummy-PPT:PRINS",
82+
"cryptoProperties": {
83+
"assetType": "protocol",
84+
"protocolProperties": {
85+
"type": "other"
86+
}
87+
},
88+
"name": "ProtocolPropertiesType: PRINS",
89+
"type": "cryptographic-asset"
90+
},
91+
{
92+
"bom-ref": "dummy-PPT:QUIC",
93+
"cryptoProperties": {
94+
"assetType": "protocol",
95+
"protocolProperties": {
96+
"type": "other"
97+
}
98+
},
99+
"name": "ProtocolPropertiesType: QUIC",
100+
"type": "cryptographic-asset"
101+
},
36102
{
37103
"bom-ref": "dummy-PPT:SSH",
38104
"cryptoProperties": {
@@ -90,6 +156,18 @@
90156
}
91157
],
92158
"dependencies": [
159+
{
160+
"ref": "dummy-PPT:DTLS"
161+
},
162+
{
163+
"ref": "dummy-PPT:EAP_AKA"
164+
},
165+
{
166+
"ref": "dummy-PPT:EAP_AKA_PRIME"
167+
},
168+
{
169+
"ref": "dummy-PPT:FIVEG_AKA"
170+
},
93171
{
94172
"ref": "dummy-PPT:IKE"
95173
},
@@ -99,6 +177,12 @@
99177
{
100178
"ref": "dummy-PPT:OTHER"
101179
},
180+
{
181+
"ref": "dummy-PPT:PRINS"
182+
},
183+
{
184+
"ref": "dummy-PPT:QUIC"
185+
},
102186
{
103187
"ref": "dummy-PPT:SSH"
104188
},

tests/_data/snapshots/enum_ProtocolPropertiesType-1.6.xml.bin

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,42 @@
44
<timestamp>2023-01-07T13:44:32.312678+00:00</timestamp>
55
</metadata>
66
<components>
7+
<component type="cryptographic-asset" bom-ref="dummy-PPT:DTLS">
8+
<name>ProtocolPropertiesType: DTLS</name>
9+
<cryptoProperties>
10+
<assetType>protocol</assetType>
11+
<protocolProperties>
12+
<type>other</type>
13+
</protocolProperties>
14+
</cryptoProperties>
15+
</component>
16+
<component type="cryptographic-asset" bom-ref="dummy-PPT:EAP_AKA">
17+
<name>ProtocolPropertiesType: EAP_AKA</name>
18+
<cryptoProperties>
19+
<assetType>protocol</assetType>
20+
<protocolProperties>
21+
<type>other</type>
22+
</protocolProperties>
23+
</cryptoProperties>
24+
</component>
25+
<component type="cryptographic-asset" bom-ref="dummy-PPT:EAP_AKA_PRIME">
26+
<name>ProtocolPropertiesType: EAP_AKA_PRIME</name>
27+
<cryptoProperties>
28+
<assetType>protocol</assetType>
29+
<protocolProperties>
30+
<type>other</type>
31+
</protocolProperties>
32+
</cryptoProperties>
33+
</component>
34+
<component type="cryptographic-asset" bom-ref="dummy-PPT:FIVEG_AKA">
35+
<name>ProtocolPropertiesType: FIVEG_AKA</name>
36+
<cryptoProperties>
37+
<assetType>protocol</assetType>
38+
<protocolProperties>
39+
<type>other</type>
40+
</protocolProperties>
41+
</cryptoProperties>
42+
</component>
743
<component type="cryptographic-asset" bom-ref="dummy-PPT:IKE">
844
<name>ProtocolPropertiesType: IKE</name>
945
<cryptoProperties>
@@ -31,6 +67,24 @@
3167
</protocolProperties>
3268
</cryptoProperties>
3369
</component>
70+
<component type="cryptographic-asset" bom-ref="dummy-PPT:PRINS">
71+
<name>ProtocolPropertiesType: PRINS</name>
72+
<cryptoProperties>
73+
<assetType>protocol</assetType>
74+
<protocolProperties>
75+
<type>other</type>
76+
</protocolProperties>
77+
</cryptoProperties>
78+
</component>
79+
<component type="cryptographic-asset" bom-ref="dummy-PPT:QUIC">
80+
<name>ProtocolPropertiesType: QUIC</name>
81+
<cryptoProperties>
82+
<assetType>protocol</assetType>
83+
<protocolProperties>
84+
<type>other</type>
85+
</protocolProperties>
86+
</cryptoProperties>
87+
</component>
3488
<component type="cryptographic-asset" bom-ref="dummy-PPT:SSH">
3589
<name>ProtocolPropertiesType: SSH</name>
3690
<cryptoProperties>
@@ -78,9 +132,15 @@
78132
</component>
79133
</components>
80134
<dependencies>
135+
<dependency ref="dummy-PPT:DTLS"/>
136+
<dependency ref="dummy-PPT:EAP_AKA"/>
137+
<dependency ref="dummy-PPT:EAP_AKA_PRIME"/>
138+
<dependency ref="dummy-PPT:FIVEG_AKA"/>
81139
<dependency ref="dummy-PPT:IKE"/>
82140
<dependency ref="dummy-PPT:IPSEC"/>
83141
<dependency ref="dummy-PPT:OTHER"/>
142+
<dependency ref="dummy-PPT:PRINS"/>
143+
<dependency ref="dummy-PPT:QUIC"/>
84144
<dependency ref="dummy-PPT:SSH"/>
85145
<dependency ref="dummy-PPT:SSTP"/>
86146
<dependency ref="dummy-PPT:TLS"/>

0 commit comments

Comments
 (0)