From 534ca59b65b2cb6346697f0826e8fc4075c036b6 Mon Sep 17 00:00:00 2001 From: "Jonas Brand (8R0WNI3)" Date: Tue, 10 Dec 2024 15:23:18 +0100 Subject: [PATCH] Add PoC to display crypto assets --- .../dependencies/ComplianceCells.js | 9 +++ .../dependencies/ComplianceChips.js | 57 +++++++++++++++++++ src/components/dependencies/Component.js | 2 + src/consts.js | 10 ++++ src/ocm/model.js | 8 +++ 5 files changed, 86 insertions(+) diff --git a/src/components/dependencies/ComplianceCells.js b/src/components/dependencies/ComplianceCells.js index ab6a51c..abfe260 100644 --- a/src/components/dependencies/ComplianceCells.js +++ b/src/components/dependencies/ComplianceCells.js @@ -30,6 +30,7 @@ import UnfoldMoreIcon from '@mui/icons-material/UnfoldMore' import { evaluateResourceBranch, GolangChip, + CryptoAssetsChip, IssueChip, } from './ComplianceChips' import { @@ -338,9 +339,11 @@ const ComplianceCell = ({ const structureInfos = complianceFiltered?.filter((d) => d.meta.type === artefactMetadataTypes.STRUCTURE_INFO) const osData = complianceFiltered?.find((d) => d.meta.type === artefactMetadataTypes.OS_IDS) const codecheckData = complianceFiltered?.find((d) => d.meta.type === artefactMetadataTypes.CODECHECKS_AGGREGATED) + const cryptoAssets = complianceFiltered?.filter((d) => d.meta.type === artefactMetadataTypes.CRYPTO_ASSET) const lastBdbaScan = findLastScan(complianceFiltered, datasources.BDBA) const lastMalwareScan = findLastScan(complianceFiltered, datasources.CLAMAV) + const lastCryptoScan = findLastScan(complianceFiltered, datasources.CRYPTO) return @@ -370,6 +373,12 @@ const ComplianceCell = ({ timestamp={lastScanTimestampStr(lastBdbaScan)} /> } + { + artefact.kind === ARTEFACT_KIND.RESOURCE && + } { artefact.kind === ARTEFACT_KIND.RESOURCE && { + if (!cryptoAssets?.length > 0) return null + + const cryptoLibraries = cryptoAssets.filter((cryptoAsset) => { + return cryptoAsset.data.asset_type === CRYPTO_ASSET_TYPES.LIBRARY + }).map((cryptoAsset) => cryptoAsset.data.properties).sort((left, right) => { + return left.name === right.name + ? left.version.localeCompare(right.version) + : left.name.localeCompare(right.name) + }) + + return + + { + cryptoLibraries.map((cryptoLibrary) => `${cryptoLibrary.name}:${cryptoLibrary.version}\n`) + } + + + + { + timestamp + } + + + } + > + + + + +} +CryptoAssetsChip.displayName = 'CryptoAssetsChip' +CryptoAssetsChip.propTypes = { + cryptoAssets: PropTypes.arrayOf(PropTypes.object), + timestamp: PropTypes.string, +} + + const IssueChip = ({ ocmNodes, component, @@ -384,6 +440,7 @@ IssueChip.propTypes = { export { ComponentChip, GolangChip, + CryptoAssetsChip, IssueChip, evaluateResourceBranch, } diff --git a/src/components/dependencies/Component.js b/src/components/dependencies/Component.js index 31b804d..d2188c9 100644 --- a/src/components/dependencies/Component.js +++ b/src/components/dependencies/Component.js @@ -678,12 +678,14 @@ const Artefacts = ({ artefactMetadataTypes.CODECHECKS_AGGREGATED, artefactMetadataTypes.OS_IDS, artefactMetadataTypes.STRUCTURE_INFO, + artefactMetadataTypes.CRYPTO_ASSET, ] }, [ artefactMetadataTypes.ARTEFACT_SCAN_INFO, artefactMetadataTypes.CODECHECKS_AGGREGATED, artefactMetadataTypes.OS_IDS, artefactMetadataTypes.STRUCTURE_INFO, + artefactMetadataTypes.CRYPTO_ASSET, ]) const params = React.useMemo(() => { diff --git a/src/consts.js b/src/consts.js index 5a84048..e2199d0 100644 --- a/src/consts.js +++ b/src/consts.js @@ -232,3 +232,13 @@ export const PACKAGES = { GOLANG: 'golang-runtime', } Object.freeze(PACKAGES) + + +export const CRYPTO_ASSET_TYPES = { + ALGORITHM: 'algorithm', + CERTIFICATE: 'certificate', + LIBRARY: 'library', + PROTOCOL: 'protocol', + RELATED_CRYPTO_MATERIAL: 'related-crypto-material', +} +Object.freeze(CRYPTO_ASSET_TYPES) diff --git a/src/ocm/model.js b/src/ocm/model.js index d154910..517bb8c 100644 --- a/src/ocm/model.js +++ b/src/ocm/model.js @@ -75,6 +75,7 @@ const artefactMetadataTypes = { MALWARE: 'malware', OS_IDS: 'os_ids', CODECHECKS_AGGREGATED: 'codechecks/aggregated', + CRYPTO_ASSET: 'crypto_asset', RESCORINGS: 'rescorings', } Object.freeze(artefactMetadataTypes) @@ -84,6 +85,7 @@ const datasources = { BDBA: 'bdba', CLAMAV: 'clamav', CC_UTILS: 'cc-utils', + CRYPTO: 'crypto', } Object.freeze(datasources) @@ -294,6 +296,12 @@ const knownMetadataTypes = [ SpecificTypeHandler: MultilineTextViewer, Icon: CoronavirusIcon }, + { + name: 'crypto_asset', + friendlyName: 'Crypto Asset', + SpecificTypeHandler: MultilineTextViewer, + Icon: ArticleIcon, + }, ]