Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
565 changes: 552 additions & 13 deletions cyclonedx/model/crypto.py

Large diffs are not rendered by default.

57 changes: 51 additions & 6 deletions tests/_data/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
Encoding,
ExternalReference,
ExternalReferenceType,
HashAlgorithm,
HashType,
Note,
NoteText,
Expand Down Expand Up @@ -70,6 +71,12 @@
from cyclonedx.model.contact import OrganizationalContact, OrganizationalEntity, PostalAddress
from cyclonedx.model.crypto import (
AlgorithmProperties,
CertificateCommonExtension,
CertificateCommonExtensionName,
CertificateCustomExtension,
CertificateCustomState,
CertificateLifecycleState,
CertificatePredefinedState,
CertificateProperties,
CryptoAssetType,
CryptoCertificationLevel,
Expand All @@ -83,6 +90,7 @@
ProtocolProperties,
ProtocolPropertiesCipherSuite,
ProtocolPropertiesType,
RelatedCryptographicAsset,
RelatedCryptoMaterialProperties,
RelatedCryptoMaterialSecuredBy,
RelatedCryptoMaterialState,
Expand Down Expand Up @@ -197,16 +205,49 @@ def get_crypto_properties_certificate() -> CryptoProperties:
return CryptoProperties(
asset_type=CryptoAssetType.CERTIFICATE,
certificate_properties=CertificateProperties(
serial_number='3942447fac867ae5cdb3229b658f4d48',
subject_name='cyclonedx.org',
issuer_name='Cloudflare Inc ECC CA-3',
not_valid_before=datetime(year=2023, month=5, day=19, hour=1, minute=0, second=0, microsecond=0,
tzinfo=timezone.utc),
not_valid_after=datetime(year=2024, month=5, day=19, hour=0, minute=59, second=59, microsecond=999999,
tzinfo=timezone.utc),
signature_algorithm_ref=None,
subject_public_key_ref=None,
signature_algorithm_ref=BomRef('signature-algorithm'),
subject_public_key_ref=BomRef('subject-public-key'),
certificate_format='pem',
certificate_extension='csr'
certificate_extension='csr',
certificate_file_extension='pem',
fingerprint=HashType(alg=HashAlgorithm.SHA_256, content='a' * 64),
certificate_states=[
CertificatePredefinedState(
state=CertificateLifecycleState.ACTIVE,
reason='certificate is in use',
),
CertificateCustomState(
name='pending-rotation',
description='The certificate is waiting to be rotated.',
reason='scheduled maintenance',
),
],
creation_date=datetime(2023, 5, 18, 12, 0, tzinfo=timezone.utc),
activation_date=datetime(2023, 5, 19, 1, 0, tzinfo=timezone.utc),
deactivation_date=datetime(2024, 5, 18, 12, 0, tzinfo=timezone.utc),
revocation_date=datetime(2024, 5, 18, 13, 0, tzinfo=timezone.utc),
destruction_date=datetime(2024, 5, 18, 14, 0, tzinfo=timezone.utc),
certificate_extensions=[
CertificateCommonExtension(
common_extension_name=CertificateCommonExtensionName.KEY_USAGE,
common_extension_value='digitalSignature',
),
CertificateCustomExtension(
custom_extension_name='1.2.3.4.5',
custom_extension_value='custom-value',
),
],
related_cryptographic_assets=[
RelatedCryptographicAsset(type='algorithm', ref=BomRef('signature-algorithm')),
RelatedCryptographicAsset(type='publicKey', ref=BomRef('subject-public-key')),
],
),
oid='an-oid-here'
)
Expand Down Expand Up @@ -268,7 +309,7 @@ def get_crypto_properties_related_material() -> CryptoProperties:
type=RelatedCryptoMaterialType.DIGEST,
id='some-identifier',
state=RelatedCryptoMaterialState.ACTIVE,
algorithm_ref=None,
algorithm_ref=BomRef('material-algorithm'),
creation_date=datetime(year=2023, month=5, day=19, hour=1, minute=0, second=0, microsecond=0,
tzinfo=timezone.utc),
activation_date=datetime(year=2023, month=5, day=19, hour=1, minute=0, second=0, microsecond=0,
Expand All @@ -281,8 +322,12 @@ def get_crypto_properties_related_material() -> CryptoProperties:
format='a-format',
secured_by=RelatedCryptoMaterialSecuredBy(
mechanism='hard-work',
algorithm_ref=None
)
algorithm_ref=BomRef('securing-algorithm'),
),
fingerprint=HashType(alg=HashAlgorithm.SHA_256, content='b' * 64),
related_cryptographic_assets=[
RelatedCryptographicAsset(type='algorithm', ref=BomRef('material-algorithm')),
],
),
oid='an-oid-here'
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
{
"components": [
{
"bom-ref": "dummy-CCEN:AUTHORITY_INFORMATION_ACCESS",
"cryptoProperties": {
"assetType": "certificate",
"certificateProperties": {
"certificateExtensions": [
{
"commonExtensionName": "authorityInformationAccess",
"commonExtensionValue": "authorityInformationAccess"
}
]
}
},
"name": "CertificateCommonExtensionName: AUTHORITY_INFORMATION_ACCESS",
"type": "cryptographic-asset"
},
{
"bom-ref": "dummy-CCEN:AUTHORITY_KEY_IDENTIFIER",
"cryptoProperties": {
"assetType": "certificate",
"certificateProperties": {
"certificateExtensions": [
{
"commonExtensionName": "authorityKeyIdentifier",
"commonExtensionValue": "authorityKeyIdentifier"
}
]
}
},
"name": "CertificateCommonExtensionName: AUTHORITY_KEY_IDENTIFIER",
"type": "cryptographic-asset"
},
{
"bom-ref": "dummy-CCEN:BASIC_CONSTRAINTS",
"cryptoProperties": {
"assetType": "certificate",
"certificateProperties": {
"certificateExtensions": [
{
"commonExtensionName": "basicConstraints",
"commonExtensionValue": "basicConstraints"
}
]
}
},
"name": "CertificateCommonExtensionName: BASIC_CONSTRAINTS",
"type": "cryptographic-asset"
},
{
"bom-ref": "dummy-CCEN:CERTIFICATE_POLICIES",
"cryptoProperties": {
"assetType": "certificate",
"certificateProperties": {
"certificateExtensions": [
{
"commonExtensionName": "certificatePolicies",
"commonExtensionValue": "certificatePolicies"
}
]
}
},
"name": "CertificateCommonExtensionName: CERTIFICATE_POLICIES",
"type": "cryptographic-asset"
},
{
"bom-ref": "dummy-CCEN:CRL_DISTRIBUTION_POINTS",
"cryptoProperties": {
"assetType": "certificate",
"certificateProperties": {
"certificateExtensions": [
{
"commonExtensionName": "crlDistributionPoints",
"commonExtensionValue": "crlDistributionPoints"
}
]
}
},
"name": "CertificateCommonExtensionName: CRL_DISTRIBUTION_POINTS",
"type": "cryptographic-asset"
},
{
"bom-ref": "dummy-CCEN:EXTENDED_KEY_USAGE",
"cryptoProperties": {
"assetType": "certificate",
"certificateProperties": {
"certificateExtensions": [
{
"commonExtensionName": "extendedKeyUsage",
"commonExtensionValue": "extendedKeyUsage"
}
]
}
},
"name": "CertificateCommonExtensionName: EXTENDED_KEY_USAGE",
"type": "cryptographic-asset"
},
{
"bom-ref": "dummy-CCEN:KEY_USAGE",
"cryptoProperties": {
"assetType": "certificate",
"certificateProperties": {
"certificateExtensions": [
{
"commonExtensionName": "keyUsage",
"commonExtensionValue": "keyUsage"
}
]
}
},
"name": "CertificateCommonExtensionName: KEY_USAGE",
"type": "cryptographic-asset"
},
{
"bom-ref": "dummy-CCEN:SIGNED_CERTIFICATE_TIMESTAMP",
"cryptoProperties": {
"assetType": "certificate",
"certificateProperties": {
"certificateExtensions": [
{
"commonExtensionName": "signedCertificateTimestamp",
"commonExtensionValue": "signedCertificateTimestamp"
}
]
}
},
"name": "CertificateCommonExtensionName: SIGNED_CERTIFICATE_TIMESTAMP",
"type": "cryptographic-asset"
},
{
"bom-ref": "dummy-CCEN:SUBJECT_ALTERNATIVE_NAME",
"cryptoProperties": {
"assetType": "certificate",
"certificateProperties": {
"certificateExtensions": [
{
"commonExtensionName": "subjectAlternativeName",
"commonExtensionValue": "subjectAlternativeName"
}
]
}
},
"name": "CertificateCommonExtensionName: SUBJECT_ALTERNATIVE_NAME",
"type": "cryptographic-asset"
},
{
"bom-ref": "dummy-CCEN:SUBJECT_KEY_IDENTIFIER",
"cryptoProperties": {
"assetType": "certificate",
"certificateProperties": {
"certificateExtensions": [
{
"commonExtensionName": "subjectKeyIdentifier",
"commonExtensionValue": "subjectKeyIdentifier"
}
]
}
},
"name": "CertificateCommonExtensionName: SUBJECT_KEY_IDENTIFIER",
"type": "cryptographic-asset"
}
],
"dependencies": [
{
"ref": "dummy-CCEN:AUTHORITY_INFORMATION_ACCESS"
},
{
"ref": "dummy-CCEN:AUTHORITY_KEY_IDENTIFIER"
},
{
"ref": "dummy-CCEN:BASIC_CONSTRAINTS"
},
{
"ref": "dummy-CCEN:CERTIFICATE_POLICIES"
},
{
"ref": "dummy-CCEN:CRL_DISTRIBUTION_POINTS"
},
{
"ref": "dummy-CCEN:EXTENDED_KEY_USAGE"
},
{
"ref": "dummy-CCEN:KEY_USAGE"
},
{
"ref": "dummy-CCEN:SIGNED_CERTIFICATE_TIMESTAMP"
},
{
"ref": "dummy-CCEN:SUBJECT_ALTERNATIVE_NAME"
},
{
"ref": "dummy-CCEN:SUBJECT_KEY_IDENTIFIER"
}
],
"metadata": {
"timestamp": "2023-01-07T13:44:32.312678+00:00"
},
"properties": [
{
"name": "key1",
"value": "val1"
},
{
"name": "key2",
"value": "val2"
}
],
"serialNumber": "urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac",
"version": 1,
"$schema": "http://cyclonedx.org/schema/bom-1.7.schema.json",
"bomFormat": "CycloneDX",
"specVersion": "1.7"
}
Loading