wasm

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 28 Imported by: 1 module, 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 wasm runs outside plugins: WebAssembly modules, signed with ed25519, loaded through wazero (pure Go, no cgo).

A module runs with WASI preview 1 and nothing else: no preopened directories, no sockets, an empty environment, a fixed clock and a fixed random seed, a memory cap and a time limit. It reads the matching tracked files on stdin and writes facts on stdout. The scanner validates every fact against the published schema and drops what the plugin may not say: kinds outside its manifest, evidence in files it was not sent. See https://cernly.dev/how/wasm-plugins/.

Index

Constants

View Source
const BundleSuffix = ".plugin.json"

BundleSuffix ends every signed manifest file.

View Source
const TestSignerPrefix = "test-key-not-for-production:"

TestSignerPrefix marks the test key in a scan's plugins list.

Variables

This section is empty.

Functions

func CheckManifest

func CheckManifest(m sdk.Manifest) error

CheckManifest validates a manifest's fields.

func EncodeKeys

func EncodeKeys(priv ed25519.PrivateKey) (privPEM, pubPEM []byte, err error)

EncodeKeys returns the PEM private and public key of priv.

func KeyID

func KeyID(pub ed25519.PublicKey) string

KeyID names a public key: ed25519: and the first 16 hex digits of its SHA-256.

func Load

func Load(bundlePath string, trust *Trust, lim Limits) (plugin.Plugin, error)

Load reads a bundle (<name>.plugin.json) and its module (<name>.wasm), checks the module's hash and the signature, and returns the plugin. A module that is unsigned, signed by a key outside trust or changed after signing does not load.

func LoadDir

func LoadDir(dir string, trust *Trust, lim Limits) ([]plugin.Plugin, error)

LoadDir loads every bundle in dir, sorted by file name. One bad bundle fails the whole load: the operator asked for each of them.

func ModuleHash

func ModuleHash(module []byte) string

ModuleHash is the hex SHA-256 of a module.

func New

func New(b Bundle, module []byte, trust *Trust, lim Limits) (plugin.Plugin, error)

New verifies a bundle against its module bytes.

func ParsePrivateKey

func ParsePrivateKey(data []byte) (ed25519.PrivateKey, error)

ParsePrivateKey reads a PEM "PRIVATE KEY" (PKCS #8) holding an ed25519 key, as `openssl genpkey -algorithm ed25519` writes it.

func ParsePublicKey

func ParsePublicKey(data []byte) (ed25519.PublicKey, error)

ParsePublicKey reads a PEM "PUBLIC KEY" (PKIX) holding an ed25519 key, as `openssl pkey -pubout` writes it.

func TestKey

func TestKey() ed25519.PrivateKey

TestKey is a fixed ed25519 key derived from a public seed, for tests and local builds. Anyone can sign with it, so nobody trusts it in production: it is never in the built-in keys, and a scan that trusts it records the signer as TestSigner(), so every report shows it.

func TestSigner

func TestSigner() string

TestSigner is how a scan names the test key as signer.

Types

type Bundle

type Bundle struct {
	Manifest  sdk.Manifest `json:"manifest"`
	Signature Signature    `json:"signature"`
}

Bundle is the signed manifest file next to a module: <name>.plugin.json beside <name>.wasm.

type Key

type Key struct {
	ID  string
	Pub ed25519.PublicKey
	By  string // "cernly" (built in) or "operator"
}

Key is one trusted public key and who added it.

type Limits

type Limits struct {
	MemoryPages uint32        // 64 KiB pages; default 16384 (1 GiB)
	Timeout     time.Duration // default 2 minutes
	Input       int64         // bytes of file content sent; default 256 MiB
	Output      int64         // bytes the plugin may write; default 64 MiB
}

Limits bound one plugin run. Exceeding one fails that plugin; the scan goes on.

type Plugin

type Plugin struct {
	// contains filtered or unexported fields
}

Plugin is one loaded, verified module.

func (*Plugin) Close

func (p *Plugin) Close() error

Close releases the compiled module.

func (*Plugin) Manifest

func (p *Plugin) Manifest() sdk.Manifest

func (*Plugin) Name

func (p *Plugin) Name() string

func (*Plugin) Run

func (p *Plugin) Run(r *repo.Repo) plugin.Result

func (*Plugin) SHA256

func (p *Plugin) SHA256() string

func (*Plugin) Signer

func (p *Plugin) Signer() string

func (*Plugin) Source

func (p *Plugin) Source() string

func (*Plugin) Version

func (p *Plugin) Version() string

func (*Plugin) Watches

func (p *Plugin) Watches(path string) bool

type Signature

type Signature struct {
	Key string `json:"key"` // key id, see KeyID
	Sig string `json:"sig"` // base64, standard encoding
}

Signature is an ed25519 signature over the manifest, which carries the module's hash.

func Sign

func Sign(priv ed25519.PrivateKey, m sdk.Manifest) (Signature, error)

Sign signs a manifest.

type Trust

type Trust struct {
	// contains filtered or unexported fields
}

Trust is the set of keys a module may be signed with: Cernly's built-in keys plus the keys the operator adds.

func NewTrust

func NewTrust(operator ...[]byte) (*Trust, error)

NewTrust returns Cernly's built-in keys plus the operator's PEM public keys.

func (*Trust) Keys

func (t *Trust) Keys() []Key

Keys lists the trusted keys by id.

func (*Trust) Verify

func (t *Trust) Verify(b Bundle) (string, error)

Verify checks a bundle's signature and returns the signing key's id.

Jump to

Keyboard shortcuts

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