cbom

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 15 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 assembles collector findings into a CycloneDX 1.6 CBOM.

It builds on github.com/CycloneDX/cyclonedx-go rather than hand-rolling the document model, and adds what the SDK does not provide: closed-vocabulary enforcement, de-duplication and edge integrity, and deterministic output.

Index

Constants

View Source
const (
	Spec16 = "1.6"
	Spec17 = "1.7"
)

Spec names the CycloneDX versions this program writes.

View Source
const DefaultSpec = Spec17

DefaultSpec is what the programs write unless asked otherwise.

View Source
const PropertyNamespace = "cipherhorizon"

PropertyNamespace prefixes every custom property this program adds, as the CycloneDX property taxonomy asks of non-CycloneDX property names.

View Source
const SpecVersion = cdx.SpecVersion1_6

SpecVersion is the CycloneDX version emitted. 1.7 is a later, opt-in step.

View Source
const UnrecognisedStatus = "unrecognised"

UnrecognisedStatus is the cipherhorizon:identifier-status of an algorithm this program could not name: it is in the document by the identifier it was read with, and nothing more is claimed.

Variables

This section is empty.

Functions

func Build

func Build(assets []collector.CryptoAsset, opts Options) (*cdx.BOM, []string)

Build assembles assets into a BOM. Problems with individual assets never fail the build: the offending asset (or field, or edge) is omitted and reported in the returned warnings, so one bad plugin cannot take down an inventory.

Output is deterministic for a given input: components are sorted by bom-ref, as are all edges.

func CertificateAsset

func CertificateAsset(f CertFacts, emit func(id string) (string, bool), emitAsset func(collector.CryptoAsset) string) (collector.CryptoAsset, *collector.CryptoAsset)

CertificateAsset builds the certificate component and, when the key algorithm can be named, the component for the public key it certifies (with its size), in the shape the standard intends: the certificate's subjectPublicKeyRef references the key, and the key's algorithmRef references its algorithm. emit resolves a catalogue algorithm and emitAsset adds one this document derived itself (a key-size variant such as RSA-2048); both are the caller's, so every algorithm is emitted once per document. The caller sets Evidence and any properties; nothing here says how or where the certificate was found.

func Encode

func Encode(w io.Writer, bom *cdx.BOM, pretty bool) error

Encode writes bom as CycloneDX 1.6 JSON.

It deliberately uses the SDK's plain Encode, not EncodeVersion. As of cyclonedx-go v0.12.0, EncodeVersion's downgrade pass does not know the "cryptographic-asset" component type in ANY spec version, and silently rewrites every crypto component to "application": schema-valid, but no longer a CBOM. Skipping the pass is safe here because Build targets 1.6 natively: vocab.go already omits the 1.7-only crypto fields, and the schema-validation tests would fail on any other 1.7-only field. TestEncodeKeepsCryptographicAssetType guards this; revisit when the SDK is fixed.

func EncodeSpec

func EncodeSpec(w io.Writer, bom *cdx.BOM, spec string, pretty bool) error

EncodeSpec writes bom as CycloneDX JSON of the named version ("1.6" or "1.7"). An unknown version is an error, never a silent default.

func FamilyFor

func FamilyFor(name string) (family string, ok bool)

FamilyFor returns the registry family for a component name: a catalogue ID, or one of the size- or curve-qualified names this program derives (RSA-2048, ECDSA-P256, DSA-2048).

func FromHostGraph

func FromHostGraph(g *evidence.Graph, opts HostOptions) ([]collector.CryptoAsset, []cdx.Property, error)

FromHostGraph projects a host's evidence graph into CBOM assets and metadata properties. It is a projection, not a store: it contains nothing the graph does not, and it refuses to project a graph that breaks the contract. In particular every `provides` edge it writes comes from a derived, cited `capable (mapped)` fact, and the component carries the claim so a consumer cannot mistake "can provide" for "uses" (CycloneDX's own guide: "a component that implements another component does not imply that the implementation is in use").

func Property

func Property(name, value string) cdx.Property

Property returns a namespaced custom property, e.g. Property("collector","apt").

func PublicKeyAsset

func PublicKeyAsset(ref, name, algorithm string, bits int, curve string, emit func(id string) (string, bool), emitAsset func(collector.CryptoAsset) string) (collector.CryptoAsset, bool)

PublicKeyAsset is a public key seen on its own, such as an SSH host key: the same related-crypto-material component a certificate's key gets, at the same precision (RSA-2048, ECDSA-P256), under the caller's bom-ref. false when the key's algorithm cannot be named.

func RandomSerial

func RandomSerial() string

RandomSerial is randomSerial for documents assembled outside Build (the merged inventory CBOM).

func Registry17Gaps

func Registry17Gaps() map[string]string

Registry17Gaps lists catalogue entries the registry has no family for, with the reason. It is what the export documentation prints, so a gap is a stated fact and not a silent omission.

func To17

func To17(in *cdx.BOM) *cdx.BOM

To17 converts a 1.6-shaped BOM to 1.7 and returns a converted copy. The input is not changed.

Types

type CertExtension

type CertExtension struct {
	Name  string // basicConstraints, keyUsage, extendedKeyUsage, certificatePolicies, ...
	Value string
	// Custom marks an extension 1.7 has no common name for: it is written as a customExtension,
	// named by Name (which carries the OID), the schema's own place for such extensions.
	Custom bool
}

CertExtension is one certificate extension by its CycloneDX 1.7 common name.

type CertFacts

type CertFacts struct {
	Subject      string
	Issuer       string
	SerialHex    string
	SHA256       string // lower-case hex over the DER encoding
	NotBefore    time.Time
	NotAfter     time.Time
	KeyAlgorithm string // as certinfo names it: RSA, ECDSA, Ed25519, ... or "unknown"
	KeyBits      int
	Curve        string
	SigName      string // as Go's x509 (or certinfo, for algorithms Go does not know) names the signature algorithm
	SigOID       string // the certificate's signatureAlgorithm OID, as read from it
	KeyOID       string // the SubjectPublicKeyInfo algorithm OID, as read from it

	// Extensions are the certificate extensions CycloneDX 1.7 names (certificateExtensions,
	// commonExtensionName). They are written only to 1.7 documents; 1.6 has no such field.
	Extensions []CertExtension
}

CertFacts is what a certificate says about itself, in the form CBOM assets are built from. The TLS scanner (a certificate a server presented) and the host inventory (a certificate a machine holds) both fill it, so the same certificate becomes the same components either way.

type HostOptions

type HostOptions struct {
	// PrivilegeNote is the warning shown when the run had less than the highest
	// privilege tier ("results may be incomplete; Administrator/root may reveal
	// more"). It is written into the document so a reader sees it too (ADR-0009).
	PrivilegeNote string
}

HostOptions carries what the projection cannot read from the graph.

type Options

type Options struct {
	Tool Tool

	// The CBOM's subject: set exactly one, or neither for a document with no
	// metadata.component. HostName is a host inventory's subject (bom-ref
	// "host:<name>", type device). Endpoint is a TLS scan's subject, "host:port"
	// (bom-ref "endpoint:<host:port>", type device: a network endpoint, not
	// necessarily the machine running this program).
	HostName string
	Endpoint string

	// MetadataProperties are extra namespaced properties written on metadata: what
	// the run was allowed to see, the privilege it ran with, and what it could not see.
	MetadataProperties []cdx.Property

	// Now and NewSerial exist so tests can make output byte-for-byte reproducible.
	Now       func() time.Time
	NewSerial func() string // must return a "urn:uuid:..." value
}

Options configures Build. The zero value is usable.

type Tool

type Tool struct {
	Name    string
	Version string
}

Tool identifies this program in the CBOM's metadata.

type UnknownSpecError

type UnknownSpecError struct{ Spec string }

UnknownSpecError is returned for a version this program does not write.

func (*UnknownSpecError) Error

func (e *UnknownSpecError) Error() string

Jump to

Keyboard shortcuts

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