efi

package module
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2023 License: LGPL-3.0 Imports: 36 Imported by: 41

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCRCCheck        = errors.New("CRC check failed")
	ErrNoProtectiveMBR = errors.New("no protective master boot record found")

	// ErrInvalidBackupPartitionTableLocation may be returned from
	// ReadPartitionTable when called with the BackupPartitionTable
	// role if the partition table isn't located at the end of the
	// device. Note that the function will still return a valid table
	// in this case.
	ErrInvalidBackupPartitionTableLocation = errors.New("backup partition table not located at end of device")

	// UnusedPartitionType is the type GUID of an unused partition entry.
	UnusedPartitionType GUID
)
View Source
var (
	ErrVarsUnavailable = errors.New("no variable backend is available")
	ErrVarNotExist     = errors.New("variable does not exist")
	ErrVarPermission   = errors.New("permission denied")
)

Functions

func ComputePeImageDigest

func ComputePeImageDigest(alg crypto.Hash, r io.ReaderAt, sz int64) ([]byte, error)

ComputePeImageDigest computes the digest of the supplied PE image in accordance with the Authenticode specification, using the specified digest algorithm.

func ConvertUTF16ToUTF8

func ConvertUTF16ToUTF8(in []uint16) string

ConvertUTF16ToUTF8 converts the supplied UTF-16 or UCS2 string to a UTF-8 string. If the supplied string is NULL-terminated, then the NULL termination is removed from the string.

func ConvertUTF8ToUCS2 added in v0.1.2

func ConvertUTF8ToUCS2(in string) []uint16

ConvertUTF8ToUCS2 converts the supplied UTF-8 string to a UCS2 string. Any code point outside of the Basic Multilingual Plane cannot be represented by UCS2 and is converted to the replacement character.

func ConvertUTF8ToUTF16

func ConvertUTF8ToUTF16(in string) []uint16

ConvertUTF8ToUTF16 converts the supplied UTF-8 string to a UTF-16 string.

func WriteVariable added in v0.1.2

func WriteVariable(name string, guid GUID, attrs VariableAttributes, data []byte) error

WriteVariable writes the supplied data value with the specified attributes to the EFI variable with the specified name and GUID.

If the variable already exists, the specified attributes must match the existing attributes with the exception of AttributeAppendWrite.

If the variable does not exist, it will be created.

Types

type ACPIDevicePathNode

type ACPIDevicePathNode struct {
	HID EISAID
	UID uint32
}

ACPIDevicePathNode corresponds to an ACPI device path node.

func (*ACPIDevicePathNode) String

func (d *ACPIDevicePathNode) String() string

func (*ACPIDevicePathNode) ToString added in v0.3.0

func (*ACPIDevicePathNode) Write

func (d *ACPIDevicePathNode) Write(w io.Writer) error

type ACPIExtendedDevicePathNode

type ACPIExtendedDevicePathNode struct {
	HID    EISAID
	UID    uint32
	CID    EISAID
	HIDStr string
	UIDStr string
	CIDStr string
}

func (*ACPIExtendedDevicePathNode) String

func (d *ACPIExtendedDevicePathNode) String() string

func (*ACPIExtendedDevicePathNode) ToString added in v0.3.0

func (*ACPIExtendedDevicePathNode) Write

type ATAPIControllerRole

type ATAPIControllerRole uint8
const (
	ATAPIControllerPrimary   ATAPIControllerRole = 0
	ATAPIControllerSecondary ATAPIControllerRole = 1
)

func (ATAPIControllerRole) String added in v0.3.0

func (r ATAPIControllerRole) String() string

type ATAPIDevicePathNode

type ATAPIDevicePathNode struct {
	Controller ATAPIControllerRole
	Drive      ATAPIDriveRole
	LUN        uint16
}

ATAPIDevicePathNode corresponds to an ATA device path node.

func (*ATAPIDevicePathNode) String

func (d *ATAPIDevicePathNode) String() string

func (*ATAPIDevicePathNode) ToString added in v0.3.0

func (*ATAPIDevicePathNode) Write

func (d *ATAPIDevicePathNode) Write(w io.Writer) error

type ATAPIDriveRole

type ATAPIDriveRole uint8
const (
	ATAPIDriveMaster ATAPIDriveRole = 0
	ATAPIDriveSlave  ATAPIDriveRole = 1
)

func (ATAPIDriveRole) String added in v0.3.0

func (r ATAPIDriveRole) String() string

type CDROMDevicePathNode

type CDROMDevicePathNode struct {
	BootEntry      uint32
	PartitionStart uint64
	PartitionSize  uint64
}

CDROMDevicePathNode corresponds to a CDROM device path node.

func (*CDROMDevicePathNode) String

func (d *CDROMDevicePathNode) String() string

func (*CDROMDevicePathNode) ToString added in v0.3.0

func (*CDROMDevicePathNode) Write

func (d *CDROMDevicePathNode) Write(w io.Writer) error

type DeviceLogicalUnitDevicePathNode

type DeviceLogicalUnitDevicePathNode struct {
	LUN uint8
}

func (*DeviceLogicalUnitDevicePathNode) String

func (*DeviceLogicalUnitDevicePathNode) ToString added in v0.3.0

func (*DeviceLogicalUnitDevicePathNode) Write

type DevicePath

type DevicePath []DevicePathNode

DevicePath represents a complete device path with the first node representing the root.

func ReadDevicePath

func ReadDevicePath(r io.Reader) (out DevicePath, err error)

ReadDevicePath decodes a device path from the supplied io.Reader.

func (DevicePath) Bytes added in v0.2.0

func (p DevicePath) Bytes() ([]byte, error)

Bytes returns the serialized form of this device path.

func (DevicePath) String

func (p DevicePath) String() string

func (DevicePath) ToString added in v0.3.0

func (p DevicePath) ToString(flags DevicePathToStringFlags) string

ToString returns a string representation of this device path with the supplied flags.

func (DevicePath) Write

func (p DevicePath) Write(w io.Writer) error

Write serializes the complete device path to w.

type DevicePathNode

type DevicePathNode interface {
	fmt.Stringer
	ToString(flags DevicePathToStringFlags) string
	Write(w io.Writer) error
}

DevicePathNode represents a single node in a device path.

type DevicePathSubType

type DevicePathSubType uint8

DevicePathSubType is the sub-type of a device path node.

type DevicePathToStringFlags added in v0.3.0

type DevicePathToStringFlags int

DevicePathToStringFlags defines flags for DevicePath.ToString and DevicePathNode.ToString.

const (
	// DevicePathDisplayOnly indicates that each node is converted
	// to the shorter text representation.
	DevicePathDisplayOnly DevicePathToStringFlags = 1 << 0
)

func (DevicePathToStringFlags) DisplayOnly added in v0.3.0

func (f DevicePathToStringFlags) DisplayOnly() bool

type DevicePathType

type DevicePathType uint8

DevicePathType is the type of a device path node.

const (
	HardwareDevicePath  DevicePathType = uefi.HARDWARE_DEVICE_PATH
	ACPIDevicePath      DevicePathType = uefi.ACPI_DEVICE_PATH
	MessagingDevicePath DevicePathType = uefi.MESSAGING_DEVICE_PATH
	MediaDevicePath     DevicePathType = uefi.MEDIA_DEVICE_PATH
	BBSDevicePath       DevicePathType = uefi.BBS_DEVICE_PATH
)

func (DevicePathType) String

func (t DevicePathType) String() string

type EISAID

type EISAID uint32

EISAID represents a compressed EISA PNP ID

func NewEISAID

func NewEISAID(vendor string, product uint16) (EISAID, error)

func (EISAID) Product

func (id EISAID) Product() uint16

Product returns the product ID.

func (EISAID) String

func (id EISAID) String() string

func (EISAID) Vendor

func (id EISAID) Vendor() string

Vendor returns the 3-letter vendor ID.

type FilePathDevicePathNode

type FilePathDevicePathNode string

FilePathDevicePathNode corresponds to a file path device path node.

func NewFilePathDevicePathNode

func NewFilePathDevicePathNode(path string) (out FilePathDevicePathNode)

NewFilePathDevicePathNode constructs a new FilePathDevicePathNode from the supplied path, converting the OS native separators to EFI separators ("\") and prepending a separator to the start of the path if one doesn't already exist.

func (FilePathDevicePathNode) String

func (d FilePathDevicePathNode) String() string

func (FilePathDevicePathNode) ToString added in v0.3.0

func (FilePathDevicePathNode) Write

type GUID

type GUID [16]byte

GUID corresponds to the EFI_GUID type.

var (
	HashAlgorithmSHA1Guid   GUID = GUID(uefi.EFI_HASH_ALGORITHM_SHA1_GUID)
	HashAlgorithmSHA256Guid GUID = GUID(uefi.EFI_HASH_ALGORITHM_SHA256_GUID)
	HashAlgorithmSHA224Guid GUID = GUID(uefi.EFI_HASH_ALGORITHM_SHA224_GUID)
	HashAlgorithmSHA384Guid GUID = GUID(uefi.EFI_HASH_ALGORITHM_SHA384_GUID)
	HashAlgorithmSHA512Guid GUID = GUID(uefi.EFI_HASH_ALGORITHM_SHA512_GUID)

	// CertTypeRSA2048SHA256Guid is used to define the type of a
	// WinCertificateGUID that corresponds to a PKCS#1-v1.5 encoded RSA2048
	// SHA256 signature and is implemented by the *WinCertificateGUIDPKCS1v15
	// type.
	CertTypeRSA2048SHA256Guid GUID = GUID(uefi.EFI_CERT_TYPE_RSA2048_SHA256_GUID)

	// CertTypePKCS7Guid is used to define the type of a WinCertificateGUID
	// that corresponds to a detached PKCS#7 signature and is implemented by
	// the *WinCertificatePKCS7 type.
	CertTypePKCS7Guid GUID = GUID(uefi.EFI_CERT_TYPE_PKCS7_GUID)

	// CertSHA1Guid is used to define the type of a signature that
	// contains a SHA1 digest.
	CertSHA1Guid GUID = GUID(uefi.EFI_CERT_SHA1_GUID)

	// CertSHA256Guid is used to define the type of a signature that
	// contains a SHA-256 digest.
	CertSHA256Guid GUID = GUID(uefi.EFI_CERT_SHA256_GUID)

	// CertSHA224Guid is used to define the type of a signature that
	// contains a SHA-224 digest.
	CertSHA224Guid GUID = GUID(uefi.EFI_CERT_SHA224_GUID)

	// CertSHA384Guid is used to define the type of a signature that
	// contains a SHA-384 digest.
	CertSHA384Guid GUID = GUID(uefi.EFI_CERT_SHA384_GUID)

	// CertSHA512Guid is used to define the type of a signature that
	// contains a SHA-512 digest.
	CertSHA512Guid GUID = GUID(uefi.EFI_CERT_SHA512_GUID)

	// CertRSA2048Guid is used to define the type of a signature that
	// contains a RSA2048 public key.
	CertRSA2048Guid GUID = GUID(uefi.EFI_CERT_RSA2048_GUID)

	// CertRSA2048SHA1Guid is used to define the type of a signature that
	// contains the SHA1 digest of a RSA2048 public key.
	CertRSA2048SHA1Guid GUID = GUID(uefi.EFI_CERT_RSA2048_SHA1_GUID)

	// CertRSA2048SHA256Guid is used to define the type of a signature that
	// contains the SHA-256 digest of a RSA2048 public key.
	CertRSA2048SHA256Guid GUID = GUID(uefi.EFI_CERT_RSA2048_SHA256_GUID)

	// CertX509Guid is used to define the type of a signature that
	// contains a DER encoded X.509 certificate.
	CertX509Guid GUID = GUID(uefi.EFI_CERT_X509_GUID)

	// CertX509SHA256Guid is used to define the type of a signature that
	// contains the SHA-256 digest of the TBS content of a X.509 certificate.
	CertX509SHA256Guid GUID = GUID(uefi.EFI_CERT_X509_SHA256_GUID)

	// CertX509SHA384Guid is used to define the type of a signature that
	// contains the SHA-384 digest of the TBS content of a X.509 certificate.
	CertX509SHA384Guid GUID = GUID(uefi.EFI_CERT_X509_SHA384_GUID)

	// CertX509SHA512Guid is used to define the type of a signature that
	// contains the SHA-512 digest of the TBS content of a X.509 certificate.
	CertX509SHA512Guid GUID = GUID(uefi.EFI_CERT_X509_SHA512_GUID)

	GlobalVariable            GUID = GUID(uefi.EFI_GLOBAL_VARIABLE)
	ImageSecurityDatabaseGuid GUID = GUID(uefi.EFI_IMAGE_SECURITY_DATABASE_GUID)
)

func DecodeGUIDString

func DecodeGUIDString(s string) (GUID, error)

DecodeGUIDString decodes the supplied GUID string. The string must have the format "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" and may be surrounded by curly braces.

func MakeGUID

func MakeGUID(a uint32, b, c, d uint16, e [6]uint8) GUID

MakeGUID makes a new GUID from the supplied arguments.

func ReadGUID

func ReadGUID(r io.Reader) (out GUID, err error)

ReadGUID reads a EFI_GUID from the supplied io.Reader.

func (GUID) A added in v0.1.2

func (guid GUID) A() uint32

func (GUID) B added in v0.1.2

func (guid GUID) B() uint16

func (GUID) C added in v0.1.2

func (guid GUID) C() uint16

func (GUID) D added in v0.1.2

func (guid GUID) D() uint16

func (GUID) E added in v0.1.2

func (guid GUID) E() [6]uint8

func (GUID) String

func (guid GUID) String() string

type GUIDHardDriveSignature added in v0.3.0

type GUIDHardDriveSignature GUID

func (GUIDHardDriveSignature) Data added in v0.3.0

func (s GUIDHardDriveSignature) Data() (out [16]uint8)

func (GUIDHardDriveSignature) String added in v0.3.0

func (s GUIDHardDriveSignature) String() string

func (GUIDHardDriveSignature) Type added in v0.3.0

type GenericDevicePathNode added in v0.1.2

type GenericDevicePathNode struct {
	Type    DevicePathType
	SubType DevicePathSubType
	Data    []byte
}

GenericDevicePathNode corresponds to a device path nodes with an unhandled type.

func (*GenericDevicePathNode) String added in v0.1.2

func (d *GenericDevicePathNode) String() string

func (*GenericDevicePathNode) ToString added in v0.3.0

func (*GenericDevicePathNode) Write added in v0.1.2

func (d *GenericDevicePathNode) Write(w io.Writer) error

type HardDriveDevicePathNode

type HardDriveDevicePathNode struct {
	PartitionNumber uint32
	PartitionStart  uint64
	PartitionSize   uint64
	Signature       HardDriveSignature
	MBRType         MBRType
}

HardDriveDevicePathNode corresponds to a hard drive device path node.

func NewHardDriveDevicePathNodeFromDevice

func NewHardDriveDevicePathNodeFromDevice(r io.ReaderAt, totalSz, blockSz int64, part int) (*HardDriveDevicePathNode, error)

NewHardDriveDevicePathNodeFromDevice constructs a HardDriveDevicePathNode for the specified partition on the supplied device reader. The device's total size and logical block size must be supplied.

func (*HardDriveDevicePathNode) String

func (d *HardDriveDevicePathNode) String() string

func (*HardDriveDevicePathNode) ToString added in v0.3.0

func (*HardDriveDevicePathNode) Write

func (d *HardDriveDevicePathNode) Write(w io.Writer) error

type HardDriveSignature added in v0.3.0

type HardDriveSignature interface {
	fmt.Stringer
	Data() [16]uint8
	Type() HardDriveSignatureType
}

type HardDriveSignatureType added in v0.3.0

type HardDriveSignatureType uint8

func (HardDriveSignatureType) String added in v0.3.0

func (t HardDriveSignatureType) String() string

type InvalidGPTHeaderError

type InvalidGPTHeaderError string

func (InvalidGPTHeaderError) Error

func (e InvalidGPTHeaderError) Error() string

type LBA

type LBA uint64

LBA corresponds to the EFI_LBA type.

type LoadOption

type LoadOption struct {
	Attributes   LoadOptionAttributes
	Description  string
	FilePath     DevicePath
	OptionalData []byte
}

LoadOption corresponds to the EFI_LOAD_OPTION type.

func ReadLoadOption

func ReadLoadOption(r io.Reader) (out *LoadOption, err error)

ReadLoadOption reads a LoadOption from the supplied io.Reader. Due to the way that EFI_LOAD_OPTION is defined, where there is no size encoded for the OptionalData field, this function will consume all of the bytes available from the supplied reader.

func (*LoadOption) Bytes added in v0.2.0

func (o *LoadOption) Bytes() ([]byte, error)

Bytes returns the serialized form of this load option.

func (*LoadOption) String

func (o *LoadOption) String() string

func (*LoadOption) Write

func (o *LoadOption) Write(w io.Writer) error

Write serializes this load option to the supplied io.Writer.

type LoadOptionAttributes added in v0.1.2

type LoadOptionAttributes uint32

func (LoadOptionAttributes) Category added in v0.1.2

type MBRHardDriveSignature added in v0.3.0

type MBRHardDriveSignature uint32

func (MBRHardDriveSignature) Data added in v0.3.0

func (s MBRHardDriveSignature) Data() (out [16]uint8)

func (MBRHardDriveSignature) String added in v0.3.0

func (s MBRHardDriveSignature) String() string

func (MBRHardDriveSignature) Type added in v0.3.0

type MBRType

type MBRType uint8
const (
	LegacyMBR MBRType = 1
	GPT               = 2
)

func (MBRType) String added in v0.3.0

func (t MBRType) String() string

type MediaFvDevicePathNode

type MediaFvDevicePathNode GUID

MediaFvDevicePathNode corresponds to a firmware volume device path node.

func (MediaFvDevicePathNode) String

func (d MediaFvDevicePathNode) String() string

func (MediaFvDevicePathNode) ToString added in v0.3.0

func (MediaFvDevicePathNode) Write

func (d MediaFvDevicePathNode) Write(w io.Writer) error

type MediaFvFileDevicePathNode

type MediaFvFileDevicePathNode GUID

MediaFvFileDevicePathNode corresponds to a firmware volume file device path node.

func (MediaFvFileDevicePathNode) String

func (d MediaFvFileDevicePathNode) String() string

func (MediaFvFileDevicePathNode) ToString added in v0.3.0

func (MediaFvFileDevicePathNode) Write

type MediaRelOffsetRangeDevicePathNode

type MediaRelOffsetRangeDevicePathNode struct {
	StartingOffset uint64
	EndingOffset   uint64
}

func (*MediaRelOffsetRangeDevicePathNode) String

func (*MediaRelOffsetRangeDevicePathNode) ToString added in v0.3.0

func (*MediaRelOffsetRangeDevicePathNode) Write

type NVMENamespaceDevicePathNode

type NVMENamespaceDevicePathNode struct {
	NamespaceID   uint32
	NamespaceUUID uint64
}

NVMENamespaceDevicePathNode corresponds to a NVME namespace device path node.

func (*NVMENamespaceDevicePathNode) String

func (d *NVMENamespaceDevicePathNode) String() string

func (*NVMENamespaceDevicePathNode) ToString added in v0.3.0

func (*NVMENamespaceDevicePathNode) Write

type PCIDevicePathNode

type PCIDevicePathNode struct {
	Function uint8
	Device   uint8
}

PCIDevicePathNode corresponds to a PCI device path node.

func (*PCIDevicePathNode) String

func (d *PCIDevicePathNode) String() string

func (*PCIDevicePathNode) ToString added in v0.3.0

func (*PCIDevicePathNode) Write

func (d *PCIDevicePathNode) Write(w io.Writer) error

type PartitionEntry

type PartitionEntry struct {
	PartitionTypeGUID   GUID
	UniquePartitionGUID GUID
	StartingLBA         LBA
	EndingLBA           LBA
	Attributes          uint64
	PartitionName       string
}

PartitionEntry corresponds to the EFI_PARTITION_ENTRY type.

func ReadPartitionEntries

func ReadPartitionEntries(r io.Reader, num, sz uint32) ([]*PartitionEntry, error)

ReadPartitionEntries reads the specified number of EFI_PARTITION_ENTRY structures of the specified size from the supplied io.Reader. The number and size are typically defined by the partition table header.

func ReadPartitionEntry

func ReadPartitionEntry(r io.Reader) (*PartitionEntry, error)

ReadPartitionEntry reads a single EFI_PARTITION_ENTRY from r.

func (*PartitionEntry) String

func (e *PartitionEntry) String() string

func (*PartitionEntry) Write

func (e *PartitionEntry) Write(w io.Writer) error

Write serializes this PartitionEntry to w. Note that it doesn't write any bytes beyond the end of the EFI_PARTITION_ENTRY structure, so if the caller is writing several entries and the partition table header defines an entry size of greater than 128 bytes, the caller is responsible for inserting the 0 padding bytes.

type PartitionTable

type PartitionTable struct {
	Hdr     *PartitionTableHeader
	Entries []*PartitionEntry
}

PartitionTable describes a complete GUID partition table.

func ReadPartitionTable

func ReadPartitionTable(r io.ReaderAt, totalSz, blockSz int64, role PartitionTableRole, checkCrc bool) (*PartitionTable, error)

ReadPartitionTable reads a complete GUID partition table from the supplied io.Reader. The total size and logical block size of the device must be supplied - the logical block size is 512 bytes for a file, but must be obtained from the kernel for a block device.

This function expects the device to have a valid protective MBR.

If role is PrimaryPartitionTable, this will read the primary partition table that is located immediately after the protective MBR. If role is BackupPartitionTable, this will read the backup partition table that is located at the end of the device.

If checkCrc is true and either CRC check fails for the requested table, an error will be returned. Setting checkCrc to false disables the CRC checks.

Note that whilst this function checks the integrity of the header and partition table entries, it does not check the contents of the partition table entries.

If role is BackupPartitionTable and the backup table is not located at the end of the device, this will return ErrInvalidBackupPartitionTableLocation along with the valid table.

func (*PartitionTable) String added in v0.4.0

func (t *PartitionTable) String() string

type PartitionTableHeader

type PartitionTableHeader struct {
	HeaderSize               uint32
	MyLBA                    LBA
	AlternateLBA             LBA
	FirstUsableLBA           LBA
	LastUsableLBA            LBA
	DiskGUID                 GUID
	PartitionEntryLBA        LBA
	NumberOfPartitionEntries uint32
	SizeOfPartitionEntry     uint32
	PartitionEntryArrayCRC32 uint32
}

PartitionTableHeader correponds to the EFI_PARTITION_TABLE_HEADER type.

func ReadPartitionTableHeader

func ReadPartitionTableHeader(r io.Reader, checkCrc bool) (*PartitionTableHeader, error)

ReadPartitionTableHeader reads a EFI_PARTITION_TABLE_HEADER from the supplied io.Reader. If the header signature or revision is incorrect, an error will be returned. If checkCrc is true and the header has an invalid CRC, an error will be returned. If checkCrc is false, then a CRC check is not performed.

func (*PartitionTableHeader) String added in v0.4.0

func (h *PartitionTableHeader) String() string

func (*PartitionTableHeader) Write

func (h *PartitionTableHeader) Write(w io.Writer) error

Write serializes this PartitionTableHeader to w. The CRC field is computed automatically.

type PartitionTableRole

type PartitionTableRole int

PartitionTableRole describes the role of a partition table.

const (
	PrimaryPartitionTable PartitionTableRole = iota
	BackupPartitionTable
)

type PhysicalAddress

type PhysicalAddress uint64

type SATADevicePathNode

type SATADevicePathNode struct {
	HBAPortNumber            uint16
	PortMultiplierPortNumber uint16
	LUN                      uint16
}

SATADevicePathNode corresponds to a SATA device path node.

func (*SATADevicePathNode) String

func (d *SATADevicePathNode) String() string

func (*SATADevicePathNode) ToString added in v0.3.0

func (*SATADevicePathNode) Write

func (d *SATADevicePathNode) Write(w io.Writer) error

type SCSIDevicePathNode

type SCSIDevicePathNode struct {
	PUN uint16
	LUN uint16
}

SCSIDevicePathNode corresponds to a SCSI device path node.

func (*SCSIDevicePathNode) String

func (d *SCSIDevicePathNode) String() string

func (*SCSIDevicePathNode) ToString added in v0.3.0

func (*SCSIDevicePathNode) Write

func (d *SCSIDevicePathNode) Write(w io.Writer) error

type SignatureData

type SignatureData struct {
	Owner GUID
	Data  []byte
}

SignatureData corresponds to the EFI_SIGNATURE_DATA type.

func (*SignatureData) Equal

func (d *SignatureData) Equal(other *SignatureData) bool

Equal determines whether other is equal to this SignatureData

func (*SignatureData) Write

func (d *SignatureData) Write(w io.Writer) error

Write serializes this signature data to w.

type SignatureDatabase

type SignatureDatabase []*SignatureList

SignatureDatabase corresponds to a list of EFI_SIGNATURE_LIST structures.

func ReadSignatureDatabase

func ReadSignatureDatabase(r io.Reader) (SignatureDatabase, error)

ReadSignatureDatabase decodes a list of EFI_SIGNATURE_LIST structures from r.

func (SignatureDatabase) Bytes added in v0.2.0

func (db SignatureDatabase) Bytes() ([]byte, error)

Bytes returns the serialized form of this signature database.

func (SignatureDatabase) String

func (db SignatureDatabase) String() string

func (SignatureDatabase) Write

func (db SignatureDatabase) Write(w io.Writer) error

Write serializes this signature database to w.

type SignatureList

type SignatureList struct {
	Type       GUID
	Header     []byte
	Signatures []*SignatureData
}

SignatureList corresponds to the EFI_SIGNATURE_LIST type.

func ReadSignatureList

func ReadSignatureList(r io.Reader) (*SignatureList, error)

ReadSignatureList decodes a single EFI_SIGNATURE_LIST from r.

func (*SignatureList) String

func (l *SignatureList) String() string

func (*SignatureList) Write

func (l *SignatureList) Write(w io.Writer) error

Write serializes this signature list to w.

type USBClass

type USBClass uint8
const (
	USBClassAudio       USBClass = 0x01
	USBClassCDCControl  USBClass = 0x02
	USBClassHID         USBClass = 0x03
	USBClassImage       USBClass = 0x06
	USBClassPrinter     USBClass = 0x07
	USBClassMassStorage USBClass = 0x08
	USBClassHub         USBClass = 0x09
	USBClassCDCData     USBClass = 0x0a
	USBClassSmartCard   USBClass = 0x0b
	USBClassVideo       USBClass = 0x0e
	USBClassDiagnostic  USBClass = 0xdc
	USBClassWireless    USBClass = 0xe0
)

type USBClassDevicePathNode

type USBClassDevicePathNode struct {
	VendorId       uint16
	ProductId      uint16
	DeviceClass    USBClass
	DeviceSubClass uint8
	DeviceProtocol uint8
}

USBClassDevicePathNode corresponds to a USB class device path node.

func (*USBClassDevicePathNode) String

func (d *USBClassDevicePathNode) String() string

func (*USBClassDevicePathNode) ToString added in v0.3.0

func (*USBClassDevicePathNode) Write

func (d *USBClassDevicePathNode) Write(w io.Writer) error

type USBDevicePathNode

type USBDevicePathNode struct {
	ParentPortNumber uint8
	InterfaceNumber  uint8
}

USBDevicePathNode corresponds to a USB device path node.

func (*USBDevicePathNode) String

func (d *USBDevicePathNode) String() string

func (*USBDevicePathNode) ToString added in v0.3.0

func (*USBDevicePathNode) Write

func (d *USBDevicePathNode) Write(w io.Writer) error

type USBWWIDDevicePathNode

type USBWWIDDevicePathNode struct {
	InterfaceNumber uint16
	VendorId        uint16
	ProductId       uint16
	SerialNumber    string
}

USBWWIDDevicePathNode corresponds to a USB WWID device path node.

func (*USBWWIDDevicePathNode) String

func (d *USBWWIDDevicePathNode) String() string

func (*USBWWIDDevicePathNode) ToString added in v0.3.0

func (*USBWWIDDevicePathNode) Write

func (d *USBWWIDDevicePathNode) Write(w io.Writer) error

type VariableAttributes

type VariableAttributes uint32

func ReadVariable added in v0.1.2

func ReadVariable(name string, guid GUID) ([]byte, VariableAttributes, error)

ReadVariable returns the value and attributes of the EFI variable with the specified name and GUID.

type VariableAuthentication

type VariableAuthentication struct {
	MonotonicCount uint64
	AuthInfo       WinCertificateGUID
}

VariableAuthentication corresponds to the EFI_VARIABLE_AUTHENTICATION type and is used to authenticate updates to variables with the EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS attribute set.

func ReadVariableAuthentication

func ReadVariableAuthentication(r io.Reader) (*VariableAuthentication, error)

ReadVariableAuthentication decodes an authentication header for updating a variable with the EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS attribute set.

type VariableAuthentication2

type VariableAuthentication2 struct {
	TimeStamp time.Time
	AuthInfo  WinCertificateGUID
}

VariableAuthentication2 corresponds to the EFI_VARIABLE_AUTHENTICATION_2 type and is used to authenticate updates to variables with the EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute set.

func ReadTimeBasedVariableAuthentication

func ReadTimeBasedVariableAuthentication(r io.Reader) (*VariableAuthentication2, error)

ReadTimeBasedVariableAuthentication decodes an authentication header for updating a variable with the EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute set.

type VariableAuthentication3

type VariableAuthentication3 interface {
	Type() VariableAuthentication3Type
	NewCert() WinCertificateGUID
	SigningCert() WinCertificateGUID
}

VariableAuthentication3 is used to authenticate updates to variables with the EFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS attribute set.

func ReadEnhancedVariableAuthentication

func ReadEnhancedVariableAuthentication(r io.Reader) (VariableAuthentication3, error)

ReadEnhancedVariableAuthentication decodes the authentication header for updating variables with the EFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS attribute set.

type VariableAuthentication3CertId

type VariableAuthentication3CertId interface {
	// Matches determines whether the specified certificate matches this ID
	Matches(cert *x509.Certificate) bool
}

VariableAuthentication3CertId corresponds to the EFI_VARIABLE_AUTHENTICATION_3_CERT_ID type and represents the identification of an authority certificate associated with a variable that has the EFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS attribute set.

type VariableAuthentication3CertIdSHA256 added in v0.9.0

type VariableAuthentication3CertIdSHA256 [32]byte

VariableAuthentication3CertIdSHA256 corresponds to a EFI_VARIABLE_AUTHENTICATION_3_CERT_ID with a type of EFI_VARIABLE_AUTHENTICATION_3_CERT_ID_SHA256 and is the SHA-256 digest of the TBS content of a X.509 certificate.

func (VariableAuthentication3CertIdSHA256) Matches added in v0.9.0

type VariableAuthentication3Descriptor

type VariableAuthentication3Descriptor interface {
	Type() VariableAuthentication3Type
	Id() VariableAuthentication3CertId // The ID of the authority associated with the variable
}

VariableAuthentication3Descriptor corresponds to the authentication descriptor provided when reading the payload of a variable with the EFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS attribute set.

func ReadEnhancedAuthenticationDescriptor

func ReadEnhancedAuthenticationDescriptor(r io.Reader) (VariableAuthentication3Descriptor, error)

ReadEnhancedAuthenticationDescriptor decodes the enhanced authentication descriptor from the supplied reader. The supplied reader will typically read from the payload area of a variable with the EFI_VARIABLE_ENHANCED_AUTHENTICATION_ACCESS attribute set.

type VariableAuthentication3Nonce

type VariableAuthentication3Nonce struct {
	Nonce []byte
	// contains filtered or unexported fields
}

VariableAuthentication3Nonce is used to authenticate updates to variables with the EFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS attribute set, and a type of EFI_VARIABLE_AUTHENTICATION_3_NONCE_TYPE.

func (*VariableAuthentication3Nonce) NewCert

func (a *VariableAuthentication3Nonce) NewCert() WinCertificateGUID

func (*VariableAuthentication3Nonce) SigningCert

func (a *VariableAuthentication3Nonce) SigningCert() WinCertificateGUID

func (*VariableAuthentication3Nonce) Type added in v0.9.0

type VariableAuthentication3NonceDescriptor

type VariableAuthentication3NonceDescriptor struct {
	Nonce []byte
	// contains filtered or unexported fields
}

VariableAuthentication3NonceDescriptor corresponds to the authentication descriptor provided when reading the payload of a variable with the EFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS attribute set, and a type of EFI_VARIABLE_AUTHENTICATION_3_NONCE_TYPE.

func (*VariableAuthentication3NonceDescriptor) Id added in v0.9.0

func (*VariableAuthentication3NonceDescriptor) Type added in v0.9.0

type VariableAuthentication3Timestamp

type VariableAuthentication3Timestamp struct {
	Timestamp time.Time
	// contains filtered or unexported fields
}

VariableAuthentication3Timestamp is used to authenticate updates to variables with the EFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS attribute set, and a type of EFI_VARIABLE_AUTHENTICATION_3_TIMESTAMP_TYPE.

func (*VariableAuthentication3Timestamp) NewCert

func (a *VariableAuthentication3Timestamp) NewCert() WinCertificateGUID

func (*VariableAuthentication3Timestamp) SigningCert

func (a *VariableAuthentication3Timestamp) SigningCert() WinCertificateGUID

func (*VariableAuthentication3Timestamp) Type added in v0.9.0

type VariableAuthentication3TimestampDescriptor

type VariableAuthentication3TimestampDescriptor struct {
	TimeStamp time.Time
	// contains filtered or unexported fields
}

VariableAuthentication3TimestampDescriptor corresponds to the authentication descriptor provided when reading the payload of a variable with the EFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS attribute set, and a type of EFI_VARIABLE_AUTHENTICATION_3_TIMESTAMP_TYPE.

func (*VariableAuthentication3TimestampDescriptor) Id added in v0.9.0

func (*VariableAuthentication3TimestampDescriptor) Type added in v0.9.0

type VariableAuthentication3Type added in v0.9.0

type VariableAuthentication3Type int

VariableAuthentication3Type describes the type of VariableAuthentication3.

const (
	// VariableAuthentication3TimestampType indicates that a
	// VariableAuthentication3 is a timestamp based enhanced authentication
	// and is implemented by the *VariableAuthentication3Timestamp type.
	VariableAuthentication3TimestampType VariableAuthentication3Type = uefi.EFI_VARIABLE_AUTHENTICATION_3_TIMESTAMP_TYPE

	// VariableAuthentication3iNonceType indicates that a
	// VariableAuthentication3 is a nonce based enhanced authentication
	// and is implemented by the *VariableAuthentication3Nonce type.
	VariableAuthentication3NonceType VariableAuthentication3Type = uefi.EFI_VARIABLE_AUTHENTICATION_3_NONCE_TYPE
)

type VariableDescriptor added in v0.1.2

type VariableDescriptor struct {
	Name string
	GUID GUID
}

VariableDescriptor represents the identity of a variable.

func ListVariables added in v0.1.2

func ListVariables() ([]VariableDescriptor, error)

ListVariables returns a list of variables that can be accessed.

type VendorDevicePathNode

type VendorDevicePathNode struct {
	Type DevicePathType
	GUID GUID
	Data []byte
}

func (*VendorDevicePathNode) String

func (d *VendorDevicePathNode) String() string

func (*VendorDevicePathNode) ToString added in v0.3.0

func (*VendorDevicePathNode) Write

func (d *VendorDevicePathNode) Write(w io.Writer) error

type WinCertificate

type WinCertificate interface {
	Type() WinCertificateType // Type of this certificate
}

WinCertificate is an interface type corresponding to implementations of WIN_CERTIFICATE.

func ReadWinCertificate

func ReadWinCertificate(r io.Reader) (WinCertificate, error)

ReadWinCertificate decodes a signature (something that is confusingly represented by types with "certificate" in the name in both the UEFI and PE/COFF specifications) from the supplied reader and returns a WinCertificate of the appropriate type. The type returned is dependent on the data, and will be one of *WinCertificateAuthenticode, *WinCertificatePKCS1v15, *WinCertificatePKCS7 or *WinCertificateGUIDPKCS1v15.

type WinCertificateAuthenticode

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

WinCertificateAuthenticode corresponds to a WIN_CERTIFICATE_EFI_PKCS and represents an Authenticode signature.

func (*WinCertificateAuthenticode) CertLikelyTrustAnchor added in v0.9.2

func (c *WinCertificateAuthenticode) CertLikelyTrustAnchor(cert *x509.Certificate) bool

CertLikelyTrustAnchor determines if the specified certificate is likely to be a trust anchor for this signature. This is "likely" because it only checks if there are candidate certificate chains rooted to the specified certificate. When attempting to build candidate certificate chains, it considers a certificate to be likely issued by another certificate if:

  • The certificate's issuer matches the issuer's subject.
  • The certificate's Authority Key Identifier keyIdentifier field matches the issuer's Subject Key Identifier.
  • The certificate's signature algorithm is compatible with the issuer's public key algorithm.

It performs no verification of any candidate certificate chains and no verification of the signature.

func (*WinCertificateAuthenticode) Digest added in v0.9.0

func (c *WinCertificateAuthenticode) Digest() []byte

Digest returns the PE image digest of the image associated with this signature.

func (*WinCertificateAuthenticode) DigestAlgorithm added in v0.9.0

func (c *WinCertificateAuthenticode) DigestAlgorithm() crypto.Hash

func (*WinCertificateAuthenticode) GetSigner added in v0.9.0

GetSigner returns the signing certificate.

func (*WinCertificateAuthenticode) Type added in v0.9.0

type WinCertificateGUID

type WinCertificateGUID interface {
	WinCertificate
	GUIDType() GUID
}

WinCertificateGUID corresponds to implementations of WIN_CERTIFICATE_UEFI_GUID.

type WinCertificateGUIDPKCS1v15 added in v0.9.0

type WinCertificateGUIDPKCS1v15 struct {
	PublicKey [256]byte
	Signature [256]byte
}

WinCertificateGUIDPKCS1v15 corresponds to a WIN_CERTIFICATE_UEFI_GUID with the EFI_CERT_TYPE_RSA2048_SHA256_GUID type, and represents a RSA2048 SHA256 signature with PKCS#1 v1.5 padding

func (*WinCertificateGUIDPKCS1v15) GUIDType added in v0.9.0

func (c *WinCertificateGUIDPKCS1v15) GUIDType() GUID

func (*WinCertificateGUIDPKCS1v15) Type added in v0.9.0

type WinCertificateGUIDUnknown added in v0.9.0

type WinCertificateGUIDUnknown struct {
	Data []byte
	// contains filtered or unexported fields
}

WinCertificateGUIDUnknown corresponds to a WIN_CERTIFICATE_UEFI_GUID with an unknown type.

func (*WinCertificateGUIDUnknown) GUIDType added in v0.9.0

func (c *WinCertificateGUIDUnknown) GUIDType() GUID

func (*WinCertificateGUIDUnknown) Type added in v0.9.0

type WinCertificatePKCS1v15 added in v0.1.2

type WinCertificatePKCS1v15 struct {
	HashAlgorithm crypto.Hash
	Signature     [256]byte
}

WinCertificatePKCS1v15 corresponds to the WIN_CERTIFICATE_EFI_PKCS1_15 type and represents a RSA2048 signature with PKCS#1 v1.5 padding.

func (*WinCertificatePKCS1v15) Type added in v0.9.0

type WinCertificatePKCS7 added in v0.9.0

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

WinCertificatePKCS7 corresponds to a WIN_CERTIFICATE_UEFI_GUID with the EFI_CERT_TYPE_PKCS7_GUID type, and represents a detached PKCS7 signature.

func (*WinCertificatePKCS7) CertLikelyTrustAnchor added in v0.9.2

func (c *WinCertificatePKCS7) CertLikelyTrustAnchor(cert *x509.Certificate) bool

CertLikelyTrustAnchor determines if the specified certificate is likely to be a trust anchor for this signature. This is "likely" because it only checks if there are candidate certificate chains rooted to the specified certificate. When attempting to build candidate certificate chains, it considers a certificate to be likely issued by another certificate if:

  • The certificate's issuer matches the issuer's subject.
  • The certificate's Authority Key Identifier keyIdentifier field matches the issuer's Subject Key Identifier.
  • The certificate's signature algorithm is compatible with the issuer's public key algorithm.

It performs no verification of any candidate certificate chains and no verification of the signature.

func (*WinCertificatePKCS7) GUIDType added in v0.9.0

func (c *WinCertificatePKCS7) GUIDType() GUID

func (*WinCertificatePKCS7) GetSigners added in v0.9.0

func (c *WinCertificatePKCS7) GetSigners() []*x509.Certificate

GetSigners returns the signing certificates.

func (*WinCertificatePKCS7) Type added in v0.9.0

type WinCertificateType added in v0.9.0

type WinCertificateType uint16
const (
	// WinCertificateTypeAuthenticode indicates that a WinCertificate
	// is an authenticode signature and is implemented by the
	// *WinCertificateAuthenticode type.
	WinCertificateTypeAuthenticode WinCertificateType = uefi.WIN_CERT_TYPE_PKCS_SIGNED_DATA

	// WinCertificatePKCS1v15 indicates that a WinCertificate is a
	// PKCS#1-v1.5 encoded RSA2048 signature and is implemented by
	// the *WinCertificatePKCS1v15 type.
	WinCertificateTypePKCS1v15 WinCertificateType = uefi.WIN_CERT_TYPE_EFI_PKCS115

	// WinCertificateTypeGUID indicates that a WinCertificate is a
	// signature of a type indicated by a separate GUID and is implemented
	// by a type that implements the WinCertificateGUID interface.
	WinCertificateTypeGUID WinCertificateType = uefi.WIN_CERT_TYPE_EFI_GUID
)

Directories

Path Synopsis
cmd
internal
pe1.14
Package pe implements access to PE (Microsoft Windows Portable Executable) files.
Package pe implements access to PE (Microsoft Windows Portable Executable) files.

Jump to

Keyboard shortcuts

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