Skip to content

Commit

Permalink
Add PoC to display crypto assets
Browse files Browse the repository at this point in the history
  • Loading branch information
8R0WNI3 committed Dec 11, 2024
1 parent 466dc09 commit 534ca59
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/components/dependencies/ComplianceCells.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import UnfoldMoreIcon from '@mui/icons-material/UnfoldMore'
import {
evaluateResourceBranch,
GolangChip,
CryptoAssetsChip,
IssueChip,
} from './ComplianceChips'
import {
Expand Down Expand Up @@ -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 <TableCell>
<Grid container direction='row-reverse' spacing={1}>
Expand Down Expand Up @@ -370,6 +373,12 @@ const ComplianceCell = ({
timestamp={lastScanTimestampStr(lastBdbaScan)}
/>
}
{
artefact.kind === ARTEFACT_KIND.RESOURCE && <CryptoAssetsChip
cryptoAssets={cryptoAssets}
timestamp={lastScanTimestampStr(lastCryptoScan)}
/>
}
{
artefact.kind === ARTEFACT_KIND.RESOURCE && <MalwareFindingCell
ocmNodes={ocmNodes}
Expand Down
57 changes: 57 additions & 0 deletions src/components/dependencies/ComplianceChips.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { parseRelaxedSemver } from '../../osUtil'
import { findSeverityCfgByName } from '../../util'
import {
COMPLIANCE_TOOLS,
CRYPTO_ASSET_TYPES,
REPORTING_MINIMUM_SEVERITY,
SEVERITIES,
} from './../../consts'
Expand Down Expand Up @@ -308,6 +309,61 @@ GolangChip.propTypes = {
timestamp: PropTypes.string,
}


const CryptoAssetsChip = ({
cryptoAssets,
timestamp,
}) => {
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 <Tooltip
title={
<Stack direction='column' spacing={1}>
<Typography
variant='inherit'
sx={{
whiteSpace: 'pre-wrap',
maxWidth: 'none',
}}
>
{
cryptoLibraries.map((cryptoLibrary) => `${cryptoLibrary.name}:${cryptoLibrary.version}\n`)
}
</Typography>
<Divider/>
<Typography variant='inherit'>
{
timestamp
}
</Typography>
</Stack>
}
>
<Grid item>
<Chip
label='Crypto'
variant='outlined'
size='small'
color='default'
/>
</Grid>
</Tooltip>
}
CryptoAssetsChip.displayName = 'CryptoAssetsChip'
CryptoAssetsChip.propTypes = {
cryptoAssets: PropTypes.arrayOf(PropTypes.object),
timestamp: PropTypes.string,
}


const IssueChip = ({
ocmNodes,
component,
Expand Down Expand Up @@ -384,6 +440,7 @@ IssueChip.propTypes = {
export {
ComponentChip,
GolangChip,
CryptoAssetsChip,
IssueChip,
evaluateResourceBranch,
}
2 changes: 2 additions & 0 deletions src/components/dependencies/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
10 changes: 10 additions & 0 deletions src/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 8 additions & 0 deletions src/ocm/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -84,6 +85,7 @@ const datasources = {
BDBA: 'bdba',
CLAMAV: 'clamav',
CC_UTILS: 'cc-utils',
CRYPTO: 'crypto',
}
Object.freeze(datasources)

Expand Down Expand Up @@ -294,6 +296,12 @@ const knownMetadataTypes = [
SpecificTypeHandler: MultilineTextViewer,
Icon: CoronavirusIcon
},
{
name: 'crypto_asset',
friendlyName: 'Crypto Asset',
SpecificTypeHandler: MultilineTextViewer,
Icon: ArticleIcon,
},
]


Expand Down

0 comments on commit 534ca59

Please sign in to comment.