artifact

package
v0.0.0-...-a0b3ea0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 27 Imported by: 17

Documentation

Index

Constants

View Source
const (
	HeaderDirectory = "headers"
	DataDirectory   = "data"
)

Variables

View Source
var ErrCompatibleDevices error = errors.New(
	"ArtifactDepends: Required field 'CompatibleDevices' not found",
)
View Source
var ErrValidatingData = errors.New("error validating data")

ErrValidatingData is an error returned by Validate() in case of invalid data.

Functions

func GetPublic

func GetPublic(private []byte) ([]byte, error)

func GetRegisteredCompressorIds

func GetRegisteredCompressorIds() []string

func MarshalECDSASignature

func MarshalECDSASignature(r, s *big.Int) ([]byte, error)

func RegisterCompressor

func RegisterCompressor(id string, compressor Compressor)

func ToStream

func ToStream(m WriteValidator) ([]byte, error)

func UnmarshalECDSASignature

func UnmarshalECDSASignature(sig []byte) (r, s *big.Int, e error)

func UpdateDataPath

func UpdateDataPath(no int) string

func UpdateHeaderPath

func UpdateHeaderPath(no int) string

func UpdatePath

func UpdatePath(no int) string

Types

type ArtifactDepends

type ArtifactDepends struct {
	ArtifactName      []string `json:"artifact_name,omitempty"`
	CompatibleDevices []string `json:"device_type,omitempty"`
	ArtifactGroup     []string `json:"artifact_group,omitempty"`
}

func (*ArtifactDepends) UnmarshalJSON

func (a *ArtifactDepends) UnmarshalJSON(b []byte) error

type ArtifactProvides

type ArtifactProvides struct {
	ArtifactName  string `json:"artifact_name"`
	ArtifactGroup string `json:"artifact_group,omitempty"`
}

type Checksum

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

func NewReaderChecksum

func NewReaderChecksum(r io.Reader, sum []byte) *Checksum

func NewWriterChecksum

func NewWriterChecksum(w io.Writer) *Checksum

func (*Checksum) Checksum

func (c *Checksum) Checksum() []byte

func (*Checksum) Read

func (c *Checksum) Read(p []byte) (int, error)

Do not call Read directly; use io.Copy instead as we are calculating checksum only after receiving io.EOF.

func (*Checksum) Verify

func (c *Checksum) Verify() error

func (*Checksum) Write

func (c *Checksum) Write(p []byte) (int, error)

type ChecksumStore

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

func NewChecksumStore

func NewChecksumStore() *ChecksumStore

func (*ChecksumStore) Add

func (c *ChecksumStore) Add(file string, sum []byte) error

func (*ChecksumStore) FilesNotMarked

func (c *ChecksumStore) FilesNotMarked() []string

func (*ChecksumStore) Get

func (c *ChecksumStore) Get(file string) ([]byte, error)

func (*ChecksumStore) GetAndMark

func (c *ChecksumStore) GetAndMark(file string) ([]byte, error)

Same as Get(), but also marks the file as visited.

func (*ChecksumStore) GetRaw

func (c *ChecksumStore) GetRaw() []byte

func (*ChecksumStore) ReadRaw

func (c *ChecksumStore) ReadRaw(data []byte) error

type Compressor

type Compressor interface {
	GetFileExtension() string
	NewReader(r io.Reader) (io.ReadCloser, error)
	NewWriter(w io.Writer) (io.WriteCloser, error)
}

func NewCompressorFromFileName

func NewCompressorFromFileName(name string) (Compressor, error)

func NewCompressorFromId

func NewCompressorFromId(id string) (Compressor, error)

func NewCompressorGzip

func NewCompressorGzip() Compressor

func NewCompressorLzma

func NewCompressorLzma() Compressor

func NewCompressorNone

func NewCompressorNone() Compressor

func NewCompressorZstd

func NewCompressorZstd(level zstd.EncoderLevel) Compressor

type CompressorGzip

type CompressorGzip struct {
}

func (*CompressorGzip) GetFileExtension

func (c *CompressorGzip) GetFileExtension() string

func (*CompressorGzip) NewReader

func (c *CompressorGzip) NewReader(r io.Reader) (io.ReadCloser, error)

func (*CompressorGzip) NewWriter

func (c *CompressorGzip) NewWriter(w io.Writer) (io.WriteCloser, error)

type CompressorLzma

type CompressorLzma struct {
}

func (*CompressorLzma) GetFileExtension

func (c *CompressorLzma) GetFileExtension() string

func (*CompressorLzma) NewReader

func (c *CompressorLzma) NewReader(r io.Reader) (io.ReadCloser, error)

func (*CompressorLzma) NewWriter

func (c *CompressorLzma) NewWriter(w io.Writer) (io.WriteCloser, error)

type CompressorNone

type CompressorNone struct {
}

func (*CompressorNone) GetFileExtension

func (c *CompressorNone) GetFileExtension() string

func (*CompressorNone) NewReader

func (c *CompressorNone) NewReader(r io.Reader) (io.ReadCloser, error)

func (*CompressorNone) NewWriter

func (c *CompressorNone) NewWriter(w io.Writer) (io.WriteCloser, error)

type CompressorZstd

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

func (*CompressorZstd) GetFileExtension

func (c *CompressorZstd) GetFileExtension() string

func (*CompressorZstd) NewReader

func (c *CompressorZstd) NewReader(r io.Reader) (io.ReadCloser, error)

func (*CompressorZstd) NewWriter

func (c *CompressorZstd) NewWriter(w io.Writer) (io.WriteCloser, error)

type Crypto

type Crypto interface {
	Sign(message []byte, key interface{}) ([]byte, error)
	Verify(message, sig []byte, key interface{}) error
}

Crypto is an interface each specific signature algorithm must implement in order to be used with PKISigner.

type ECDSA256

type ECDSA256 struct{}

func (*ECDSA256) Sign

func (e *ECDSA256) Sign(message []byte, key interface{}) ([]byte, error)

func (*ECDSA256) Verify

func (e *ECDSA256) Verify(message, sig []byte, key interface{}) error

type FileArchiver

type FileArchiver struct {
	*tar.Writer
}

func NewTarWriterFile

func NewTarWriterFile(tw *tar.Writer) *FileArchiver

func (*FileArchiver) Write

func (fa *FileArchiver) Write(f *os.File, archivePath string) error

type Files

type Files struct {
	FileList []string `json:"files"`
}

Files represents the list of file names that make up the payload for given update.

func (Files) Validate

func (f Files) Validate() error

Validate checks format of Files.

func (*Files) Write

func (f *Files) Write(p []byte) (n int, err error)

type HeaderInfo

type HeaderInfo struct {
	ArtifactName      string       `json:"artifact_name"`
	Updates           []UpdateType `json:"updates"`
	CompatibleDevices []string     `json:"device_types_compatible"`
}

HeaderInfo contains information of number and type of update files archived in Mender metadata archive.

func NewHeaderInfo

func NewHeaderInfo(
	artifactName string,
	updates []UpdateType,
	compatibleDevices []string,
) *HeaderInfo

func (*HeaderInfo) GetArtifactDepends

func (hi *HeaderInfo) GetArtifactDepends() *ArtifactDepends

func (*HeaderInfo) GetArtifactName

func (hi *HeaderInfo) GetArtifactName() string

Satisfy HeaderInfoer interface for the artifact reader.

func (*HeaderInfo) GetArtifactProvides

func (hi *HeaderInfo) GetArtifactProvides() *ArtifactProvides

func (*HeaderInfo) GetCompatibleDevices

func (hi *HeaderInfo) GetCompatibleDevices() []string

Satisfy HeaderInfoer interface for the artifact reader.

func (*HeaderInfo) GetUpdates

func (hi *HeaderInfo) GetUpdates() []UpdateType

Satisfy HeaderInfoer interface for the artifact reader.

func (*HeaderInfo) UnmarshalJSON

func (h *HeaderInfo) UnmarshalJSON(b []byte) error

func (HeaderInfo) Validate

func (hi HeaderInfo) Validate() error

Validate checks if header-info structure is correct.

func (*HeaderInfo) Write

func (hi *HeaderInfo) Write(p []byte) (n int, err error)

type HeaderInfoV3

type HeaderInfoV3 struct {
	// For historical reasons, "payloads" are often referred to as "updates"
	// in the code, since this was the old name (and still is, in V2).
	// This is the reason why the struct field is still called
	// "Updates".
	Updates []UpdateType `json:"payloads"`
	// Has its own json marshaller tags.
	ArtifactProvides *ArtifactProvides `json:"artifact_provides"`
	// Has its own json marshaller tags.
	ArtifactDepends *ArtifactDepends `json:"artifact_depends"`
}

func NewHeaderInfoV3

func NewHeaderInfoV3(updates []UpdateType,
	artifactProvides *ArtifactProvides, artifactDepends *ArtifactDepends) *HeaderInfoV3

func (*HeaderInfoV3) GetArtifactDepends

func (hi *HeaderInfoV3) GetArtifactDepends() *ArtifactDepends

func (*HeaderInfoV3) GetArtifactName

func (hi *HeaderInfoV3) GetArtifactName() string

Satisfy HeaderInfoer interface for the artifact reader.

func (*HeaderInfoV3) GetArtifactProvides

func (hi *HeaderInfoV3) GetArtifactProvides() *ArtifactProvides

func (*HeaderInfoV3) GetCompatibleDevices

func (hi *HeaderInfoV3) GetCompatibleDevices() []string

Satisfy HeaderInfoer interface for the artifact reader.

func (*HeaderInfoV3) GetUpdates

func (hi *HeaderInfoV3) GetUpdates() []UpdateType

Satisfy HeaderInfoer interface for the artifact reader.

func (*HeaderInfoV3) Validate

func (hi *HeaderInfoV3) Validate() error

Validate validates the correctness of the header version3.

func (*HeaderInfoV3) Write

func (hi *HeaderInfoV3) Write(p []byte) (n int, err error)

type HeaderInfoer

type HeaderInfoer interface {
	Write(b []byte) (n int, err error)
	GetArtifactName() string
	GetCompatibleDevices() []string
	GetUpdates() []UpdateType
	GetArtifactDepends() *ArtifactDepends
	GetArtifactProvides() *ArtifactProvides
}

HeaderInfoer wraps headerInfo version 2 and 3, in order to supply the artifact reader with the information it needs.

type Info

type Info struct {
	Format  string `json:"format"`
	Version int    `json:"version"`
}

Info contains the information about the format and the version of artifact archive.

func (Info) Validate

func (i Info) Validate() error

Validate performs sanity checks on artifact info.

func (*Info) Write

func (i *Info) Write(p []byte) (n int, err error)

type Metadata

type Metadata map[string]interface{}

Metadata contains artifacts metadata information. The exact metadata fields are user-defined and are not specified. The only requirement is that those must be stored in a for of JSON. The fields which must exist are update-type dependent. In case of `rootfs-update` image type, there are no additional fields required.

func (*Metadata) Map

func (m *Metadata) Map() map[string]interface{}

func (Metadata) Validate

func (m Metadata) Validate() error

Validate check corecness of artifacts metadata. Since the exact format is not specified validation always succeeds.

func (*Metadata) Write

func (m *Metadata) Write(p []byte) (n int, err error)

type PKCS11Signer

type PKCS11Signer struct {
	Key openssl.PrivateKey
}

func NewPKCS11Signer

func NewPKCS11Signer(pkcsKey string) (*PKCS11Signer, error)

func (*PKCS11Signer) Sign

func (s *PKCS11Signer) Sign(message []byte) ([]byte, error)

func (*PKCS11Signer) Verify

func (s *PKCS11Signer) Verify(message, sig []byte) error

type PKISigner

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

PKISigner implements public-key encryption and supports X.509-encodded keys. For now both RSA and 256 bits ECDSA are supported.

func NewPKISigner

func NewPKISigner(privateKey []byte) (*PKISigner, error)

func NewPKIVerifier

func NewPKIVerifier(publicKey []byte) (*PKISigner, error)

func (*PKISigner) Sign

func (s *PKISigner) Sign(message []byte) ([]byte, error)

func (*PKISigner) Verify

func (s *PKISigner) Verify(message, sig []byte) error

type RSA

type RSA struct{}

RSA Crypto interface implementation

func (*RSA) Sign

func (r *RSA) Sign(message []byte, key interface{}) ([]byte, error)

func (*RSA) Verify

func (r *RSA) Verify(message, sig []byte, key interface{}) error

type Scripts

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

func (*Scripts) Add

func (s *Scripts) Add(path string) error

func (*Scripts) Get

func (s *Scripts) Get() []string

type Signer

type Signer interface {
	Sign(message []byte) ([]byte, error)
}

Signer is returning a signature of the provided message.

type SigningMethod

type SigningMethod struct {
	// Key can be private or public depending if we want to sign or verify message
	Key    interface{}
	Public []byte
	Method Crypto
}

func GetKeyAndSignMethod

func GetKeyAndSignMethod(keyPEM []byte) (*SigningMethod, error)

func GetKeyAndVerifyMethod

func GetKeyAndVerifyMethod(keyPEM []byte) (*SigningMethod, error)

type StreamArchiver

type StreamArchiver struct {
	*tar.Writer
}

func NewTarWriterStream

func NewTarWriterStream(w *tar.Writer) *StreamArchiver

func (*StreamArchiver) Write

func (str *StreamArchiver) Write(data []byte, archivePath string) error

type TypeInfo

type TypeInfo struct {
	Type string `json:"type"`
}

TypeInfo provides information of type of individual updates archived in artifacts archive.

func (TypeInfo) Validate

func (ti TypeInfo) Validate() error

Validate validates corectness of TypeInfo.

func (*TypeInfo) Write

func (ti *TypeInfo) Write(p []byte) (n int, err error)

type TypeInfoDepends

type TypeInfoDepends map[string]interface{}

func NewTypeInfoDepends

func NewTypeInfoDepends(m interface{}) (ti TypeInfoDepends, err error)

func (TypeInfoDepends) Map

func (t TypeInfoDepends) Map() map[string]interface{}

func (*TypeInfoDepends) UnmarshalJSON

func (t *TypeInfoDepends) UnmarshalJSON(b []byte) error

UnmarshalJSON attempts to deserialize the json stream into a 'map[string]interface{}', where each interface value is required to be either a string, or an array of strings

type TypeInfoProvides

type TypeInfoProvides map[string]string

func NewTypeInfoProvides

func NewTypeInfoProvides(m interface{}) (ti TypeInfoProvides, err error)

func (TypeInfoProvides) Map

func (t TypeInfoProvides) Map() map[string]string

func (*TypeInfoProvides) UnmarshalJSON

func (t *TypeInfoProvides) UnmarshalJSON(b []byte) error

UnmarshalJSON attempts to deserialize the json stream into a 'map[string]interface{}', where each interface value is required to be either a string, or an array of strings

type TypeInfoV3

type TypeInfoV3 struct {
	// Rootfs/Delta (Required).
	Type *string `json:"type"`

	ArtifactDepends        TypeInfoDepends  `json:"artifact_depends,omitempty"`
	ArtifactProvides       TypeInfoProvides `json:"artifact_provides,omitempty"`
	ClearsArtifactProvides []string         `json:"clears_artifact_provides,omitempty"`
}

TypeInfoV3 provides information about the type of update contained within the headerstructure.

func (*TypeInfoV3) Validate

func (ti *TypeInfoV3) Validate() error

Validate checks that the required `Type` field is set.

func (*TypeInfoV3) Write

func (ti *TypeInfoV3) Write(b []byte) (n int, err error)

Write writes the underlying struct into a json data structure (bytestream).

type UpdateType

type UpdateType struct {
	Type *string `json:"type"`
}

UpdateType provides information about the type of update. At the moment the only built-in type is "rootfs-image".

type Verifier

type Verifier interface {
	Verify(message, sig []byte) error
}

Verifier is verifying if provided message and signature matches.

type WriteValidator

type WriteValidator interface {
	io.Writer
	Validate() error
}

WriteValidator is the interface that wraps the io.Writer interface and Validate method.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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