fit

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2023 License: BSD-3-Clause Imports: 20 Imported by: 18

Documentation

Index

Constants

View Source
const (
	// ACHeaderVersion0 is version "0.0 – for SINIT ACM before 2017"
	ACHeaderVersion0 = ACModuleHeaderVersion(0x00000000)

	// ACHeaderVersion3 is version "3.0 – for SINIT ACM of converge of BtG and TXT"
	ACHeaderVersion3 = ACModuleHeaderVersion(0x00030000)
)
View Source
const (
	EntryTypeFITHeaderEntry              = EntryType(0x00)
	EntryTypeMicrocodeUpdateEntry        = EntryType(0x01)
	EntryTypeStartupACModuleEntry        = EntryType(0x02)
	EntryTypeDiagnosticACModuleEntry     = EntryType(0x03)
	EntryTypeBIOSStartupModuleEntry      = EntryType(0x07)
	EntryTypeTPMPolicyRecord             = EntryType(0x08)
	EntryTypeBIOSPolicyRecord            = EntryType(0x09)
	EntryTypeTXTPolicyRecord             = EntryType(0x0A)
	EntryTypeKeyManifestRecord           = EntryType(0x0B)
	EntryTypeBootPolicyManifest          = EntryType(0x0C)
	EntryTypeCSESecureBoot               = EntryType(0x10)
	EntryTypeFeaturePolicyDeliveryRecord = EntryType(0x2D)
	EntryTypeJMPDebugPolicy              = EntryType(0x2F)
	EntryTypeSkip                        = EntryType(0x7F)
)

noinspection GoSnakeCaseUsage

Variables

This section is empty.

Functions

func CalculateOffsetFromPhysAddr

func CalculateOffsetFromPhysAddr(physAddr uint64, imageSize uint64) uint64

CalculateOffsetFromPhysAddr calculates the offset within an image of the physical address (address to a region mapped from the SPI chip).

Examples:

CalculateOffsetFromPhysAddr(0xffffffff, 0x1000) == 0xfff
CalculateOffsetFromPhysAddr(0xffffffc0, 0x1000) == 0xfc0

func CalculatePhysAddrFromOffset

func CalculatePhysAddrFromOffset(offset uint64, imageSize uint64) uint64

CalculatePhysAddrFromOffset calculates the physical address (address to a region mapped from the SPI chip) using an offset withtin an image, relatively to BasePhysAddr.

Examples:

CalculatePhysAddrFromOffset(0x01, 0x2000) ==  0xffffe001
CalculatePhysAddrFromOffset(0x40, 0x2000) ==  0xffffe040

func CalculateTailOffsetFromPhysAddr

func CalculateTailOffsetFromPhysAddr(physAddr uint64) uint64

CalculateTailOffsetFromPhysAddr calculates the offset (towards down, relatively to BasePhysAddr) of the physical address (address to a region mapped from the SPI chip).

Examples:

CalculateTailOffsetFromPhysAddr(0xffffffff) == 0x01
CalculateTailOffsetFromPhysAddr(0xffffffc0) == 0x40

func EntryDataSegmentCoordinates

func EntryDataSegmentCoordinates(entry Entry, firmware io.ReadSeeker) (uint64, uint64, error)

EntryDataSegmentCoordinates returns the coordinates of the data segment coordinates associates with the entry.

func EntryDataSegmentSize

func EntryDataSegmentSize(entry Entry, firmware io.ReadSeeker) (uint64, error)

EntryDataSegmentSize returns the coordinates of the data segment size associates with the entry.

func EntryRecalculateHeaders

func EntryRecalculateHeaders(entry Entry) error

EntryRecalculateHeaders recalculates headers of the entry based on its data.

func EntrySACMParseSize

func EntrySACMParseSize(b []byte) (uint32, error)

EntrySACMParseSize parses SACM structure size

func EntrySACMParseSizeFrom

func EntrySACMParseSizeFrom(r io.ReadSeeker, offset uint64) (uint32, error)

EntrySACMParseSizeFrom parses SACM structure size

func GetHeadersTableRangeFrom

func GetHeadersTableRangeFrom(firmware io.ReadSeeker) (startIdx, endIdx uint64, err error)

GetHeadersTableRangeFrom returns the starting and ending indexes of the FIT headers table within the firmware image.

func GetPointerCoordinates

func GetPointerCoordinates(firmwareSize uint64) (startIdx, endIdx int64)

GetPointerCoordinates returns the position of the FIT pointer within the firmware.

func RegisterEntryType

func RegisterEntryType(entryTypeID EntryType, entryGoType Entry)

RegisterEntryType adds a new FIT entry type to the registry of known entry types.

Types

type ACChipsetID

type ACChipsetID uint16

ACChipsetID defines the module release identifier

type ACFlags

type ACFlags uint16

ACFlags defines the module-specific flags

type ACModuleHeaderVersion

type ACModuleHeaderVersion uint32

ACModuleHeaderVersion defines module format version: * 0.0 – for SINIT ACM before 2017 * 3.0 – for SINIT ACM of converge of BtG and TXT

func (ACModuleHeaderVersion) GoString added in v1.1.1

func (ver ACModuleHeaderVersion) GoString() string

type ACModuleSubType

type ACModuleSubType uint16

ACModuleSubType defines the subtype of AC module (0 - TXT ACM; 1 - S-ACM)

type ACModuleType

type ACModuleType uint16

ACModuleType defines the type of AC module

type ACModuleVendor

type ACModuleVendor uint32

ACModuleVendor defines the module vendor identifier

type Address64

type Address64 uint64

Address64 is a 64bit address type

func (Address64) Offset

func (addr Address64) Offset(firmwareSize uint64) uint64

Offset returns an offset from the beginning of a firmware of a defined size.

func (Address64) Pointer

func (addr Address64) Pointer() uint64

Pointer returns the pointer which could be used for pointer arithmetics.

func (*Address64) SetOffset

func (addr *Address64) SetOffset(offset, firmwareSize uint64)

SetOffset sets the value to a physical address corresponding to an offset from the beginning of the firmware.

See also the description of calculatePhysAddrFromOffset.

func (Address64) String

func (addr Address64) String() string

String implements fmt.Stringer

type BCDDate

type BCDDate uint32

BCDDate is a date in format ("year.month.day")

type CodeControl

type CodeControl uint32

CodeControl is the authenticated code control flags

type Entries

type Entries []Entry

Entries are a slice of multiple parsed FIT entries (headers + data)

func GetEntries

func GetEntries(firmware []byte) (Entries, error)

GetEntries returns parsed FIT-entries

func GetEntriesFrom

func GetEntriesFrom(firmware io.ReadSeeker) (Entries, error)

GetEntriesFrom returns parsed FIT-entries

func (Entries) Inject

func (entries Entries) Inject(b []byte, headersOffset uint64) error

Inject writes complete FIT (headers + data + pointer) to a firmware image.

What will happen: 1. The FIT headers will be written by offset headersOffset. 2. The FIT pointer will be written at consts.FITPointerOffset offset from the end of the image. 3. Data referenced by FIT headers will be written at offsets accordingly to Address fields (in the headers).

Consider calling Rehash() before Inject()/InjectTo()

func (Entries) InjectTo

func (entries Entries) InjectTo(w io.WriteSeeker, headersOffset uint64) error

InjectTo does the same as Inject, but for io.WriteSeeker.

func (Entries) RecalculateHeaders

func (entries Entries) RecalculateHeaders() error

RecalculateHeaders recalculates metadata to be consistent with data. For example, it fixes checksum, data size, entry type and so on.

Supposed to be used before Inject or/and InjectTo. Since it is possible to prepare data in entries, then call Rehash (to prepare headers consistent with data).

func (Entries) String

func (entries Entries) String() string

String implements fmt.Stringer

func (Entries) Table

func (entries Entries) Table() Table

Table returns a table of headers of all entries of the slice.

type EntriesByType

type EntriesByType []Entry

EntriesByType is a helper to sort a slice of `Entry`-ies by their type/class.

func (EntriesByType) Len

func (entries EntriesByType) Len() int

func (EntriesByType) Less

func (entries EntriesByType) Less(i, j int) bool

func (EntriesByType) Swap

func (entries EntriesByType) Swap(i, j int)

type Entry

type Entry interface {
	// GetEntryBase returns EntryBase (which contains metadata of the Entry).
	GetEntryBase() *EntryBase
}

Entry is the interface common to any FIT entry

func NewEntry

func NewEntry(hdr *EntryHeaders, firmware io.ReadSeeker) Entry

NewEntry returns a new entry using headers and firmware image

type EntryBIOSPolicyRecord

type EntryBIOSPolicyRecord struct{ EntryBase }

EntryBIOSPolicyRecord represents a FIT entry of type "BIOS Policy Record" (0x09)

func (*EntryBIOSPolicyRecord) CustomGetDataSegmentSize

func (entry *EntryBIOSPolicyRecord) CustomGetDataSegmentSize(firmware io.ReadSeeker) (uint64, error)

func (*EntryBIOSPolicyRecord) CustomRecalculateHeaders

func (entry *EntryBIOSPolicyRecord) CustomRecalculateHeaders() error

CustomRecalculateHeaders recalculates metadata to be consistent with data. For example, it fixes checksum, data size, entry type and so on.

type EntryBIOSStartupModuleEntry

type EntryBIOSStartupModuleEntry struct{ EntryBase }

EntryBIOSStartupModuleEntry represents a FIT entry of type "BIOS Startup Module Entry" (0x07)

type EntryBase

type EntryBase struct {
	// Headers is FIT entry headers.
	//
	// See "Table 1-1" in "1.2 Firmware Interface Table" in "Firmware Interface Table" specification:
	//  * https://www.intel.com/content/dam/www/public/us/en/documents/guides/fit-bios-specification.pdf
	Headers EntryHeaders

	// DataSegmentBytes is the raw bytes of the special data segment referenced by the headers.
	//
	// Is not nil only if FIT entry really references to a data segment. If FIT entry
	// stores data directly in headers then DataSegmentBytes is nil.
	DataSegmentBytes []byte `json:",omitempty"`

	// HeadersErrors is the list of errors occurred while parsing and interpreting FIT entry headers.
	HeadersErrors []error `json:",omitempty"`
}

EntryBase is the common information for any FIT entry

func (*EntryBase) GetEntryBase

func (entry *EntryBase) GetEntryBase() *EntryBase

GetEntryBase returns EntryBase (which contains metadata of the Entry).

func (*EntryBase) GoString

func (entry *EntryBase) GoString() string

GoString implements fmt.GoStringer

type EntryBootPolicyManifestRecord

type EntryBootPolicyManifestRecord struct{ EntryBase }

EntryBootPolicyManifestRecord represents a FIT entry of type "Boot Policy Manifest" (0x0C)

func (*EntryBootPolicyManifestRecord) CustomGetDataSegmentSize

func (entry *EntryBootPolicyManifestRecord) CustomGetDataSegmentSize(firmware io.ReadSeeker) (uint64, error)

func (*EntryBootPolicyManifestRecord) CustomRecalculateHeaders

func (entry *EntryBootPolicyManifestRecord) CustomRecalculateHeaders() error

CustomRecalculateHeaders recalculates metadata to be consistent with data. For example, it fixes checksum, data size, entry type and so on.

func (*EntryBootPolicyManifestRecord) ParseData

ParseData creates EntryBootPolicyManifestRecord from EntryBootPolicyManifest

func (*EntryBootPolicyManifestRecord) Reader added in v1.2.0

func (entry *EntryBootPolicyManifestRecord) Reader() *bytes.Reader

Reader creates io.ReadSeeker from EntryBootPolicyManifestRecord

type EntryCSESecureBoot

type EntryCSESecureBoot struct{ EntryBase }

EntryCSESecureBoot represents a FIT entry of type "CSE Secure Boot" (0x10)

type EntryCustomGetDataSegmentSizer

type EntryCustomGetDataSegmentSizer interface {
	// CustomGetDataSegmentSize returns the size of the data segment associates with the entry.
	CustomGetDataSegmentSize(firmwareImage io.ReadSeeker) (uint64, error)
}

EntryCustomGetDataSegmentSizer is an extension of Entry which overrides the default procedure of calculating the data segment size.

type EntryCustomRecalculateHeaderser

type EntryCustomRecalculateHeaderser interface {
	// CustomRecalculateHeaders recalculates metadata to be consistent with data.
	// For example, it fixes checksum, data size, entry type and so on.
	CustomRecalculateHeaders() error
}

CustomRecalculateHeaderser is an extension of Entry which overrides the default procedure of recalculating EntryHeaders.

type EntryDiagnosticACM

type EntryDiagnosticACM struct{ EntryBase }

EntryDiagnosticACM represents a FIT entry of type "Diagnostic ACM" (0x03)

func (*EntryDiagnosticACM) CustomGetDataSegmentSize

func (entry *EntryDiagnosticACM) CustomGetDataSegmentSize(firmware io.ReadSeeker) (uint64, error)

Init initializes the entry using EntryHeaders and firmware image.

func (*EntryDiagnosticACM) CustomRecalculateHeaders

func (entry *EntryDiagnosticACM) CustomRecalculateHeaders() error

CustomRecalculateHeaders recalculates metadata to be consistent with data. For example, it fixes checksum, data size, entry type and so on.

type EntryFITHeaderEntry

type EntryFITHeaderEntry struct{ EntryBase }

EntryFITHeaderEntry represents a FIT entry of type "FIT Header Entry" (0x00)

func (*EntryFITHeaderEntry) CustomGetDataSegmentSize

func (entry *EntryFITHeaderEntry) CustomGetDataSegmentSize(firmware io.ReadSeeker) (uint64, error)

func (*EntryFITHeaderEntry) CustomRecalculateHeaders

func (entry *EntryFITHeaderEntry) CustomRecalculateHeaders() error

type EntryFeaturePolicyDeliveryRecord

type EntryFeaturePolicyDeliveryRecord struct{ EntryBase }

EntryFeaturePolicyDeliveryRecord represents a FIT entry of type "Feature Policy Delivery Record" (0x2D)

type EntryHeaders

type EntryHeaders struct {
	// Address is the base address of the firmware component.
	// Must be aligned on 16 byte boundary.
	Address Address64

	Size Uint24

	// Reserved should always be equal to zero.
	Reserved uint8

	Version EntryVersion

	TypeAndIsChecksumValid TypeAndIsChecksumValid

	Checksum uint8
}

EntryHeaders implements a "FIT Entry Format".

See "Table 1-1" in "1.2 Firmware Interface Table" in "Firmware Interface Table" specification:

Descriptions of the fields are adapted descriptions from the document by the link above.

func ParseEntryHeadersFrom

func ParseEntryHeadersFrom(r io.Reader) (*EntryHeaders, error)

ParseEntryHeadersFrom parses a single entry headers entry.

func (*EntryHeaders) CalculateChecksum

func (hdr *EntryHeaders) CalculateChecksum() uint8

CalculateChecksum calculates the checksum ("CHKSUM") according to point 4.0 of the FIT specification.

func (EntryHeaders) GetEntry

func (hdr EntryHeaders) GetEntry(firmware []byte) Entry

GetEntry returns a full entry (headers + data)

func (EntryHeaders) GetEntryFrom

func (hdr EntryHeaders) GetEntryFrom(firmware io.ReadSeeker) Entry

GetEntryFrom returns a full entry (headers + data)

func (*EntryHeaders) GoString

func (hdr *EntryHeaders) GoString() string

GoString implements fmt.GoStringer.

func (*EntryHeaders) IsChecksumValid

func (hdr *EntryHeaders) IsChecksumValid() bool

IsChecksumValid returns if bit "C_V" has value "1".

func (EntryHeaders) MarshalJSON

func (hdr EntryHeaders) MarshalJSON() ([]byte, error)

MarshalJSON just implements encoding/json.Marshaler

func (*EntryHeaders) String

func (hdr *EntryHeaders) String() string

func (*EntryHeaders) Type

func (hdr *EntryHeaders) Type() EntryType

Type returns the type of the FIT entry

func (*EntryHeaders) UnmarshalJSON

func (hdr *EntryHeaders) UnmarshalJSON(b []byte) error

UnmarshalJSON just implements encoding/json.Unmarshaler

func (*EntryHeaders) Write

func (hdr *EntryHeaders) Write(b []byte) (int, error)

Write implements io.Writer. It writes the headers in a binary format to `b`.

func (*EntryHeaders) WriteTo

func (hdr *EntryHeaders) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo. It writes the headers in a binary format to `w`.

type EntryJMPDebugPolicy

type EntryJMPDebugPolicy struct{ EntryBase }

EntryJMPDebugPolicy represents a FIT entry of type "JMP $ Debug Policy" (0x2F)

type EntryKeyManifestRecord

type EntryKeyManifestRecord struct{ EntryBase }

EntryKeyManifestRecord represents a FIT entry of type "Key Manifest Record" (0x0B)

func (*EntryKeyManifestRecord) CustomGetDataSegmentSize

func (entry *EntryKeyManifestRecord) CustomGetDataSegmentSize(firmware io.ReadSeeker) (uint64, error)

func (*EntryKeyManifestRecord) CustomRecalculateHeaders

func (entry *EntryKeyManifestRecord) CustomRecalculateHeaders() error

CustomRecalculateHeaders recalculates metadata to be consistent with data. For example, it fixes checksum, data size, entry type and so on.

func (*EntryKeyManifestRecord) ParseData

func (entry *EntryKeyManifestRecord) ParseData() (*bgkey.Manifest, *cbntkey.Manifest, error)

ParseData creates EntryKeyManifestRecord from EntryKeyManifest

func (*EntryKeyManifestRecord) Reader added in v1.2.0

func (entry *EntryKeyManifestRecord) Reader() *bytes.Reader

Reader creates io.ReadSeeker from EntryKeyManifestRecord

type EntryMicrocodeUpdateEntry

type EntryMicrocodeUpdateEntry struct{ EntryBase }

EntryMicrocodeUpdateEntry represents a FIT entry of type "Microcode Update Entry" (0x01)

type EntryPoint

type EntryPoint uint32

EntryPoint is the authenticated code entry point offset (bytes)

type EntrySACM

type EntrySACM struct{ EntryBase }

EntrySACM represents a FIT entry of type "Startup AC Module Entry" (0x02)

func (*EntrySACM) CustomGetDataSegmentSize

func (entry *EntrySACM) CustomGetDataSegmentSize(firmware io.ReadSeeker) (uint64, error)

func (*EntrySACM) CustomRecalculateHeaders

func (entry *EntrySACM) CustomRecalculateHeaders() error

func (*EntrySACM) MarshalJSON

func (entry *EntrySACM) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*EntrySACM) ParseData

func (entry *EntrySACM) ParseData() (*EntrySACMData, error)

ParseData parses SACM entry and returns EntrySACMData.

func (*EntrySACM) UnmarshalJSON

func (entry *EntrySACM) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaller

type EntrySACMData

type EntrySACMData struct {
	EntrySACMDataInterface

	UserArea []byte
}

EntrySACMData combines the structure for ACM and the user area.

func ParseSACMData added in v1.1.0

func ParseSACMData(r io.Reader) (*EntrySACMData, error)

ParseSACMData parses SACM entry and returns EntrySACMData.

func (*EntrySACMData) GetCommon

func (entryData *EntrySACMData) GetCommon() *EntrySACMDataCommon

GetCommon returns the common part of the structures for different ACM versions.

func (*EntrySACMData) Read added in v1.1.0

func (entryData *EntrySACMData) Read(b []byte) (int, error)

Read parses the ACM

func (*EntrySACMData) ReadFrom added in v1.1.0

func (entryData *EntrySACMData) ReadFrom(r io.Reader) (int64, error)

ReadFrom parses the ACM

func (*EntrySACMData) Write added in v1.1.0

func (entryData *EntrySACMData) Write(b []byte) (int, error)

Write compiles the SACM into a binary representation

func (*EntrySACMData) WriteTo added in v1.1.0

func (entryData *EntrySACMData) WriteTo(w io.Writer) (int64, error)

WriteTo compiles the SACM into a binary representation

type EntrySACMData0

type EntrySACMData0 struct {
	EntrySACMDataCommon

	RSAPubKey [256]byte
	RSAPubExp [4]byte
	RSASig    [256]byte
	Scratch   [572]byte
}

EntrySACMData0 is the structure for ACM of version 0.0.

func (*EntrySACMData0) GetRSAPubExp

func (entryData *EntrySACMData0) GetRSAPubExp() uint32

GetRSAPubExp returns the RSA exponent

func (*EntrySACMData0) GetRSAPubKey

func (entryData *EntrySACMData0) GetRSAPubKey() rsa.PublicKey

GetRSAPubKey returns the RSA public key

func (*EntrySACMData0) GetRSASig

func (entryData *EntrySACMData0) GetRSASig() []byte

GetRSASig returns the RSA signature.

func (*EntrySACMData0) GetScratch

func (entryData *EntrySACMData0) GetScratch() []byte

GetScratch returns the Scratch field value

func (*EntrySACMData0) RSASigBinaryOffset

func (entryData *EntrySACMData0) RSASigBinaryOffset() uint64

RSASigBinaryOffset returns the RSA signature offset

func (*EntrySACMData0) Read added in v1.1.0

func (entryData *EntrySACMData0) Read(b []byte) (int, error)

Read parses the ACM v0 headers

func (*EntrySACMData0) ReadFrom added in v1.1.0

func (entryData *EntrySACMData0) ReadFrom(r io.Reader) (int64, error)

ReadFrom parses the ACM v0 headers

func (*EntrySACMData0) Write added in v1.1.0

func (entryData *EntrySACMData0) Write(b []byte) (int, error)

Write compiles the SACM v0 headers into a binary representation

func (*EntrySACMData0) WriteTo added in v1.1.0

func (entryData *EntrySACMData0) WriteTo(w io.Writer) (int64, error)

WriteTo compiles the SACM v0 headers into a binary representation

type EntrySACMData3

type EntrySACMData3 struct {
	EntrySACMDataCommon

	RSAPubKey [384]byte
	RSASig    [384]byte
	Scratch   [832]byte
}

EntrySACMData3 is the structure for ACM of version 3.0

func (*EntrySACMData3) GetRSAPubKey

func (entryData *EntrySACMData3) GetRSAPubKey() rsa.PublicKey

GetRSAPubKey returns the RSA public key

func (*EntrySACMData3) GetRSASig

func (entryData *EntrySACMData3) GetRSASig() []byte

GetRSASig returns the RSA signature.

func (*EntrySACMData3) GetScratch

func (entryData *EntrySACMData3) GetScratch() []byte

GetScratch returns the Scratch field value

func (*EntrySACMData3) RSASigBinaryOffset

func (entryData *EntrySACMData3) RSASigBinaryOffset() uint64

RSASigBinaryOffset returns the RSA signature offset

func (*EntrySACMData3) Read added in v1.1.0

func (entryData *EntrySACMData3) Read(b []byte) (int, error)

Read parses the ACM v3 headers

func (*EntrySACMData3) ReadFrom added in v1.1.0

func (entryData *EntrySACMData3) ReadFrom(r io.Reader) (int64, error)

ReadFrom parses the ACM v3 headers

func (*EntrySACMData3) Write added in v1.1.0

func (entryData *EntrySACMData3) Write(b []byte) (int, error)

Write compiles the SACM v3 headers into a binary representation

func (*EntrySACMData3) WriteTo added in v1.1.0

func (entryData *EntrySACMData3) WriteTo(w io.Writer) (int64, error)

WriteTo compiles the SACM v3 headers into a binary representation

type EntrySACMDataCommon

type EntrySACMDataCommon struct {
	ModuleType      ACModuleType
	ModuleSubType   ACModuleSubType
	HeaderLen       SizeM4
	HeaderVersion   ACModuleHeaderVersion
	ChipsetID       ACChipsetID
	Flags           ACFlags
	ModuleVendor    ACModuleVendor
	Date            BCDDate
	Size            SizeM4
	TXTSVN          TXTSVN
	SESVN           SESVN
	CodeControl     CodeControl
	ErrorEntryPoint ErrorEntryPoint
	GDTLimit        GDTLimit
	GDTBasePtr      GDTBasePtr
	SegSel          SegSel
	EntryPoint      EntryPoint
	Reserved2       [64]byte
	KeySize         SizeM4
	ScratchSize     SizeM4
}

EntrySACMDataCommon is the common part from the beginning of a startup AC module entry of any version.

func (EntrySACMDataCommon) DateBinaryOffset

func (entryData EntrySACMDataCommon) DateBinaryOffset() uint

DateBinaryOffset returns the offset of the field 'Date' relatively to the beginning of the structure in the binary format (see 'encoding/binary').

func (*EntrySACMDataCommon) GetChipsetID

func (entryData *EntrySACMDataCommon) GetChipsetID() ACChipsetID

GetChipsetID returns ChipsetID field value

func (*EntrySACMDataCommon) GetCodeControl

func (entryData *EntrySACMDataCommon) GetCodeControl() CodeControl

GetCodeControl returns the authenticated code control flags

func (*EntrySACMDataCommon) GetDate

func (entryData *EntrySACMDataCommon) GetDate() BCDDate

GetDate returns Date field value ("year.month.day")

func (*EntrySACMDataCommon) GetEntryPoint

func (entryData *EntrySACMDataCommon) GetEntryPoint() EntryPoint

GetEntryPoint returns the authenticated code entry point offset (bytes)

func (*EntrySACMDataCommon) GetErrorEntryPoint

func (entryData *EntrySACMDataCommon) GetErrorEntryPoint() ErrorEntryPoint

GetErrorEntryPoint returns error entry point field value

func (*EntrySACMDataCommon) GetFlags

func (entryData *EntrySACMDataCommon) GetFlags() ACFlags

GetFlags returns Flags field value (the module-specific flags)

func (*EntrySACMDataCommon) GetGDTBasePtr

func (entryData *EntrySACMDataCommon) GetGDTBasePtr() GDTBasePtr

GetGDTBasePtr returns the GDT base pointer offset (bytes)

func (*EntrySACMDataCommon) GetGDTLimit

func (entryData *EntrySACMDataCommon) GetGDTLimit() GDTLimit

GetGDTLimit returns GDTLimit field value

func (*EntrySACMDataCommon) GetHeaderLen

func (entryData *EntrySACMDataCommon) GetHeaderLen() SizeM4

GetHeaderLen returns HeaderLen field value

func (*EntrySACMDataCommon) GetHeaderVersion

func (entryData *EntrySACMDataCommon) GetHeaderVersion() ACModuleHeaderVersion

GetHeaderVersion returns module format version: * 0.0 – for SINIT ACM before 2017 * 3.0 – for SINIT ACM of converge of BtG and TXT

func (*EntrySACMDataCommon) GetKeySize

func (entryData *EntrySACMDataCommon) GetKeySize() SizeM4

GetKeySize returns the KeySize field value (the size in multiples of four bytes)

func (*EntrySACMDataCommon) GetModuleSubType

func (entryData *EntrySACMDataCommon) GetModuleSubType() ACModuleSubType

GetModuleSubType returns the subtype of AC module (0 - TXT ACM; 1 - S-ACM)

func (*EntrySACMDataCommon) GetModuleType

func (entryData *EntrySACMDataCommon) GetModuleType() ACModuleType

GetModuleType returns the type of AC module

func (*EntrySACMDataCommon) GetModuleVendor

func (entryData *EntrySACMDataCommon) GetModuleVendor() ACModuleVendor

GetModuleVendor returns ModuleVendor field value

func (*EntrySACMDataCommon) GetRSAPubExp

func (entryData *EntrySACMDataCommon) GetRSAPubExp() uint32

GetRSAPubExp returns the RSA exponent

func (*EntrySACMDataCommon) GetRSAPubKey

func (entryData *EntrySACMDataCommon) GetRSAPubKey() rsa.PublicKey

GetRSAPubKey returns the RSA public key

func (*EntrySACMDataCommon) GetRSASig

func (entryData *EntrySACMDataCommon) GetRSASig() []byte

GetRSASig returns the RSA signature.

func (*EntrySACMDataCommon) GetReserved2

func (entryData *EntrySACMDataCommon) GetReserved2() [64]byte

GetReserved2 returns the Reserved2 field value

func (*EntrySACMDataCommon) GetSESVN

func (entryData *EntrySACMDataCommon) GetSESVN() SESVN

GetSESVN returns Software Guard Extensions (Secure Enclaves) Security Version Number

func (*EntrySACMDataCommon) GetScratch

func (entryData *EntrySACMDataCommon) GetScratch() []byte

GetScratch returns the Scratch field value

func (*EntrySACMDataCommon) GetScratchSize

func (entryData *EntrySACMDataCommon) GetScratchSize() SizeM4

GetScratchSize returns the ScratchSize field value (the size in multiples of four bytes)

func (*EntrySACMDataCommon) GetSegSel

func (entryData *EntrySACMDataCommon) GetSegSel() SegSel

GetSegSel the segment selector initializer

func (*EntrySACMDataCommon) GetSize

func (entryData *EntrySACMDataCommon) GetSize() SizeM4

GetSize returns Size field value (the size in multiples of four bytes)

func (*EntrySACMDataCommon) GetTXTSVN

func (entryData *EntrySACMDataCommon) GetTXTSVN() TXTSVN

GetTXTSVN returns TXT security version number

func (EntrySACMDataCommon) HeaderVersionBinaryOffset

func (entryData EntrySACMDataCommon) HeaderVersionBinaryOffset() uint

HeaderVersionBinaryOffset returns the offset of the field 'HeaderVersion' relatively to the beginning of the structure in the binary format (see 'encoding/binary').

func (EntrySACMDataCommon) KeySizeBinaryOffset

func (entryData EntrySACMDataCommon) KeySizeBinaryOffset() uint

KeySizeBinaryOffset returns the offset of the field 'KeySize' relatively to the beginning of the structure in the binary format (see 'encoding/binary').

func (*EntrySACMDataCommon) RSASigBinaryOffset

func (entryData *EntrySACMDataCommon) RSASigBinaryOffset() uint64

RSASigBinaryOffset returns the RSA signature offset

func (*EntrySACMDataCommon) Read added in v1.1.0

func (entryData *EntrySACMDataCommon) Read(b []byte) (int, error)

Read parses the ACM common headers

func (*EntrySACMDataCommon) ReadFrom added in v1.1.0

func (entryData *EntrySACMDataCommon) ReadFrom(r io.Reader) (int64, error)

ReadFrom parses the ACM common headers

func (EntrySACMDataCommon) SizeBinaryOffset

func (entryData EntrySACMDataCommon) SizeBinaryOffset() uint

SizeBinaryOffset returns the offset of the field 'Size' relatively to the beginning of the structure in the binary format (see 'encoding/binary').

func (*EntrySACMDataCommon) TXTSVNBinaryOffset

func (entryData *EntrySACMDataCommon) TXTSVNBinaryOffset() uint64

TXTSVNBinaryOffset returns the offset of the field 'TXTSVN' relatively to the beginning of the structure in the binary format (see 'encoding/binary').

func (*EntrySACMDataCommon) Write added in v1.1.0

func (entryData *EntrySACMDataCommon) Write(b []byte) (int, error)

Write compiles the SACM common headers into a binary representation

func (*EntrySACMDataCommon) WriteTo added in v1.1.0

func (entryData *EntrySACMDataCommon) WriteTo(w io.Writer) (int64, error)

WriteTo compiles the SACM common headers into a binary representation

type EntrySACMDataInterface

type EntrySACMDataInterface interface {
	io.ReadWriter
	io.ReaderFrom
	io.WriterTo

	GetModuleType() ACModuleType
	GetModuleSubType() ACModuleSubType
	GetHeaderLen() SizeM4
	GetHeaderVersion() ACModuleHeaderVersion
	GetChipsetID() ACChipsetID
	GetFlags() ACFlags
	GetModuleVendor() ACModuleVendor
	GetDate() BCDDate
	GetSize() SizeM4
	GetTXTSVN() TXTSVN
	GetSESVN() SESVN
	GetCodeControl() CodeControl
	GetErrorEntryPoint() ErrorEntryPoint
	GetGDTLimit() GDTLimit
	GetGDTBasePtr() GDTBasePtr
	GetSegSel() SegSel
	GetEntryPoint() EntryPoint
	GetReserved2() [64]byte
	GetKeySize() SizeM4
	GetScratchSize() SizeM4
	GetRSAPubKey() rsa.PublicKey
	GetRSAPubExp() uint32
	GetRSASig() []byte
	GetScratch() []byte

	// Auxiliary methods:
	RSASigBinaryOffset() uint64

	// DateBinaryOffset returns the offset of the field 'Date'
	// relatively to the beginning of the structure in the binary
	// format (see 'encoding/binary').
	DateBinaryOffset() uint
}

EntrySACMDataInterface is the interface of a startup AC module data (of any version)

type EntrySkip

type EntrySkip struct{ EntryBase }

EntrySkip represents a FIT entry of type "Unused Entry (skip)" (0x7F)

type EntryTPMPolicyRecord

type EntryTPMPolicyRecord struct{ EntryBase }

EntryTPMPolicyRecord represents a FIT entry of type "TPM Policy Record" (0x08)

func (*EntryTPMPolicyRecord) CustomGetDataSegmentSize

func (entry *EntryTPMPolicyRecord) CustomGetDataSegmentSize(firmware io.ReadSeeker) (uint64, error)

Init initializes the entry using EntryHeaders and firmware image.

func (*EntryTPMPolicyRecord) CustomRecalculateHeaders

func (entry *EntryTPMPolicyRecord) CustomRecalculateHeaders() error

CustomRecalculateHeaders recalculates metadata to be consistent with data. For example, it fixes checksum, data size, entry type and so on.

type EntryTXTPolicyRecord

type EntryTXTPolicyRecord struct{ EntryBase }

EntryTXTPolicyRecord represents a FIT entry of type "TXT Policy Record" (0x0A)

func (*EntryTXTPolicyRecord) CustomGetDataSegmentSize

func (entry *EntryTXTPolicyRecord) CustomGetDataSegmentSize(firmware io.ReadSeeker) (uint64, error)

Init initializes the entry using EntryHeaders and firmware image.

func (*EntryTXTPolicyRecord) CustomRecalculateHeaders

func (entry *EntryTXTPolicyRecord) CustomRecalculateHeaders() error

CustomRecalculateHeaders recalculates metadata to be consistent with data. For example, it fixes checksum, data size, entry type and so on.

func (*EntryTXTPolicyRecord) Parse

Parse parses TXT Policy Record entry

type EntryTXTPolicyRecordDataFlatPointer

type EntryTXTPolicyRecordDataFlatPointer uint64

EntryTXTPolicyRecordDataFlatPointer is a parsed TXT Policy Record entry of version 0

func (EntryTXTPolicyRecordDataFlatPointer) IsTXTEnabled

func (entryData EntryTXTPolicyRecordDataFlatPointer) IsTXTEnabled() bool

IsTXTEnabled returns true if TXT is enabled.

func (EntryTXTPolicyRecordDataFlatPointer) TPMPolicyPointer

func (entryData EntryTXTPolicyRecordDataFlatPointer) TPMPolicyPointer() uint64

TPMPolicyPointer returns the TPM Policy pointer.

type EntryTXTPolicyRecordDataIndexedIO

type EntryTXTPolicyRecordDataIndexedIO struct {
	IndexRegisterIOAddress uint16
	DataRegisterIOAddress  uint16
	AccessWidth            uint8
	BitPosition            uint8
	Index                  uint16
}

EntryTXTPolicyRecordDataIndexedIO is a parsed TXT Policy Record entry of version 1.

func (*EntryTXTPolicyRecordDataIndexedIO) IsTXTEnabled

func (entryData *EntryTXTPolicyRecordDataIndexedIO) IsTXTEnabled() bool

IsTXTEnabled returns true if TXT is enabled.

type EntryTXTPolicyRecordDataInterface

type EntryTXTPolicyRecordDataInterface interface {
	IsTXTEnabled() bool
}

EntryTXTPolicyRecordDataInterface is a parsed TXT Policy Record entry

type EntryType

type EntryType uint8

EntryType is a 7 bit field containing the type code for the component registered in the FIT table.

func AllEntryTypes

func AllEntryTypes() []EntryType

func (EntryType) String

func (_type EntryType) String() string

String implements fmt.Stringer

type EntryUnknown

type EntryUnknown struct{ EntryBase }

EntryUnknown represents an unknown FIT entry type.

type EntryVersion

type EntryVersion uint16

EntryVersion contains the component's version number in binary coded decimal (BCD) format. For the FIT header entry, the value in this field will indicate the revision number of the FIT data structure. The upper byte of the revision field indicates the major revision and the lower byte indicates the minor revision. The format 0x1234 conveys the major number encoded in the first two digits and the minor number in the last two with a fixed point assumed in between

func (EntryVersion) Major

func (ver EntryVersion) Major() uint8

Major returns the major part of the entry version

func (EntryVersion) MarshalJSON

func (ver EntryVersion) MarshalJSON() ([]byte, error)

MarshalJSON just implements encoding/json.Marshaler

func (EntryVersion) Minor

func (ver EntryVersion) Minor() uint8

Minor returns the minor part of the entry version

func (EntryVersion) String

func (ver EntryVersion) String() string

func (*EntryVersion) UnmarshalJSON

func (ver *EntryVersion) UnmarshalJSON(b []byte) error

UnmarshalJSON just implements encoding/json.Unmarshaler

type ErrACMInvalidKeySize

type ErrACMInvalidKeySize struct {
	ExpectedKeySize uint64
	RealKeySize     uint64
}

ErrACMInvalidKeySize means ACM entry has invalid key size

func (*ErrACMInvalidKeySize) Error

func (err *ErrACMInvalidKeySize) Error() string

type ErrExpectedFITHeadersMagic

type ErrExpectedFITHeadersMagic struct {
	Received []byte
}

ErrExpectedFITHeadersMagic means FIT magic string was not found where it was expected.

func (*ErrExpectedFITHeadersMagic) Error

func (err *ErrExpectedFITHeadersMagic) Error() string

type ErrInvalidTXTPolicyRecordVersion

type ErrInvalidTXTPolicyRecordVersion struct {
	EntryVersion EntryVersion
}

ErrInvalidTXTPolicyRecordVersion means TXT Policy entry has invalid version.

func (*ErrInvalidTXTPolicyRecordVersion) Error

type ErrNotFound

type ErrNotFound struct{}

ErrNotFound literally means "not found".

func (ErrNotFound) Error

func (ErrNotFound) Error() string

type ErrUnknownACMHeaderVersion

type ErrUnknownACMHeaderVersion struct {
	ACHeaderVersion ACModuleHeaderVersion
}

ErrUnknownACMHeaderVersion means ACM entry has invalid header version

func (*ErrUnknownACMHeaderVersion) Error

func (err *ErrUnknownACMHeaderVersion) Error() string

type ErrorEntryPoint

type ErrorEntryPoint uint32

ErrorEntryPoint is the error response entry point offset (bytes)

func (ErrorEntryPoint) Pointer

func (ptr ErrorEntryPoint) Pointer() uint64

Pointer returns the value of ErrorEntryPoint as a pointer which could be used for pointer arithmetics.

type Firmware

type Firmware interface {
	ImageBytes() []byte
	PhysAddrToOffset(physAddr uint64) uint64
}

Firmware is an abstraction from (*uefi.UEFI).

type GDTBasePtr

type GDTBasePtr uint32

GDTBasePtr is the GDT base pointer offset (bytes)

func (GDTBasePtr) Offset

func (ptr GDTBasePtr) Offset() uint64

Offset returns the GDTBasePtr value as a pointer which could be used for pointer arithmetics.

type GDTLimit

type GDTLimit uint32

GDTLimit is the GDT limit (defines last byte of GDT)

type SESVN

type SESVN uint16

SESVN is the Software Guard Extensions (Secure Enclaves) Security Version Number

type SegSel

type SegSel uint32

SegSel is the segment selector initializer

type SizeM16

type SizeM16 uint16

SizeM16 is a size in multiple of 16 bytes (M16).

func (SizeM16) Size

func (size SizeM16) Size() uint

Size returns the size in bytes

func (SizeM16) String

func (size SizeM16) String() string

type SizeM4

type SizeM4 uint32

SizeM4 is a size in multiples of four bytes

func (*SizeM4) SetSize added in v1.1.0

func (size *SizeM4) SetSize(v uint64)

func (SizeM4) Size

func (size SizeM4) Size() uint64

Size return the size in bytes

func (SizeM4) String

func (size SizeM4) String() string

type TXTSVN

type TXTSVN uint16

TXTSVN is the TXT Security Version Number

type Table

type Table []EntryHeaders

Table is the FIT entry headers table (located by the "FIT Pointer"), without data this headers reference to.

func GetTable

func GetTable(firmware []byte) (Table, error)

GetTable returns the table of FIT entries of the firmware image.

func GetTableFrom

func GetTableFrom(firmware io.ReadSeeker) (Table, error)

GetTableFrom returns the table of FIT entries of the firmware image.

func ParseTable

func ParseTable(b []byte) (Table, error)

ParseTable parses a FIT table from `b`.

func (Table) First

func (table Table) First(entryType EntryType) *EntryHeaders

First returns the first entry headers with selected entry type

func (Table) GetEntries

func (table Table) GetEntries(firmware []byte) (result Entries)

GetEntries returns parsed FIT-entries

func (Table) GetEntriesFrom

func (table Table) GetEntriesFrom(firmware io.ReadSeeker) (result Entries)

GetEntriesFrom returns parsed FIT-entries

func (Table) ParseBootPolicyManifest

func (table Table) ParseBootPolicyManifest(firmware []byte) (*bgbootpolicy.Manifest, *cbntbootpolicy.Manifest, error)

ParseBootPolicyManifest returns a boot policy manifest if it was able to parse one.

func (Table) ParseKeyManifest

func (table Table) ParseKeyManifest(firmware []byte) (*bgkey.Manifest, *cbntkey.Manifest, error)

ParseKeyManifest returns a key manifest if it was able to parse one.

func (Table) String

func (table Table) String() string

String prints the fit table in a tabular form

func (Table) Write

func (table Table) Write(b []byte) (n int, err error)

Write compiles FIT headers into a binary representation and writes to "b". If len(b) is less than required, then io.ErrUnexpectedEOF is returned.

func (Table) WriteTo

func (table Table) WriteTo(w io.Writer) (n int64, err error)

WriteTo does the same as Write, but for io.Writer

func (Table) WriteToFirmwareImage

func (table Table) WriteToFirmwareImage(w io.ReadWriteSeeker) (n int64, err error)

WriteToFirmwareImage finds the position of FIT in a firmware image and writes the table there.

type TypeAndIsChecksumValid

type TypeAndIsChecksumValid uint8

TypeAndIsChecksumValid combines two fields:

  • "C_V" -- Checksum Valid bit. This is a one bit field that indicates, whether component has a valid checksum. CPU must ignore "Checksum" field, if C_V bit is not set.
  • EntryType (see "entry_type.go").

func (TypeAndIsChecksumValid) IsChecksumValid

func (f TypeAndIsChecksumValid) IsChecksumValid() bool

IsChecksumValid returns bit "C_V" of the FIT entry.

A quote from the specification: Checksum Valid bit. This is a one bit field that indicates, whether component has a valid checksum. CPU must ignore CHKSUM field, if C_V bit is not set.

func (TypeAndIsChecksumValid) MarshalJSON

func (f TypeAndIsChecksumValid) MarshalJSON() ([]byte, error)

MarshalJSON just implements encoding/json.Marshaler

func (*TypeAndIsChecksumValid) SetIsChecksumValid

func (f *TypeAndIsChecksumValid) SetIsChecksumValid(newValue bool)

SetIsChecksumValid sets the value of field IsChecksumValid ("C_V" of the FIT entry in terms of the specification).

func (*TypeAndIsChecksumValid) SetType

func (f *TypeAndIsChecksumValid) SetType(newType EntryType)

SetType sets the value of field EntryType ("TYPE" of the FIT entry in terms of the specification).

func (TypeAndIsChecksumValid) String

func (f TypeAndIsChecksumValid) String() string

func (TypeAndIsChecksumValid) Type

Type returns field EntryType ("TYPE" of the FIT entry in terms of the specification).

func (*TypeAndIsChecksumValid) UnmarshalJSON

func (f *TypeAndIsChecksumValid) UnmarshalJSON(b []byte) error

UnmarshalJSON just implements encoding/json.Unmarshaler

type Uint24

type Uint24 struct {
	Value [3]byte
}

Uint24 is a 24 bit unsigned little-endian integer value.

func (Uint24) MarshalJSON

func (size Uint24) MarshalJSON() ([]byte, error)

MarshalJSON just implements encoding/json.Marshaler

func (*Uint24) SetUint32

func (size *Uint24) SetUint32(newValue uint32)

SetUint32 sets the value. See also Uint32.

func (Uint24) Uint32

func (size Uint24) Uint32() uint32

Uint32 returns the value as parsed uint32.

If the value is used in "Size" then in the most cases the value should be shifted with "<< 4" to get the real size value.

See also the code of EntryHeaders.getDataCoordinates()

func (*Uint24) UnmarshalJSON

func (size *Uint24) UnmarshalJSON(b []byte) error

UnmarshalJSON just implements encoding/json.Unmarshaler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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