Documentation
¶
Overview ¶
Package normalize provides utilities for normalizing package identifiers. This file handles mapping binary package names to their source package names for Linux distributions (Debian, Alpine), enabling vulnerability matching against security advisories that reference source packages.
Index ¶
- Constants
- Variables
- func ArtifactPurl(scanner string, assetName string) string
- func BeautifyPURL(pURL string) (string, error)
- func CheckVersion(exactVersion, introduced, fixed *string, ...) (bool, error)
- func ConvertToSemver(originalVersion string) (string, error)
- func DeepSort(el any) any
- func FixFixedVersion(purl string, fixedVersion *string) *string
- func GetComponentID(component cdx.Component) string
- func MapCDXToEventType(a *cdx.VulnerabilityAnalysis) string
- func MapCDXToVulnStatus(a *cdx.VulnerabilityAnalysis) string
- func PackageToPurl(ecosystem, packageName string) string
- func PurlToEcosystem(purlType string) string
- func Purlify(artifactName string, assetVersionName string) string
- func QualifiersMapToString(qualifiers map[string]string) string
- func RemoveOriginTypePrefixIfExists(origin string) (nodeType, string)
- func SemverCompare(v1, v2 string) int
- func SemverSort(versions []string)
- func SortStringsSlice(slice []string) []string
- func StructuralCompareCdxBoms(a, b *cdx.BOM) error
- func ToPurlWithoutVersion(purl packageurl.PackageURL) string
- type CdxBom
- func (bom *CdxBom) AddChild(parent *TreeNode[cdxBomNode], child *TreeNode[cdxBomNode])
- func (bom *CdxBom) AddDirectChildWhichInheritsChildren(parent cdxBomNode, child cdxBomNode)
- func (bom *CdxBom) AddSourceChildrenToTarget(source *TreeNode[cdxBomNode], target *TreeNode[cdxBomNode])
- func (bom *CdxBom) CalculateDepth() map[string]int
- func (bom *CdxBom) CountParentTypes() map[string]map[nodeType]int
- func (bom *CdxBom) EjectMinimalDependencyTree() *minimalTreeNode
- func (bom *CdxBom) EjectSBOM(assetID *uuid.UUID) *cdx.BOM
- func (bom *CdxBom) EjectVex(assetID *uuid.UUID) *cdx.BOM
- func (bom *CdxBom) GetAllParentNodes(nodeID string) []string
- func (bom *CdxBom) GetComponents() *[]cdx.Component
- func (bom *CdxBom) GetComponentsIncludingFakeNodes() *[]cdx.Component
- func (bom *CdxBom) GetCsafRootPurls() []string
- func (bom *CdxBom) GetDependencies() *[]cdx.Dependency
- func (bom *CdxBom) GetDependenciesIncludingFakeNodes() *[]cdx.Dependency
- func (bom *CdxBom) GetDependenciesOfComponent(componentRef string) *cdx.Dependency
- func (bom *CdxBom) GetDirectDependencies() *[]cdx.Dependency
- func (bom *CdxBom) GetInformationSourceNodes() []*TreeNode[cdxBomNode]
- func (bom *CdxBom) GetInformationSources() []string
- func (bom *CdxBom) GetMetadata() *cdx.Metadata
- func (bom *CdxBom) GetTransitiveDependencies() *[]cdx.Dependency
- func (bom *CdxBom) GetVulnerabilities() *[]cdx.Vulnerability
- func (bom *CdxBom) InformationFromVexOrMultipleSBOMs() []string
- func (bom *CdxBom) ReplaceOrAddInformationSourceNode(subTree *TreeNode[cdxBomNode])
- func (bom *CdxBom) ReplaceRoot(newRoot cdxBomNode)
- type CdxComponent
- type Node
- type PurlMatchContext
- type Tree
- func (tree *Tree[Element]) AddChild(parent *TreeNode[Element], child *TreeNode[Element])
- func (tree *Tree[Element]) AddDirectChildWhichInheritsChildren(parent Element, child Element)
- func (tree *Tree[Element]) AddSourceChildrenToTarget(source *TreeNode[Element], target *TreeNode[Element])
- func (tree *Tree[Data]) Reachable(id string) bool
- func (tree *Tree[Data]) RenderToMermaid() string
- func (tree *Tree[Element]) ReplaceNode(old *TreeNode[Element], new *TreeNode[Element])
- func (tree *Tree[Element]) ReplaceRoot(node Element)
- func (tree *Tree[Element]) ReplaceSubtree(other *TreeNode[Element])
- func (tree *Tree[Element]) Visitable() ([]string, []string)
- type TreeNode
- type VersionInterpretationType
Constants ¶
const ( NodeTypeComponent nodeType = "component" NodeTypeSbomInformationSource nodeType = "sbom" NodeTypeVexInformationSource nodeType = "vex" NodeTypeCSAFInformationSource nodeType = "csaf" NodeTypeUnknown nodeType = "unknown" )
Variables ¶
var PURLEcosystems = map[string]string{
"Alpine": "apk",
"crates.io": "cargo",
"Debian": "deb",
"Go": "golang",
"Hackage": "hackage",
"Hex": "hex",
"Maven": "maven",
"npm": "npm",
"NuGet": "nuget",
"OSS-Fuzz": "generic",
"Packagist": "composer",
"Pub": "pub",
"PyPI": "pypi",
"RubyGems": "gem",
}
PURL conversion utilities
var ValidSemverRegex = regexp.MustCompile(`^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$`)
Regex for validating a correct semver.
Functions ¶
func ArtifactPurl ¶
func BeautifyPURL ¶
function to make purl look more visually appealing
func CheckVersion ¶
func ConvertToSemver ¶
ConvertToSemver converts various version formats to semantic versioning format. It handles: - Epoch prefixes (e.g., "2:1.2.3" -> "1.2.3") - "v" prefixes (e.g., "v1.2.3" -> "1.2.3") - Pre-release identifiers with "-" (e.g., "1.2.3-rc1") - Build metadata with "+" (e.g., "1.2.3+build1") - Tilde versions "~" (e.g., "1.2.3~rc1" -> "1.2.3-rc1") - Missing version segments (e.g., "1.2" -> "1.2.0")
Returns an error if: - Version contains invalid characters (only 0-9 and . allowed in version part) - Version has more than 3 numeric segments
func DeepSort ¶
this is a deep sort function that sorts all maps and slices recursively it is REALLY expensive, so use it wisely! it treats any arrays as sets and sorts them by their canonical JSON representation
func FixFixedVersion ¶
func GetComponentID ¶
func MapCDXToEventType ¶
func MapCDXToEventType(a *cdx.VulnerabilityAnalysis) string
func MapCDXToVulnStatus ¶
func MapCDXToVulnStatus(a *cdx.VulnerabilityAnalysis) string
map CycloneDX Analysis State / Response to internal status strings used by CreateVulnEventAndApply
func PackageToPurl ¶
func PurlToEcosystem ¶
func QualifiersMapToString ¶
func SemverCompare ¶
func SemverSort ¶
func SemverSort(versions []string)
func SortStringsSlice ¶
func ToPurlWithoutVersion ¶
func ToPurlWithoutVersion(purl packageurl.PackageURL) string
Types ¶
type CdxBom ¶
type CdxBom struct {
// contains filtered or unexported fields
}
func FromCdxBom ¶
func FromComponents ¶
func FromComponents(assetSlug, artifactName, assetVersionName, assetVersionSlug, projectSlug, orgSlug, frontendURL string, components []CdxComponent, licenseOverwrites map[string]string) *CdxBom
func FromVulnerabilities ¶
func FromVulnerabilities(assetSlug, artifactName, assetVersionName, assetVersionSlug, projectSlug, orgSlug, frontendURL string, vulns []cdx.Vulnerability) *CdxBom
func (*CdxBom) AddDirectChildWhichInheritsChildren ¶
func (bom *CdxBom) AddDirectChildWhichInheritsChildren(parent cdxBomNode, child cdxBomNode)
func (*CdxBom) AddSourceChildrenToTarget ¶
func (*CdxBom) CalculateDepth ¶
func (*CdxBom) CountParentTypes ¶
func (*CdxBom) EjectMinimalDependencyTree ¶
func (bom *CdxBom) EjectMinimalDependencyTree() *minimalTreeNode
func (*CdxBom) GetAllParentNodes ¶
func (*CdxBom) GetComponents ¶
func (*CdxBom) GetComponentsIncludingFakeNodes ¶
func (*CdxBom) GetCsafRootPurls ¶
this returns direct csaf children of csaf information source nodes since csaf does not scope transitive dependencies but we might be able to redistribute found cves to the subtree reachable from those purls.
func (*CdxBom) GetDependencies ¶
func (bom *CdxBom) GetDependencies() *[]cdx.Dependency
func (*CdxBom) GetDependenciesIncludingFakeNodes ¶
func (bom *CdxBom) GetDependenciesIncludingFakeNodes() *[]cdx.Dependency
func (*CdxBom) GetDependenciesOfComponent ¶
func (bom *CdxBom) GetDependenciesOfComponent(componentRef string) *cdx.Dependency
func (*CdxBom) GetDirectDependencies ¶
func (bom *CdxBom) GetDirectDependencies() *[]cdx.Dependency
func (*CdxBom) GetInformationSourceNodes ¶
func (*CdxBom) GetInformationSources ¶
func (*CdxBom) GetMetadata ¶
func (*CdxBom) GetTransitiveDependencies ¶
func (bom *CdxBom) GetTransitiveDependencies() *[]cdx.Dependency
func (*CdxBom) GetVulnerabilities ¶
func (bom *CdxBom) GetVulnerabilities() *[]cdx.Vulnerability
func (*CdxBom) InformationFromVexOrMultipleSBOMs ¶
func (*CdxBom) ReplaceOrAddInformationSourceNode ¶
func (*CdxBom) ReplaceRoot ¶
func (bom *CdxBom) ReplaceRoot(newRoot cdxBomNode)
type CdxComponent ¶
type PurlMatchContext ¶
type PurlMatchContext struct {
SearchPurl string
NormalizedVersion string
HowToInterpretVersionString VersionInterpretationType
Qualifiers packageurl.Qualifiers
Namespace string
}
PurlMatchContext holds the parsed purl information for matching
func ParsePurlForMatching ¶
func ParsePurlForMatching(purl packageurl.PackageURL) *PurlMatchContext
ParsePurlForMatching parses a purl and version into a context for database matching
type Tree ¶
type Tree[Element Node] struct { Root *TreeNode[Element] `json:"root"` // contains filtered or unexported fields }
func BuildDependencyTree ¶
func (*Tree[Element]) AddDirectChildWhichInheritsChildren ¶
func (tree *Tree[Element]) AddDirectChildWhichInheritsChildren(parent Element, child Element)
func (*Tree[Element]) AddSourceChildrenToTarget ¶
func (*Tree[Data]) RenderToMermaid ¶
func (*Tree[Element]) ReplaceNode ¶
func (*Tree[Element]) ReplaceRoot ¶
func (tree *Tree[Element]) ReplaceRoot(node Element)
func (*Tree[Element]) ReplaceSubtree ¶
type VersionInterpretationType ¶
type VersionInterpretationType string
const ( ExactVersionString VersionInterpretationType = "exact" SemanticVersionString VersionInterpretationType = "semver_range" EmptyVersion VersionInterpretationType = "empty_version" EcosystemSpecificVersion VersionInterpretationType = "ecosystem_specific" )