models

package
v0.0.0-...-f44e450 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2023 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnalyzeReport

type AnalyzeReport struct {

	// ID is just the primary key. It is used to reference to from the `analyzer_report` table.
	ID uint64 `db:"id"`

	// JobID is the ID of the job which initiated the analysis. Used for searching
	// for results.
	JobID types.JobID `db:"job_id"`

	// AssetID is an optional field that represents a host which was analyzed
	AssetID *int64 `db:"asset_id"`

	// Timestamp defines the time moment when the analysis report was requested
	Timestamp time.Time `db:"timestamp"`

	// ProcessedAt defines the time moment when the analysis report was processed
	ProcessedAt sql.NullTime `db:"processed_at"`

	// GroupKey is the key used to aggregate multiple reports together.
	//
	// Is assigned by an application which decides how to group reports,
	// currently it is firmware-alerter.
	GroupKey *AnalyzeReportGroupKey `db:"group_key"`

	// AnalyzerReports is a list of succeeded analysis reports
	AnalyzerReports []AnalyzerReport `db:"-"`
}

AnalyzeReport represents a full report for a single analysis

type AnalyzeReportGroup

type AnalyzeReportGroup struct {

	// GroupKey is the primary key and the reference to `analyze_report`.`group_key`.
	GroupKey AnalyzeReportGroupKey `db:"group_key"`

	// The ID of the post which represents this group of reports (aggregated by `ReportKey`).
	PostID *int64 `db:"post_id"`

	// The ID of the task (currently, for PWM) which represents this group of reports (aggregated by `ReportKey`).
	TaskID *int64 `db:"task_id"`

	// AnalyzeReports is the list of AnalyzeReports` associated with this group.
	AnalyzeReports []AnalyzeReport `db:"-"`
}

AnalyzeReportGroup represents a group of AnalyzeReports, grouped by `Key`.

type AnalyzeReportGroupKey

type AnalyzeReportGroupKey = types.ImageID

AnalyzeReportGroupKey is an unique key used to aggregate multiple AnalyzeReport-s.

Currently the "ActualImageID" is used for that, so the type is aliased to types.ImageID, but feel free to change that.

type AnalyzerReport

type AnalyzerReport struct {
	ID              uint64              `db:"id"`
	AnalyzeReportID uint64              `db:"analyze_report_id"`
	AnalyzerID      analysis.AnalyzerID `db:"analyzer_id"` // TODO: remove this field from here, it should be just an index on the DB side
	Input           analysis.Input      `db:"input"`       // TODO: make typed, so that AnalyzeID could be removed
	Report          *analysis.Report    `db:"report"`
	ExecError       SQLErrorWrapper     `db:"exec_error"`
}

AnalyzerReport represents a report that was generated by a specific analyzer

type FirmwareImageMetadata

type FirmwareImageMetadata struct {
	ImageID         types.ImageID   `db:"image_id,pk"`
	FirmwareVersion sql.NullString  `db:"firmware_version"`
	Filename        sql.NullString  `db:"filename"`
	Size            uint64          `db:"size"`
	TSAdd           time.Time       `db:"ts_add"`
	TSUpload        sql.NullTime    `db:"ts_upload"`
	HashSHA2_512    types.HashValue `db:"hash_sha2_512"`
	HashBlake3_512  types.HashValue `db:"hash_blake3_512"`
	HashStable      types.HashValue `db:"hash_stable"`
}

FirmwareImageMetadata is a metadata of a stored firmware image. noinspection GoSnakeCaseUsage

func NewFirmwareImageMetadata

func NewFirmwareImageMetadata(
	image []byte,
	firmwareVersion string,
	firmwareDate string,
	filename string,
) FirmwareImageMetadata

NewFirmwareImageMetadata returns a new instance of image metadata.

func (FirmwareImageMetadata) BlobStorageKey

func (meta FirmwareImageMetadata) BlobStorageKey() []byte

BlobStorageKey return the path should be used to store the image in the BlobStorage.

func (*FirmwareImageMetadata) CalcMissingInfo

func (meta *FirmwareImageMetadata) CalcMissingInfo(ctx context.Context, image []byte)

CalcMissingInfo calculates values for empty fields based on the image

func (*FirmwareImageMetadata) ToThrift

ToThrift converts ImageMetadata to the structure defined in the Thrift model. noinspection GoSnakeCaseUsage

type GenericSQLError

type GenericSQLError struct {
	Err string
}

GenericSQLError is used as the fallback type for an error, which type was not registered in the analysis type registry.

func (GenericSQLError) Error

func (e GenericSQLError) Error() string

Error implements interface "error".

type ReproducedPCRs

type ReproducedPCRs struct {
	ID              uint64          `db:"id,pk"`
	HashStable      types.HashValue `db:"hash_stable"`
	Registers       string          `db:"registers"`
	RegistersSHA512 types.HashValue `db:"registers_sha512"`
	TPMDevice       string          `db:"tpm_device"`
	PCR0SHA1        []byte          `db:"pcr0_sha1"`
	PCR0SHA256      []byte          `db:"pcr0_sha256"`
	Timestamp       time.Time       `db:"timestamp"`
}

ReproducedPCRs represents a single row `reproduced_pcrs` table

func NewReproducedPCRs

func NewReproducedPCRs(
	hashStable types.HashValue,
	regs registers.Registers,
	tpmDevice tpmdetection.Type,
	pcr0SHA1 []byte,
	pcr0SHA256 []byte,
) (ReproducedPCRs, error)

NewReproducedPCRs creates a new ReproducedPCRs object

func (ReproducedPCRs) ParseResgisters

func (r ReproducedPCRs) ParseResgisters() (registers.Registers, error)

ParseResgisters returns unmarshalled registers

func (ReproducedPCRs) ParseTPMDevice

func (r ReproducedPCRs) ParseTPMDevice() (tpmdetection.Type, error)

ParseTPMDevice returns detected TPM device

type SQLErrorWrapper

type SQLErrorWrapper struct {
	Err error
}

SQLErrorWrapper wraps an error to serialize and deserialize it for SQL. The type is preserved if it was registered using analysis.RegisterType.

func (SQLErrorWrapper) Error

func (e SQLErrorWrapper) Error() string

Error implements interface "error".

func (*SQLErrorWrapper) Scan

func (e *SQLErrorWrapper) Scan(src any) error

Scan converts DB's value to JobID.

func (SQLErrorWrapper) Unwrap

func (e SQLErrorWrapper) Unwrap() error

Unwrap implements the interface used by errors.Unwrap()

func (SQLErrorWrapper) Value

func (e SQLErrorWrapper) Value() (driver.Value, error)

Value converts the value to be stored in DB.

type UniqueKey

type UniqueKey struct {
	HashStable      types.HashValue
	RegistersSHA512 types.HashValue
	TPMDevice       string
}

UniqueKey represents a unique search index for reproduced_pcrs table

func NewUniqueKey

func NewUniqueKey(
	hashStable types.HashValue,
	regs registers.Registers,
	tpmDevice tpmdetection.Type,
) (UniqueKey, error)

NewUniqueKey create a new UniqueKey object

Jump to

Keyboard shortcuts

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