winapi

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 2 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 winapi is the platform layer for Windows cryptography: the ONLY code in the collector that calls the CNG, key storage and legacy CSP APIs. Like internal/hostinfo it is where operating-system code lives, so nothing else has to import x/sys/windows or unsafe (enforced by internal/archtest).

It knows nothing about evidence, CBOMs or knowledge: it answers "what does Windows say", with bounded, validated values. The sensor in internal/sense/wincng turns the answers into evidence.

It is split so the logic above it is testable anywhere:

  • api.go the interface, the limits and the error type;
  • api_windows.go the real implementation (hand-written, bounded);
  • api_other.go a stub for every other operating system.

Security rules (ADR-0004, ADR-0005, ADR-0013): no subprocess and no network; no private key, certificate or secret is opened or enumerated; a provider is opened (which loads its code) only when the caller asks for that one provider, and the sensor asks only for an allow-listed in-box provider; every string that comes back is bounded and checked before it is used.

Index

Constants

View Source
const (
	OpCipher            uint32 = 0x00000001
	OpHash              uint32 = 0x00000002
	OpAsymmetricEncrypt uint32 = 0x00000004
	OpSecretAgreement   uint32 = 0x00000008
	OpSignature         uint32 = 0x00000010
	OpRNG               uint32 = 0x00000020
	OpKeyDerivation     uint32 = 0x00000040
	OpAll               uint32 = 0x0000007f
)

Operation classes for BCryptEnumAlgorithms and NCryptEnumAlgorithms (the BCRYPT_*_OPERATION values in bcrypt.h).

View Source
const (
	MaxEntries = 2048 // algorithms, providers or CSPs accepted from one call
	MaxName    = 256  // UTF-16 code units in one name
)

Limits. Every one bounds what a misconfigured or hostile registration can make a run read or carry.

View Source
const (
	MaxCertsPerStore = 20_000
	MaxCertDER       = 64 << 10
)

Limits on what one store can make a run carry (ADR-0016).

View Source
const (
	KeyYes     = "yes"
	KeyNo      = "no"
	KeyUnknown = "unknown"
)

Private-key answers. "no" means no key is associated with the certificate in that store; it is not a claim about any other place.

Variables

View Source
var CertStoreNames = []string{"MY", "Root", "CA", "TrustedPeople", "TrustedPublisher", "AuthRoot"}

CertStoreNames is the fixed list of system store names the layer will open (ADR-0016). The Disallowed store is left out on purpose: a certificate on a deny list must not be mistaken for a trust anchor.

View Source
var ErrStoreNotAllowed = errors.New("winapi: that certificate store is not on the allow-list")

ErrStoreNotAllowed is returned for a store outside the allow-list.

View Source
var ErrUnsupported = errors.New("wincng: Windows cryptography is not available on this operating system")

ErrUnsupported means the API exists only on Windows.

Functions

func ValidStore

func ValidStore(loc StoreLocation, name string) bool

ValidStore reports whether (loc, name) is on the allow-list. The real implementation checks it before calling Windows, whoever the caller is.

Types

type API

type API interface {
	// Native reports whether this is the real Windows implementation. A fake or the
	// non-Windows stub returns false, so the sensor is not detected on a host it
	// cannot describe.
	Native() bool
	// Algorithms lists the registered algorithm identifiers that support ops.
	Algorithms(ops uint32) (list []Algorithm, skipped int, err error)
	// AlgorithmProviders lists the CNG providers registered for one algorithm.
	AlgorithmProviders(algID string) (names []string, skipped int, err error)
	// RegisteredProviders lists every registered CNG provider.
	RegisteredProviders() (names []string, skipped int, err error)
	// StorageProviders lists the registered key storage providers. It loads none.
	StorageProviders() (list []StorageProvider, skipped int, err error)
	// StorageProviderAlgorithms opens ONE key storage provider and lists the
	// algorithms it offers. The sensor calls it only for allow-listed providers.
	StorageProviderAlgorithms(provider string, ops uint32) (list []Algorithm, skipped int, err error)
	// CSPs lists the registered legacy providers. It loads none.
	CSPs() (list []CSP, skipped int, err error)
	// Probe reports whether the default CNG provider will open algID and, when
	// paramSet (digits only) is not empty, accept it as the algorithm's parameter
	// set. Probing a parameter set generates an ephemeral in-memory key pair and
	// destroys it immediately; it is never exported, stored or used.
	Probe(algID, paramSet string) (bool, error)
}

API is what the sensor needs from Windows. Every method returns only bounded, valid strings; a value that is not is omitted and counted in Skipped.

func New

func New() API

New returns an API that reports the operating system as unsupported. The sensor never registers itself as detected off Windows, so this is only reached by a direct caller.

type Algorithm

type Algorithm struct {
	Name string
	// Ops is the set of operation classes it supports.
	Ops uint32
}

Algorithm is one identifier CNG has registered.

type CSP

type CSP struct {
	Name string
	Type uint32 // PROV_* provider type
}

CSP is a registered legacy cryptographic service provider.

type CertStoreAPI

type CertStoreAPI interface {
	// Native reports whether this is the real Windows implementation.
	Native() bool
	// CertStore lists the certificates in one allow-listed store. A store that does not
	// exist yields no certificates and no error. skipped counts certificates left out
	// because they were too large or the store held more than MaxCertsPerStore.
	CertStore(loc StoreLocation, name string) (certs []StoreCert, skipped int, err error)
}

CertStoreAPI is what the certificate sensor needs from Windows.

func NewCertStore

func NewCertStore() CertStoreAPI

NewCertStore returns an API that reports the operating system as unsupported.

type StatusError

type StatusError struct {
	Call string
	Code uint32
}

StatusError is a failed Windows call and its NTSTATUS or Win32 code.

func (*StatusError) Error

func (e *StatusError) Error() string

type StorageProvider

type StorageProvider struct {
	Name    string
	Comment string
}

StorageProvider is a registered key storage provider.

type StoreCert

type StoreCert struct {
	DER        []byte
	PrivateKey string
}

StoreCert is one certificate from a store: its own encoded bytes and whether a private key is associated with it. Nothing else is read from the store.

type StoreLocation

type StoreLocation string

StoreLocation is where a system certificate store lives.

const (
	LocalMachine StoreLocation = "LocalMachine"
	CurrentUser  StoreLocation = "CurrentUser"
)

The store locations the layer will read.

Jump to

Keyboard shortcuts

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