evidence

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 9 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 evidence is the platform-neutral record of what a host collector saw, and the rules that stop a report claiming more than was seen.

It is the middle of a pipeline (see docs/decisions/ADR-0001):

sensors (OS-specific)  ->  Batch of Observations + Coverage
Graph (normalise)      ->  one node per thing, all its observations kept
derive                 ->  cited, rule-made facts, each naming its inputs
cbom projection        ->  CycloneDX 1.6

This package imports no operating-system package and no CycloneDX type, so nothing platform-specific can leak past a sensor. Its central rule is mechanical: no relationship may claim more than the weakest evidence it rests on (see Class and CheckGraph).

Index

Constants

View Source
const (
	UnknownPermission  = "permission"
	UnknownBudget      = "budget"
	UnknownUnsupported = "unsupported"
	UnknownStubbed     = "stubbed-source" // a source that fails silently returned a suspect result
	UnknownError       = "error"
)

The unknown reasons.

View Source
const (
	MethodDpkgStatus   = "debian.dpkg.status@1"
	MethodRPMQuery     = "rpm.query@1"            // the package list rpm -qa reports, gathered by the inventory script
	MethodAPKInstalled = "alpine.apk.installed@1" // the package list apk reports, gathered by the inventory script
	MethodFSWalkName   = "fs.walk.filename@1"
	MethodPEVersion    = "pe.version-info@1"
	MethodKnowledge    = "knowledge.mapping@1"
	MethodPEImports    = "pe.imports@1"

	// Certificates held as files: parsed from PEM or DER (PRD-003 REQ-CERT-2).
	MethodCertFile = "certs.file-parse@1"
	// Certificates in the Windows system stores: the system is asked, and each certificate's own
	// bytes are parsed (ADR-0016).
	MethodCertStore = "windows.certstore.enum@1"

	// Windows native cryptography: the system is asked, not a file read (ADR-0013).
	MethodCNGProviders  = "windows.cng.enum-providers@1"
	MethodCNGAlgorithms = "windows.cng.enum-algorithms@1"
	MethodKSPProviders  = "windows.ncrypt.enum-providers@1"
	MethodKSPAlgorithms = "windows.ncrypt.enum-algorithms@1"
	MethodCSPProviders  = "windows.csp.enum@1"
	MethodCNGProbe      = "windows.cng.probe@1"
)

Method IDs.

View Source
const (
	KindPackage   = "package"
	KindArtefact  = "artefact"
	KindAlgorithm = "algorithm"
	KindProvider  = "provider" // a cryptographic provider the operating system registers
	// KindCertificate is an X.509 certificate a host holds. Only the certificate's public
	// metadata is ever described: never a key, never a password (ADR-0005, PRD-003 REQ-CERT-4).
	KindCertificate = "certificate"
)

Subject kinds.

Variables

View Source
var AllowedAttrs = map[string]map[string]bool{
	KindPackage:   set("name", "version", "arch", "distro", "family", "kind"),
	KindArtefact:  set("path", "size", "fileVersion", "productName", "family", "kind", "arch", "peValid", "sha256", "imports"),
	KindAlgorithm: set(),
	KindProvider:  set("providerKind", "cspType", "comment", "opened", "algorithms"),

	KindCertificate: set("sha256", "serial", "subject", "issuer", "notBefore", "notAfter", "keyAlg", "keyBits", "curve",
		"sigAlg", "isCA", "selfSigned", "dnsNames", "keyUsage"),
}

AllowedAttrs is the allow-list of attributes per subject kind (ADR-0005). A sensor may not put anything else on a subject: free-form host data is how secrets and hostile strings would travel.

View Source
var SourceAttrs = map[string]bool{"privateKey": true}

SourceAttrs is the allow-list of attributes of a place (Source.Attrs). privateKey says whether a private key is known to be stored beside a certificate at this place: yes, no or unknown. It is read from metadata or the presence of a key block, never from opening a key.

Functions

func AlgorithmKey

func AlgorithmKey(id string) string

AlgorithmKey is the canonical key of a catalogue algorithm.

func ArtefactKey

func ArtefactKey(relPath string) string

ArtefactKey is the canonical key of a file: its host-relative, forward-slash path with the user-profile segment tokenised (see RedactPath).

func CertificateKey

func CertificateKey(sha256hex string) string

CertificateKey is the canonical key of a certificate: its SHA-256 fingerprint over the DER encoding, lower-case hex. It is the same key the estate graph uses, so a certificate a host holds and the one a server presents are one entity.

func Clean

func Clean(s string, max int) string

Clean makes a host-supplied string safe to carry: invalid UTF-8 and control characters become '?', and the result is truncated to max bytes. Use it for values that are expected to be tidy (a version, an architecture) where dropping the whole observation would lose a real finding.

func Finish

func Finish(o *Observation)

Finish computes the observation's deterministic ID from its content. Call it last: any later change invalidates the ID and Validate says so.

func ProviderKey

func ProviderKey(namespace, name string) string

ProviderKey is the canonical key of a cryptographic provider: the namespace it lives in ("cng" for a CNG primitive or key storage provider, "csp" for a legacy cryptographic service provider) and its registered name, lower-cased. Two namespaces, because a CSP and a CNG provider are different things that could share a name.

func RedactPath

func RedactPath(p string) string

RedactPath tokenises the user-profile segment of a host-relative path so that no user name is ever emitted: "Users/alice/AppData/x" -> "Users/%USER%/AppData/x", "home/alice/x" -> "home/%USER%/x". It expects forward slashes and no leading slash. The Windows built-in profile roots that are not user names are left alone.

func SafeText

func SafeText(s string, max int) bool

SafeText reports whether s is fit to carry as host-supplied data: valid UTF-8, no control characters, and at most max bytes. Host strings (file names, versions) are attacker-controlled; a sensor that meets one that fails this must skip it and say so in its coverage, never pass it on, because Validate would reject it and a single hostile name must not be able to abort an inventory.

func Validate

func Validate(o Observation) error

Validate checks one observation against the contract. It does not resolve BasedOn (the Graph does that).

Types

type Batch

type Batch struct {
	Observations []Observation
	Coverage     []Coverage
}

Batch is what one sensor returns. A partial Batch with an error is valid: partial beats none.

type BindingKind

type BindingKind string

BindingKind says how an application is tied to a library or material.

const (
	BindStaticImport    BindingKind = "static-import"
	BindPackageDepends  BindingKind = "package-depends"
	BindServiceConfig   BindingKind = "service-config"
	BindDynamicLoadHint BindingKind = "dynamic-load-hint"
)

The binding kinds. Every one means "could use", never "uses".

type CapableKind

type CapableKind string

CapableKind distinguishes asking the running system from applying cited knowledge.

const (
	CapableProbed CapableKind = "probed" // the running system was asked
	CapableMapped CapableKind = "mapped" // cited knowledge applied to a present artefact
)

The capable kinds.

type Claim

type Claim struct {
	Rung      Rung        `json:"rung"`
	Capable   CapableKind `json:"capable,omitempty"`
	Direction Direction   `json:"direction,omitempty"`
	Binding   BindingKind `json:"binding,omitempty"`
}

Claim is what an observation asserts. Only the field that goes with Rung is set.

type Class

type Class int

Class is how strong a statement is. A relationship, and a path made of relationships, has the class of its weakest link, and the words a report may use follow the class.

E0 existence  <  E1 reachable  <  E2 loaded  <  E3 exercised
const (
	E0Existence Class = iota
	E1Reachable
	E2Loaded
	E3Exercised
)

The classes.

func ClassOf

func ClassOf(c Claim) Class

ClassOf is the strength class of a claim. Policy is a modifier, not a link in a chain (it changes what a path means without making it stronger), so it is existence-class here and is applied separately.

func MinClass

func MinClass(cs ...Class) Class

MinClass is the weakest of the given classes; the empty list is the strongest (nothing weakens it).

func (Class) String

func (c Class) String() string

String is the short name used in messages.

func (Class) Wording

func (c Class) Wording() string

Wording is what a report may say at this class, and no more.

type Coverage

type Coverage struct {
	Sensor string            `json:"sensor"`
	Method string            `json:"method"`
	Scope  string            `json:"scope"`
	Status CoverageStatus    `json:"status"`
	Reason string            `json:"reason,omitempty"`
	Limits map[string]string `json:"limits,omitempty"` // budgets that applied and, if hit, the counts
	Unseen []string          `json:"unseen,omitempty"` // named blind spots for this scope
	// Denied counts locations that could not be read for lack of permission, and
	// is what lets a run say "elevated privileges may reveal more".
	Denied int `json:"denied,omitempty"`
}

Coverage records what a sensor attempted and what it could not see. It is part of the evidence, not a log: silence must never read as safety.

type CoverageStatus

type CoverageStatus string

CoverageStatus is how completely a sensor covered its scope.

const (
	CoverageComplete CoverageStatus = "complete"
	CoveragePartial  CoverageStatus = "partial"
	CoverageSkipped  CoverageStatus = "skipped"
	CoverageDenied   CoverageStatus = "denied"
	CoverageFailed   CoverageStatus = "failed"
)

The coverage statuses.

type Direction

type Direction string

Direction is the effect of a policy. Unspecified means defaults apply: it is never the same as "none".

const (
	DirPermits     Direction = "permits"
	DirForbids     Direction = "forbids"
	DirUnspecified Direction = "unspecified"
)

The policy directions.

type Graph

type Graph struct {
	Host     Host
	Coverage []Coverage
	// contains filtered or unexported fields
}

Graph holds the normalised evidence for one host: one Node per subject key, every observation kept (nothing is averaged), plus the coverage each sensor reported.

func NewGraph

func NewGraph(host Host) *Graph

NewGraph returns an empty graph for host.

func (*Graph) Add

func (g *Graph) Add(o Observation) error

Add validates o and inserts it. A derived observation's BasedOn must already be in the graph, and neither it nor its relations may be stronger than the weakest observation it rests on (the central rule). Adding an identical observation twice is a no-op.

func (*Graph) AddBatch

func (g *Graph) AddBatch(b Batch) error

AddBatch adds every observation and the coverage of a batch. It stops at the first invalid observation: a sensor that breaks the contract is a bug, not a partial result.

func (*Graph) Check

func (g *Graph) Check() error

Check re-verifies the whole graph against the contract: every observation is valid, every derived fact's inputs exist, and nothing claims more than the weakest evidence it rests on. Graph.Add already enforces this as evidence is added; Check is the independent second look the projection makes before it writes anything, so a bug in either place cannot produce an over-claiming report.

func (*Graph) Node

func (g *Graph) Node(key string) (*Node, bool)

Node returns the node with the given subject key.

func (*Graph) Nodes

func (g *Graph) Nodes() []*Node

Nodes returns every node, sorted by key.

func (*Graph) Observation

func (g *Graph) Observation(id string) (*Observation, bool)

Observation returns an observation by ID.

func (*Graph) Observations

func (g *Graph) Observations() []*Observation

Observations returns every observation, sorted by ID.

type Host

type Host struct {
	Name string
	// ID is a salted hash of the platform machine id. The raw id is never
	// emitted. Empty when the platform offers none.
	ID        string
	OSFamily  string
	OSVersion string
	Arch      string
	// PrivilegeTier is the highest tier the run used: "user" or "admin".
	PrivilegeTier string
}

Host identifies the machine the evidence is about.

type KnowledgeRef

type KnowledgeRef struct {
	ID        string   `json:"id"`
	Version   string   `json:"version"`
	Citations []string `json:"citations,omitempty"`
}

KnowledgeRef names the cited knowledge a derived fact applies.

type Method

type Method struct {
	ID      string
	Version string
	// Sensor is the name of the sensor that uses the method; it is what a
	// component's cipherhorizon:collector property reports.
	Sensor string
	// Technique is a value of CycloneDX 1.6's closed evidence-technique list.
	Technique string
	Quality   Quality
	// MinPrivilege is the lowest tier the method works at: "user" or "admin".
	MinPrivilege string
	// SecretProximity is "none", or "adjacent" when the method works near key
	// material and so needs extra review and tests (ADR-0005).
	SecretProximity string
}

Method is a named, versioned way of sensing, declared once.

func LookupMethod

func LookupMethod(id string) (Method, bool)

LookupMethod returns the declared method.

func Methods

func Methods() []Method

Methods lists the declared methods, sorted by ID.

type Node

type Node struct {
	Subject      Subject
	Observations []*Observation
}

Node is one thing on the host and every observation made about it.

func (*Node) Derived

func (n *Node) Derived() []*Observation

Derived returns the derived observations of the node.

func (*Node) Present

func (n *Node) Present() []*Observation

Present returns the observed `present` observations of the node.

func (*Node) PresentQuality

func (n *Node) PresentQuality() (Quality, bool)

PresentQuality is the strongest method quality among the node's observed `present` observations, and whether there is one. It is what decides whether a capability may be derived: a name match alone is not enough (ADR-0002).

type Observation

type Observation struct {
	ID        string          `json:"id"`
	Stream    Stream          `json:"stream"`
	Origin    Origin          `json:"origin"`
	Subject   Subject         `json:"subject"`
	Claim     Claim           `json:"claim"`
	Outcome   Outcome         `json:"outcome"`
	Unknown   *UnknownReason  `json:"unknown,omitempty"`
	Relations []Relation      `json:"relations,omitempty"`
	Method    string          `json:"method"`
	Source    Source          `json:"source"`
	Privilege string          `json:"privilege"`
	BasedOn   []string        `json:"basedOn,omitempty"`
	Knowledge *KnowledgeRef   `json:"knowledge,omitempty"`
	Downgrade *QualityLowered `json:"qualityOverride,omitempty"`
}

Observation is one fact, or one derived fact. It is immutable once Finish has given it an ID.

type Origin

type Origin string

Origin says whether a record was seen or worked out.

const (
	OriginObserved Origin = "observed"
	OriginDerived  Origin = "derived"
)

The origins. A derived record must name the observations it rests on.

type Outcome

type Outcome string

Outcome is what a sensor can say about a thing. Absence is earned, not assumed.

const (
	OutcomeObserved        Outcome = "observed"
	OutcomeConfirmedAbsent Outcome = "confirmed-absent" // only from an authoritative method that completed
	OutcomeUnknown         Outcome = "unknown"          // the sensor could not see
)

The outcomes.

type Quality

type Quality string

Quality is how reliably a method establishes what it claims. It is declared once per method, not guessed per fact. No numeric confidence is used: nothing here has been calibrated, and a number would suggest precision we lack (ADR-0002).

const (
	QualityAuthoritative Quality = "authoritative" // a complete authoritative source was parsed, or the system was asked
	QualityParsed        Quality = "parsed"        // a file or structure was parsed in a stable format
	QualityHeuristic     Quality = "heuristic"     // a name or pattern match
	QualitySampled       Quality = "sampled"       // a runtime observation that may miss
)

The qualities, strongest first.

func QualityOf

func QualityOf(o Observation) (Quality, error)

QualityOf is an observation's effective method quality: the method's own, unless the observation lowers it.

func (Quality) Sufficient

func (q Quality) Sufficient() bool

Sufficient reports whether the quality may support a derived capability: authoritative or parsed. A name match alone may not.

type QualityLowered

type QualityLowered struct {
	To     Quality `json:"to"`
	Reason string  `json:"reason"`
}

QualityLowered lowers an observation's method quality, with a reason. It can only lower: a fact may never claim more reliability than its method has.

type Relation

type Relation struct {
	Kind  string `json:"kind"`
	To    string `json:"to"` // Subject.Key
	Claim Claim  `json:"claim"`
}

Relation is an edge from an observation's subject to another subject.

type Rung

type Rung string

Rung is the kind of statement an observation makes.

const (
	RungPresent     Rung = "present"     // an artefact exists here
	RungProvisioned Rung = "provisioned" // the host holds key/certificate material (metadata only)
	RungCapable     Rung = "capable"     // the artefact can perform an algorithm
	RungPolicy      Rung = "policy"      // configuration permits or forbids something
	RungBound       Rung = "bound"       // an application is linked/configured to use something
	RungLoaded      Rung = "loaded"      // a running process has it mapped
	RungExercised   Rung = "exercised"   // an operation was observed (network stream; never host)
)

The claim rungs. See Class for how they compare.

type Source

type Source struct {
	Kind     string `json:"kind"`     // file, registry, api, database, procfs
	Location string `json:"location"` // host-relative, forward-slash, user names tokenised
	// Attrs are facts about this particular place, as opposed to the thing found there:
	// the same certificate in two files can have a private key beside it in one and not
	// the other. Allow-listed (SourceAttrs); nothing free-form.
	Attrs map[string]string `json:"attrs,omitempty"`
}

Source says where on the host an observation came from.

type Stream

type Stream string

Stream says who observed a record. A record made by a host collector is host evidence even when it is about network activity; a record made by `tls scan` is network evidence. They are joined only by a labelled assessment (ADR-0006).

const (
	StreamHost    Stream = "host"
	StreamNetwork Stream = "network"
)

The streams.

type Subject

type Subject struct {
	Kind string `json:"kind"`
	// Key is canonical: the same thing seen by two methods has the same Key, so
	// the graph merges them. See the key constructors in keys.go.
	Key  string `json:"key"`
	Name string `json:"name,omitempty"`
	// Attrs is allow-listed per Kind (AllowedAttrs). Nothing free-form.
	Attrs map[string]string `json:"attrs,omitempty"`
}

Subject is what an observation is about.

type UnknownReason

type UnknownReason struct {
	Code   string `json:"code"` // one of the Unknown* constants
	Detail string `json:"detail,omitempty"`
}

UnknownReason explains an OutcomeUnknown.

Jump to

Keyboard shortcuts

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