cbom

package
v4.27.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cbom discovers cryptographic usage in a codebase — in source, config, certificates/keys on disk and declared crypto libraries — and maps it to a CycloneDX Cryptography Bill of Materials, classifying each algorithm for post-quantum posture (quantum-safe | quantum-vulnerable | deprecated | hybrid).

All detection is driven by a declarative catalog (internal/cbom/catalog/*.json) so the rules — algorithm aliases, per-language source patterns, config patterns, crypto-library imports and the per-country approval matrix — can be maintained without code changes. The catalog is embedded in the binary and can be extended or overridden at runtime with --catalog.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Detect

func Detect(opts Options) (cdx.CryptoDetections, error)

Detect runs the enabled passes and returns CycloneDX-ready crypto detections.

func Normalize

func Normalize(s string) string

Normalize folds a cryptographic-algorithm token to a canonical comparison key: lower-cased with every non-alphanumeric character (spaces, '-', '_', '.', '/') removed. This is what makes "SHA256", "Sha256", "sha256" and "SHA_256" all resolve to the same algorithm and be stored under one canonical SPDX name.

Normalize("SHA-256")  == "sha256"
Normalize("Sha_256")  == "sha256"
Normalize("ML-KEM-768") == "mlkem768"

Types

type AlgorithmDef

type AlgorithmDef struct {
	ID                     string              `json:"id"`   // canonical SPDX id (override key)
	Name                   string              `json:"name"` // canonical stored name
	SPDXClass              string              `json:"spdx_class,omitempty"`
	OID                    string              `json:"oid,omitempty"`
	Aliases                []string            `json:"aliases,omitempty"`
	Primitive              string              `json:"primitive,omitempty"` // CycloneDX primitive enum
	ParameterSet           string              `json:"parameter_set,omitempty"`
	Curve                  string              `json:"curve,omitempty"`
	Mode                   string              `json:"mode,omitempty"`    // CycloneDX mode enum
	Padding                string              `json:"padding,omitempty"` // CycloneDX padding enum
	CryptoFunctions        []string            `json:"crypto_functions,omitempty"`
	ClassicalSecurityLevel int                 `json:"classical_security_level,omitempty"`
	NISTQuantumLevel       int                 `json:"nist_quantum_security_level,omitempty"`
	PQCStatus              string              `json:"pqc_status,omitempty"`
	Standards              map[string]string   `json:"standards,omitempty"`
	SourcePatterns         map[string][]string `json:"source_patterns,omitempty"` // language -> patterns
	ConfigPatterns         []string            `json:"config_patterns,omitempty"`
}

AlgorithmDef describes one cryptographic algorithm: how to detect it, its canonical SPDX identity, its CycloneDX algorithmProperties and its PQC posture.

type Catalog

type Catalog struct {
	Version    string         `json:"version"`
	Extractors []ExtractorDef `json:"call_extractors,omitempty"`
	Algorithms []AlgorithmDef `json:"algorithms"`
	Libraries  []LibraryDef   `json:"libraries"`
}

Catalog is the raw (uncompiled) detection catalog.

func DefaultCatalog

func DefaultCatalog() (*Catalog, error)

DefaultCatalog loads and merges the embedded catalog/*.json files.

func LoadCatalog

func LoadCatalog(overridePath string, noBuiltin bool) (*Catalog, error)

LoadCatalog loads the builtin catalog (unless noBuiltin) and merges an optional override file on top (upsert by id).

func (*Catalog) Compile

func (c *Catalog) Compile() (*CompiledCatalog, error)

Compile validates and compiles every pattern and builds the alias index. It is the single validation gate: an invalid regex, duplicate id, or out-of-enum CycloneDX value fails here.

type CompiledAlgorithm

type CompiledAlgorithm struct {
	Def    AlgorithmDef
	Source map[string][]*regexp.Regexp // canonical language -> patterns
	Config []*regexp.Regexp
}

type CompiledCatalog

type CompiledCatalog struct {
	Version    string
	Algorithms []CompiledAlgorithm
	Libraries  []CompiledLibrary
	Extractors []CompiledExtractor
	// contains filtered or unexported fields
}

CompiledCatalog is the catalog with all regexes compiled and the alias index built. It is the single matching surface used by every detection pass.

func (*CompiledCatalog) Lookup

func (c *CompiledCatalog) Lookup(token string) (*CompiledAlgorithm, bool)

Lookup resolves a raw token (e.g. "SHA256", "Sha256", "SHA_256") to its canonical algorithm via the normalized alias index. This is what makes case/separator variants equivalent for detection.

type CompiledExtractor

type CompiledExtractor struct {
	Languages map[string]bool
	Re        *regexp.Regexp
	Role      string
}

type CompiledLibrary

type CompiledLibrary struct {
	Def     LibraryDef
	Imports []*regexp.Regexp
}

type ExtractorDef

type ExtractorDef struct {
	Languages []string `json:"languages,omitempty"` // empty = any file
	Pattern   string   `json:"pattern"`             // one capture group = the token
	Role      string   `json:"role,omitempty"`      // algorithm | transform | jwt
}

ExtractorDef captures an algorithm token from a generic crypto-API call. The captured token is normalized and looked up in the alias index, so arbitrary case/separator variants (sha256, SHA-256, SHA_256, …) resolve to one algorithm.

type LibraryDef

type LibraryDef struct {
	ID             string            `json:"id"`
	Name           string            `json:"name"`
	Provider       string            `json:"provider,omitempty"`
	Languages      []string          `json:"languages,omitempty"`
	PurlNames      map[string]string `json:"purl_names,omitempty"`
	ImportPatterns []string          `json:"import_patterns,omitempty"`
}

LibraryDef describes a cryptographic library / SDK.

type Options

type Options struct {
	Root        string
	MaxDepth    int
	Ignore      []string
	ScanSource  bool
	ScanConfig  bool
	ScanCerts   bool
	ScanDeps    bool
	IncludeHome bool
	Catalog     *CompiledCatalog
	// RespectGitignore prunes .gitignored paths (default off; the cbom command
	// sets it true unless --cbom-include-ignored is passed).
	RespectGitignore bool
}

Options controls a CBOM detection run.

Directories

Path Synopsis
Command cbomgen renders the CBOM detection documentation from the single source of truth: the embedded catalog (internal/cbom/catalog/*.json).
Command cbomgen renders the CBOM detection documentation from the single source of truth: the embedded catalog (internal/cbom/catalog/*.json).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL