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
- func Build(assets []collector.CryptoAsset, opts Options) (*cdx.BOM, []string)
- func CertificateAsset(f CertFacts, emit func(id string) (string, bool), ...) (collector.CryptoAsset, *collector.CryptoAsset)
- func Encode(w io.Writer, bom *cdx.BOM, pretty bool) error
- func EncodeSpec(w io.Writer, bom *cdx.BOM, spec string, pretty bool) error
- func FamilyFor(name string) (family string, ok bool)
- func FromHostGraph(g *evidence.Graph, opts HostOptions) ([]collector.CryptoAsset, []cdx.Property, error)
- func Property(name, value string) cdx.Property
- func PublicKeyAsset(ref, name, algorithm string, bits int, curve string, ...) (collector.CryptoAsset, bool)
- func RandomSerial() string
- func Registry17Gaps() map[string]string
- func To17(in *cdx.BOM) *cdx.BOM
- type CertExtension
- type CertFacts
- type HostOptions
- type Options
- type Tool
- type UnknownSpecError
Constants ¶
const ( Spec16 = "1.6" Spec17 = "1.7" )
Spec names the CycloneDX versions this program writes.
const DefaultSpec = Spec17
DefaultSpec is what the programs write unless asked otherwise.
const PropertyNamespace = "cipherhorizon"
PropertyNamespace prefixes every custom property this program adds, as the CycloneDX property taxonomy asks of non-CycloneDX property names.
const SpecVersion = cdx.SpecVersion1_6
SpecVersion is the CycloneDX version emitted. 1.7 is a later, opt-in step.
Variables ¶
This section is empty.
Functions ¶
func Build ¶
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 ¶
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 ¶
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 ¶
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 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 ¶
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.
Types ¶
type CertExtension ¶
type CertExtension struct {
Name string // basicConstraints, keyUsage, extendedKeyUsage, certificatePolicies, ...
Value string
}
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
// 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 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