feat(crypto): CBOM model metadata - #1016
Conversation
Certificate serial numbers are needed to identify issued certificates unambiguously in CycloneDX 1.7 CBOMs. Gate the value to the 1.7 serialization view, place it in schema order for XML, and include it in deterministic comparison and round-trip coverage. Refs: CycloneDX 1.7 `cryptoProperties.certificateProperties.serialNumber`. Signed-off-by: Quentin Kaiser <quentin.kaiser@onekey.com>
Consumers need the preferred CycloneDX 1.7 representation while older documents still rely on the deprecated certificate extension field. Store and serialize both values independently, gate the preferred value to 1.7, and retain the legacy value during downgrade and round-trip operations. Refs: CycloneDX 1.7 `cryptoProperties.certificateProperties.certificateFileExtension`. Signed-off-by: Quentin Kaiser <quentin.kaiser@onekey.com>
CBOM consumers need stable digests for certificates and related cryptographic material without conflating those digests with signatures. Reuse the existing hash model for JSON and XML mappings, gate both properties to 1.7, and include them in deterministic comparison and schema-valid round trips. Refs: CycloneDX 1.7 certificate and related-material `fingerprint` properties. Signed-off-by: Quentin Kaiser <quentin.kaiser@onekey.com>
Certificate inventories need machine-readable lifecycle status while still permitting organization-specific states. Model predefined and custom variants as a discriminated union, store them deterministically, and select the concrete variant from its JSON or XML shape during deserialization. Refs: CycloneDX 1.7 `cryptoProperties.certificateProperties.certificateState`. Signed-off-by: Quentin Kaiser <quentin.kaiser@onekey.com>
Certificate lifecycle analysis depends on distinct issuance, operation, retirement, and destruction events rather than validity bounds alone. Map each timestamp through the existing date-time serializer, gate them to 1.7, preserve schema ordering, and include them in equality, hashing, and round-trip coverage. Refs: CycloneDX 1.7 certificate lifecycle date properties. Signed-off-by: Quentin Kaiser <quentin.kaiser@onekey.com>
X.509 inventories need standardized extension names and vendor-defined extensions without collapsing their distinct shapes into unstructured strings. Model common and custom variants as a discriminated union, derive common names from the 1.7 schema, and preserve concrete variants across deterministic JSON and XML round trips. Refs: CycloneDX 1.7 `cryptoProperties.certificateProperties.certificateExtensions`. Signed-off-by: Quentin Kaiser <quentin.kaiser@onekey.com>
Deprecated direct references cannot describe all relationships between certificates, related material, algorithms, and keys. Use reusable typed references in deterministic collections, gate them to 1.7, and retain every deprecated reference unchanged for compatibility with existing 1.6 and 1.7 consumers. Refs: CycloneDX 1.7 `relatedCryptographicAssets`. Signed-off-by: Quentin Kaiser <quentin.kaiser@onekey.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 126 |
| Duplication | 8 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Documentation build overview
|
CAOShurong
left a comment
There was a problem hiding this comment.
Thanks for the thorough 1.7 coverage. I found one remaining protocol-level round-trip gap on 546d0b49 (AI-assisted review; reproduced locally).
ProtocolProperties still models only the deprecated cryptoRefArray; the 1.7 JSON/XML schemas also define protocolProperties.relatedCryptographicAssets. A strict-valid 1.7 BOM containing that preferred field is accepted, but Bom.from_json(...).as_json(view_=SchemaVersion1Dot7) silently drops it:
component["cryptoProperties"]["protocolProperties"] = {
"type": "tls",
"version": "1.3",
"relatedCryptographicAssets": [{"type": "algorithm", "ref": "alg-1"}],
}
assert JsonStrictValidator(SchemaVersion.V1_7).validate_str(json.dumps(bom)) is None
round_trip = json.loads(Bom.from_json(bom).as_json(view_=SchemaVersion1Dot7))
# round_trip protocolProperties is now only {"type": "tls", "version": "1.3"}Could this PR add the same 1.7-gated RelatedCryptographicAsset collection to ProtocolProperties, include it in comparison/hash behavior, and cover JSON/XML round trips while retaining crypto_refs for 1.6 compatibility? I also ran tests.test_model_crypto and tests.test_enums at this head: 722 tests passed.
CycloneDX 1.7 JSON defines relatedCryptographicAssets for protocol properties, but deserialization ignored it and silently dropped preferred typed relationships during round trips. Model the relationships as a deterministic sorted collection, gate serialization to 1.7, and include the collection in equality, ordering, and hashing. Keep the deprecated cryptoRefArray and cryptoRef representation unchanged for both 1.6 and 1.7, and cover version gating plus JSON and XML round trips. The XML model intentionally deviates from the bundled CycloneDX 1.7 XSD: protocol relatedCryptographicAssets are serialized and deserialized even though that XSD omits the field. This provides model parity with the JSON specification and requested round-trip behavior, but strict XML schema validation cannot cover the field until the upstream XSD is corrected. Signed-off-by: Quentin Kaiser <quentin.kaiser@onekey.com>
4323fb8 to
ea7d2ca
Compare
|
@CAOShurong done. Note that:
Maybe worth reporting it to CycloneDX ? |
|
To be a bit more precise: The JSON schema allows
The XSD allows it in:
So the JSON and XML schemas are inconsistent. The model in this branch supports the protocol field for both formats to avoid losing data and maintain model parity, but XML containing that field will not pass strict validation against the current 1.7 XSD. |
|
Confirmed. The official 1.7 JSON schema defines I reported the specification defect as I also checked the updated |
CAOShurong
left a comment
There was a problem hiding this comment.
I re-reviewed the updated head ea7d2ca93198d85fdd34e40b963b7e3bb1c7c7bd. The protocol-level relatedCryptographicAssets round-trip gap from my earlier review is now addressed, including the intended CycloneDX 1.7 behavior and the documented XML-schema limitation tracked in CycloneDX/specification#1018.
Verification I ran on this exact head:
- the related crypto model/JSON/enum test set: 770 tests passed
- the full test suite with
PYTHONUTF8=1: 6,994 tests passed
I also confirmed the upstream schema inconsistency separately and followed it through to the specification issue and an independently tested schema fix path. I did not rerun mypy or flake8 for this approval, so this review does not claim those checks.
OpenAI Codex assisted with the test execution and comparison; I reviewed the implementation and observed outputs and take responsibility for this approval.
|
re: #1016 (review) I think we will wait until the fix is out: |
Description
This branch expands the cryptographic asset model with CycloneDX 1.7 certificate metadata. Certificates can now include serial numbers, preferred file extensions, fingerprints, lifecycle dates, predefined or custom lifecycle states, and standardized or custom X.509 extensions. Related cryptographic material also gains fingerprints, while both certificates and related material can express typed relationships to other cryptographic assets such as algorithms and public keys.
All new fields are version-gated to CycloneDX 1.7 and support deterministic comparison, hashing, and JSON/XML round-tripping. Existing CycloneDX 1.6 fields (including deprecated certificate extensions and direct asset references) remain intact for backward compatibility, with expanded schema-validation, enum, snapshot, and serialization tests covering the new behavior.
AI Tool Disclosure
codexcodex-5.6-sol xhighLLM prompt
RelatedCryptographicAsset(type, ref)andrelated_cryptographic_assetscollections to certificate, related-material, and protocol properties.CertificatePropertieswith:serial_number,certificate_file_extension, andfingerprint: HashType.certificate_states, usingCertificateLifecycleState,CertificatePredefinedState, andCertificateCustomState.certificate_extensions, using common/custom extension models and a schema-backed common-extension-name enum.RelatedCryptoMaterialPropertieswithfingerprintandrelated_cryptographic_assets.signature_algorithm_ref,subject_public_key_ref,certificate_extension,algorithm_ref, andcrypto_refsoperational for both 1.6 and 1.7.Serialization behavior
SchemaVersion1Dot7, with exact CycloneDX JSON names, XML element names, ordering, nested arrays, and date/hash mappings.Test plan
key-wrap, and protocol types.Assumptions
SortedSetstorage.Affirmation