spk

package
v0.0.0-...-fd1ce1a Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Path to the capnp schema that ship with Sandstorm, assuming sandstorm
	// is installed in /opt/sandstorm.
	SandstormCapnpPath = "/opt/sandstorm/latest/usr/include"
)

Variables

View Source
var (
	// The base32 alphabet used by Sandstorm for app-ids/public keys.
	SandstormBase32Encoding = base32.NewEncoding("0123456789acdefghjkmnpqrstuvwxyz").
							WithPadding(base32.NoPadding)

	ErrBadKeyLength = errors.New("invalid app id: wrong length")
)
View Source
var (
	ErrKeyNotFound        = errors.New("Key not found in keyring")
	ErrMalformedKey       = errors.New("Key is malformed")
	ErrVerificationFailed = errors.New("signature verification failed")
)
View Source
var (
	ErrArchiveTooLarge = errors.New("spk archive is too large")
	ErrNoMagicNumber   = errors.New("spk file does not start with magic number")
)

Functions

func PackInto

func PackInto(dest io.Writer, key Key, archive spk.Archive) error

Write an .spk into `dest`, using `archive` as the contents and `key` for signing. The archive must already contain the manifest.

func ReadPackageDefinition

func ReadPackageDefinition(file, variable string, extraPaths []string) (spk.PackageDefinition, error)

Read the package definition from a textual pkgdef on disk. The `capnp` executable must be in PATH.

Parameters:

- file: The schema file to read - variable: the name of the variable in the file defining the package definition. - extraPaths: a list of extra directories to search for capnproto schema.

A typical use of this would be:

ReadPackageDefinition("sandstorm-pkgdef.capnp", "pkgdef", []string{SandstormCapnpPath})

Types

type AppID

type AppID [32]byte

An app id/public key

func VerifySignature

func VerifySignature(sig spk.Signature) (pk AppID, msg []byte, err error)

VerifySignature checks the signature for validity, and returns the public key and signed message.

func (AppID) MarshalBinary

func (id AppID) MarshalBinary() ([]byte, error)

func (AppID) MarshalText

func (id AppID) MarshalText() (text []byte, err error)

func (AppID) String

func (id AppID) String() string

func (*AppID) UnmarshalBinary

func (id *AppID) UnmarshalBinary(data []byte) error

func (*AppID) UnmarshalText

func (id *AppID) UnmarshalText(text []byte) error

type ExtractedPackageMetadata

type ExtractedPackageMetadata struct {
	Dir      string       // Path where the files were extracted
	AppID    AppID        // App ID for the package
	Hash     PackageHash  // Hash of the package
	Manifest spk.Manifest // Manifest stored in the package.
}

Results of unpacking an spk

func Unpack

func Unpack(tmpDir string, r io.Reader) (ExtractedPackageMetadata, error)

Unpack reads an spk file from r and unpacks its contents to a newly created directory under tmpDir, after verifying the package's signature. Returns information about the package.

This may create other temporary files under tmpDir, which are deleted before the function returns.

type Key

type Key spk.KeyFile

A package signing key

func GenerateKey

func GenerateKey(r io.Reader) (Key, error)

Generate a new signing key. It will be the root object of its own message. The argument is a cryptographic random number generator. Defaults to crypto/rand.Reader if nil.

func (Key) AddToFile

func (k Key) AddToFile(path string) error

Add the key to the keyring in the file at `path`, which is created if it does not already exist.

func (Key) AppID

func (k Key) AppID() (AppID, error)

type Keyring

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

The contents of a sandstorm keyring, typically stored at ~/.sandstorm-keyring or ~/.sandstorm/sandstorm-keyring.

func LoadKeyring

func LoadKeyring(filename string) (Keyring, error)

Load the sandstorm keyring from a named file.

func (Keyring) GetKey

func (k Keyring) GetKey(appID AppID) (Key, error)

Get the key for the given app id from the keyring.

type PackageHash

type PackageHash [sha256.Size]byte

func (PackageHash) ID

func (ph PackageHash) ID() string

ID returns the package ID based on the hash. This string is used in various places: as a directory name, as part of the package's URL in the app market, and others. The value is the first 128 bits, hex-encoded.

TODO(cleanup): have this return a types.ID[something].

type PkgDefParams

type PkgDefParams struct {
	AppID AppID
	Key   Key

	// The capnp schema id for the app's sandstorm-pkgdef.capnp
	SchemaId uint64

	// The keyring in which to save the gerated key.
	// Defaults to ~/.sandstorm/sandstorm-keyring
	KeyringPath string

	// Path to save the package definition. Defaults to
	// `.sandstorm/sandstorm-pkgdef.capnp`.
	PkgDefPath string
}

Parameters for initializing an application's pkgdef.

func NewApp

func NewApp() (*PkgDefParams, error)

Generate the information needed to initialize a new app.

func (*PkgDefParams) Emit

func (p *PkgDefParams) Emit() error

Emit a pkgdef with the given parameters, and save the app's key to the keyring.

Jump to

Keyboard shortcuts

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