efi

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: LGPL-3.0 Imports: 37 Imported by: 45

Documentation

Index

Constants

View Source
const (
	OSIndicationBootToFWUI                   = uefi.EFI_OS_INDICATIONS_BOOT_TO_FW_UI
	OSIndicationTimestampRevocation          = uefi.EFI_OS_INDICATIONS_TIMESTAMP_REVOCATION
	OSIndicationFileCapsuleDeliverySupported = uefi.EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED
	OSIndicationFMPCapsuleSupported          = uefi.EFI_OS_INDICATIONS_FMP_CAPSULE_SUPPORTED
	OSIndicationCapsuleResultVarSupported    = uefi.EFI_OS_INDICATIONS_CAPSULE_RESULT_VAR_SUPPORTED
	OSIndicationStartOSRecovery              = uefi.EFI_OS_INDICATIONS_START_OS_RECOVERY
	OSIndicationStartPlatformRecovery        = uefi.EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY
	OSIndicationJSONConfigDataRefresh        = uefi.EFI_OS_INDICATIONS_JSON_CONFIG_DATA_REFRESH
)
View Source
const (
	BootOptionSupportKey     = uefi.EFI_BOOT_OPTION_SUPPORT_KEY
	BootOptionSupportApp     = uefi.EFI_BOOT_OPTION_SUPPORT_APP
	BootOptionSupportSysPrep = uefi.EFI_BOOT_OPTION_SUPPORT_SYSPREP
	BootOptionSupportCount   = uefi.EFI_BOOT_OPTION_SUPPORT_COUNT
)

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")
)
View Source
var DefaultVarContext = newDefaultVarContext()

DefaultVarContext should generally be passed to functions that interact with EFI variables in order to use the default system backend for accessing EFI variables. It is based on a new background context.

On Linux, this uses efivarfs. The kernel rate limits unprivileged users' read accesses to the EFI variable runtime service to 100 accesses per second, after which any thread that attempts to perform a read access will sleep in an uninterruptible state. This makes adding a deadline to the context for sections of code that perform multiple variable reads worthwhile in some cases. Unfortunately, there is no way to determine whether an access will be ratelimited before performing it.

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 DeleteBootNextVariable added in v0.9.6

func DeleteBootNextVariable(ctx context.Context) error

DeleteBootNextVariable deletes the option number of the boot entry to try next. In general DefaultVarContext should be supplied to this.

func DeleteLoadOptionVariable added in v0.9.6

func DeleteLoadOptionVariable(ctx context.Context, class LoadOptionClass, n uint16) error

DeleteLoadOptionVariable deletes the load option variable for the specified class and option number. The variable is written to the global namespace. This will succeed even if the variable doesn't alreeady exist. The class must be one of LoadOptionClassDriver, LoadOptionClassSysprep, or LoadOptionClassBoot. In general DefaultVarContext should be supplied to this.

func IsDeployedModeSupported added in v0.9.6

func IsDeployedModeSupported(ctx context.Context) bool

IsDeployedModeSupported indicates whether the firmware is new enough (ie based on at least UEFI 2.5) to support deployed mode. In general, DefaultVarContext should be supplied to this.

func ListLoadOptionNumbers added in v0.9.6

func ListLoadOptionNumbers(ctx context.Context, class LoadOptionClass) ([]uint16, error)

ListLoadOptionNumbers lists the numbers of all of the load option variables for the specified class from the global namespace. The returned numbers will be sorted in ascending order. In general DefaultVarContext should be supplied to this.

func NextAvailableLoadOptionNumber added in v0.9.6

func NextAvailableLoadOptionNumber(ctx context.Context, class LoadOptionClass) (uint16, error)

NextAvailableLoadOptionNumber returns the next available load option number for the specified class, which must be one of LoadOptionClassDriver, LoadOptionClassSysprep, or LoadOptionClassBoot. In general DefaultVarContext should be supplied to this.

func ReadBootCurrentVariable added in v0.9.6

func ReadBootCurrentVariable(ctx context.Context) (uint16, error)

ReadBootCurrentVariable returns the option number used for the current boot. In general DefaultVarContext should be supplied to this.

func ReadBootNextVariable added in v0.9.6

func ReadBootNextVariable(ctx context.Context) (uint16, error)

ReadBootNextVariable returns the option number of the boot entry to try next. In general DefaultVarContext should be supplied to this.

func ReadLoadOrderVariable added in v0.9.6

func ReadLoadOrderVariable(ctx context.Context, class LoadOptionClass) ([]uint16, error)

ReadLoadOrderVariable returns the load option order for the specified class, which must be one of LoadOptionClassDriver, LoadOptionClassSysPrep, or LoadOptionClassBoot. In general DefaultVarContext should be supplied to this.

func ReadPlatformKeyCertificate added in v0.9.7

func ReadPlatformKeyCertificate(ctx context.Context) (*x509.Certificate, error)

ReadPlatformKeyCertificate reads the PK global variable and returns the corresponding certificate, if a platform key is enrolled. If no platform key is enrolled, this will return nil. In general, DefaultVarContext should be supplied to this.

func ReadSecureBootVariable added in v0.9.6

func ReadSecureBootVariable(ctx context.Context) (bool, error)

ReadSecureBootVariable reads the SecureBoot global variable which provides an indication of whether secure boot is enabled. If it returns false, then secure boot is disabled. If it returns true, then it is an indication that secure boot is enabled. In general, DefaultVarContext should be supplied to this.

Note that this function cannot prove that secure boot is enabled. If a platform provides a way to disable secure boot and execute arbitrary code, then the platform or kernel may not tell the truth about this. Obtaining proof that secure boot is enabled would involve the use of attestations and a third party verifier.

func RegisterMediaFvFileNameLookup added in v0.9.9

func RegisterMediaFvFileNameLookup(fn func(GUID) (string, bool))

RegisterMediaFvFileNameLookup registers a function that can map guids to strings for well known names, and these will be displayed by MediaFvFileDevicePathNode.String and MediaFvFileDevicePathNode.ToString if the flags argument is marked as display only. Note that this does make the string representation of the path unparseable, if the string is being used in such a way (this package doesn't yet have any ways of parsing device paths that are in string form).

Just importing github.com/canonical/go-efilib/guids is sufficient to register a function that does this. It's included in a separate and optional package for systems that are concerned about binary size.

func RegisterMediaFvNameLookup added in v1.0.0

func RegisterMediaFvNameLookup(fn func(GUID) (string, bool))

RegisterMediaFvNameLookup registers a function that can map guids to strings for well known names, and these will be displayed by MediaFvDevicePathNode.String and MediaFvDevicePathNode.ToString if the flags argument is marked as display only. Note that this does make the string representation of the path unparseable, if the string is being used in such a way (this package doesn't yet have any ways of parsing device paths that are in string form).

Just importing github.com/canonical/go-efilib/guids is sufficient to register a function that does this. It's included in a separate and optional package for systems that are concerned about binary size.

func WithDefaultVarsBackend added in v1.1.0

func WithDefaultVarsBackend(ctx context.Context) context.Context

WithDefaultVarsBackend adds the default system backend for accesssing EFI variables to an existing context. It allows for usage of any context other than the internally created background one.

On Linux, this uses efivarfs. The kernel rate limits unprivileged users' read accesses to the EFI variable runtime service to 100 accesses per second, after which any thread that attempts to perform a read access will sleep in an uninterruptible state. This makes adding a deadline to the context for sections of code that perform multiple variable reads worthwhile in some cases. Unfortunately, there is no way to determine whether an access will be ratelimited before performing it.

func WriteBootNextVariable added in v0.9.6

func WriteBootNextVariable(ctx context.Context, n uint16) error

WriteBootNextVariable writes the option number of the boot entry to try next. In general DefaultVarContext should be supplied to this.

func WriteLoadOptionVariable added in v0.9.6

func WriteLoadOptionVariable(ctx context.Context, class LoadOptionClass, n uint16, option *LoadOption) error

WriteLoadOptionVariable writes the supplied LoadOption to a variable for the specified class and option number. The variable is written to the global namespace. This will overwrite any variable that already exists. The class must be one of LoadOptionClassDriver, LoadOptionClassSysprep, or LoadOptionClassBoot. In general DefaultVarContext should be supplied to this.

func WriteLoadOrderVariable added in v0.9.6

func WriteLoadOrderVariable(ctx context.Context, class LoadOptionClass, order []uint16) error

WriteLoadOrderVariable writes the load option order for the specified class, which must be one of LoadOptionClassDriver, LoadOptionClassSysprep, or LoadOptionClassBoot. In general DefaultVarContext should be supplied to this.

This will check that each entry corresponds to a valid load option before writing the new order.

func WriteOSIndicationsVariable added in v0.9.6

func WriteOSIndicationsVariable(ctx context.Context, value OSIndications) error

WriteOSIndicationsVariable writes the supplied value to the OsIndications global variable in order to send commands to the firmware for the next boot. In general DefaultVarContext should be supplied to this.

func WriteVariable added in v0.1.2

func WriteVariable(ctx context.Context, 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. In general, DefaultVarContext or the result of WithDefaultVarsBackend should be supplied to this. This will return an error if the context is done.

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 // Compressed hardware ID
	UID uint32 // Unique ID
}

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
}

ACPIExtendedDevicePathNode corresponds to an ACPI device path node and is used where a CID field is required or a string field is required for HID or UID.

func (*ACPIExtendedDevicePathNode) String

func (d *ACPIExtendedDevicePathNode) String() string

func (*ACPIExtendedDevicePathNode) ToString added in v0.3.0

func (*ACPIExtendedDevicePathNode) Write

type ATAPIControllerRole

type ATAPIControllerRole uint8

ATAPIControllerRole describes the port that an IDE device is connected to.

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 // Logical unit number
}

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

ATAPIDriveRole describes the role of a device on a specific IDE port.

const (
	ATAPIDriveMaster ATAPIDriveRole = 0
	ATAPIDriveSlave  ATAPIDriveRole = 1
)

func (ATAPIDriveRole) String added in v0.3.0

func (r ATAPIDriveRole) String() string

type BootOptionSupport added in v0.9.6

type BootOptionSupport uint32

BootOptionSupport provides a way for the firmware to indicate certain boot options that are supported.

func ReadBootOptionSupportVariable added in v0.9.6

func ReadBootOptionSupportVariable(ctx context.Context) (BootOptionSupport, error)

ReadBootOptionSupportVariable returns the value of the BootOptionSupport variable in the global namespace. In general DefaultVarContext should be supplied to this.

func (BootOptionSupport) KeyCount added in v0.9.6

func (s BootOptionSupport) KeyCount() uint8

KeyCount returns the supported number of key presses (up to 3).

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 DevicePathFindFirstOccurrence added in v1.3.0

func DevicePathFindFirstOccurrence[T DevicePathNode](p DevicePath) DevicePath

DevicePathFindFirstOccurrence finds the first occurrence of the device path node with the specified type and returns it and the remaining components of the device path.

func ReadDevicePath

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

ReadDevicePath decodes a device path from the supplied io.Reader. It will read until it finds a termination node or an error occurs.

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) Matches added in v0.9.6

func (p DevicePath) Matches(other DevicePath) DevicePathMatch

Matches indicates whether other matches this path in some way, and returns the type of match. If other is a HD() short-form path, this may return DevicePathShortFormHDMatch. If other is a UsbWwid() short-form path, this may return DevicePathShortFormUSBWWIDMatch. If other is a UsbClass() short-form path, this may return DevicePathShortFormUSBClassMatch. If other is a file path short-form path, this may return DevicePathShortFormFileMatch. This returns DevicePathFullMatch if the supplied path fully matches, and DevicePathNoMatch if there is no match.

func (DevicePath) ShortFormType added in v1.3.1

func (p DevicePath) ShortFormType() DevicePathShortFormType

ShortFormType returns whether this is a short-form type of path, and if so, what type of short-form path. The UEFI boot manager is required to handle a certain set of well defined short-form paths that begin with a specific component.

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 DevicePathMatch added in v0.9.6

type DevicePathMatch int

DevicePathMatch indicates how a device path matched

const (
	// DevicePathNoMatch indicates that a pair of device paths did not match.
	DevicePathNoMatch DevicePathMatch = iota

	// DevicePathFullMatch indicates that a pair of device paths fully matched.
	DevicePathFullMatch

	// DevicePathShortFormHDMatch indicates that one device path begins with a
	// *[HardDriveDevicePathNode] and matches the end of the longer device path.
	DevicePathShortFormHDMatch

	// DevicePathShortFormUSBWWIDMatch indicates that one device path begins with
	// a *[USBWWIDDevicePathNode] and matches the end of the longer device path.
	DevicePathShortFormUSBWWIDMatch

	// DevicePathShortFormUSBClassMatch indicates that one device path begins with
	// a *[USBClassDevicePathNode] and matches the end of the longer device path.
	DevicePathShortFormUSBClassMatch

	// DevicePathShortFormFileMatch indicates that one device path begins with a
	// [FilePathDevicePathNode] and matches the end of the longer device path.
	DevicePathShortFormFileMatch
)

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 DevicePathShortFormType added in v1.3.1

type DevicePathShortFormType int

DevicePathShortFormType describes whether a path is a recognized short-form path, and what type it is.

const (
	// DevicePathNotShortForm indicates that a path is not a recognized short-form path
	DevicePathNotShortForm DevicePathShortFormType = iota

	// DevicePathShortFormHD indicates that a path is a HD() short-form path
	DevicePathShortFormHD

	// DevicePathShortFormUSBWWID indicates that a path is a UsbWwid() short-form path
	DevicePathShortFormUSBWWID

	// DevicePathShortFormUSBClass indicates that a path is a UsbClass() short-form path
	DevicePathShortFormUSBClass

	// DevicePathShortFormURI indicates that a path is a Uri() short-form path. Note that
	// this package does not currently directly support device paths containing URIs.
	DevicePathShortFormURI

	// DevicePathShortFormFilePath indicates that a path is a file path short-form path
	DevicePathShortFormFilePath
)

func (DevicePathShortFormType) IsShortForm added in v1.3.1

func (t DevicePathShortFormType) IsShortForm() bool

type DevicePathSubType

type DevicePathSubType uint8

DevicePathSubType is the sub-type of a device path node. The meaning of this depends on the DevicePathType.

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 corresponds to the SHA1 algorithm.
	HashAlgorithmSHA1Guid GUID = GUID(uefi.EFI_HASH_ALGORITHM_SHA1_GUID)

	// HashAlgorithmSHA256Guid corresponds to the SHA256 algorithm.
	HashAlgorithmSHA256Guid GUID = GUID(uefi.EFI_HASH_ALGORITHM_SHA256_GUID)

	// HashAlgorithmSHA224Guid corresponds to the SHA224 algorithm.
	HashAlgorithmSHA224Guid GUID = GUID(uefi.EFI_HASH_ALGORITHM_SHA224_GUID)

	// HashAlgorithmSHA384Guid corresponds to the SHA384 algorithm.
	HashAlgorithmSHA384Guid GUID = GUID(uefi.EFI_HASH_ALGORITHM_SHA384_GUID)

	// HashAlgorithmSHA412Guid corresponds to the SHA512 algorithm.
	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 list that
	// contains a SHA1 digest.
	CertSHA1Guid GUID = GUID(uefi.EFI_CERT_SHA1_GUID)

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

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

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

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

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

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

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

	// CertX509Guid is used to define the type of a signature list 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 list
	// that contains the SHA-256 digest of the TBS content of a X.509
	// certificate, and a revocation time.
	CertX509SHA256Guid GUID = GUID(uefi.EFI_CERT_X509_SHA256_GUID)

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

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

	// GlobalVariable is the namespace for many variables within the UEFI specification.
	GlobalVariable GUID = GUID(uefi.EFI_GLOBAL_VARIABLE)

	// ImageSecurityDatabaseGuid is the namespace for signature databases defined
	// byt the UEFI specification.
	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

GUIDHardDriveSignature is a HardDriveSignature for GPT drives.

func (GUIDHardDriveSignature) Data added in v0.3.0

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

Data implements [HardDriveSignature.Data].

func (GUIDHardDriveSignature) String added in v0.3.0

func (s GUIDHardDriveSignature) String() string

func (GUIDHardDriveSignature) Type added in v0.3.0

Type implements [HardDriveSignature.Type].

type GenericDevicePathNode added in v0.1.2

type GenericDevicePathNode struct {
	Type    DevicePathType
	SubType DevicePathSubType // the meaning of the sub-type depends on the Type field.
	Data    []byte            // An opaque blob of data associated with this node
}

GenericDevicePathNode corresponds to a device path nodes with a type that is not handled by this package

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             // 1-indexed partition number
	PartitionStart  uint64             // Starting LBA
	PartitionSize   uint64             // Size in number of LBAs
	Signature       HardDriveSignature // Signature,the type of which is implementation specific (GPT vs MBR)
	MBRType         MBRType            // Legacy MBR or GPT
}

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              // the raw signature data
	Type() HardDriveSignatureType // Signature type
}

HardDriveSignature is an abstraction for a unique hard drive identifier

type HardDriveSignatureType added in v0.3.0

type HardDriveSignatureType uint8

func (HardDriveSignatureType) String added in v0.3.0

func (t HardDriveSignatureType) String() string

type InconsistentSecureBootModeError added in v0.9.6

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

InconsistentSecureBootModeError is returned from ComputeSecureBootMode if some of the variables are in an inconsistent state.

func (*InconsistentSecureBootModeError) Error added in v0.9.6

func (*InconsistentSecureBootModeError) Unwrap added in v0.9.6

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 ReadBootNextLoadOptionVariable added in v0.9.6

func ReadBootNextLoadOptionVariable(ctx context.Context) (*LoadOption, error)

ReadBootNextLoadOptionVariable returns the LoadOption for the boot entry to try next. In general DefaultVarContext should be supplied to this.

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 ReadLoadOptionVariable added in v0.9.6

func ReadLoadOptionVariable(ctx context.Context, class LoadOptionClass, n uint16) (*LoadOption, error)

ReadLoadOptionVariable returns the LoadOption for the specified class and option number. The variable is read from the global namespace. In general DefaultVarContext should be supplied to this.

func ReadOrderedLoadOptionVariables added in v0.9.6

func ReadOrderedLoadOptionVariables(ctx context.Context, class LoadOptionClass) ([]*LoadOption, error)

ReadOrderedLoadOptionVariables returns a list of LoadOptions in the order in which they will be tried by the boot manager for the specified class. The variables are all read from the global namespace. Where class is LoadOptionClassDriver, LoadOptionClassSysPrep, or LoadOptionClassBoot, this will use the corresponding *Order variable. It will skip entries for which there isn't a corresponding variable. Where class is LoadOptionClassPlatformRecovery, the order is determined by the variable names. In general DefaultVarContext should be supplied to this.

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) IsActive added in v0.9.6

func (o *LoadOption) IsActive() bool

IsActive indicates whether the attributes has the LOAD_OPTION_ACTIVE flag set. These will be tried automaitcally if they are in BootOrder.

func (*LoadOption) IsAppCategory added in v0.9.6

func (o *LoadOption) IsAppCategory() bool

IsAppCategory indicates whether the attributes has the LOAD_OPTION_CATEGORY_APP flag set.

func (*LoadOption) IsBootCategory added in v0.9.6

func (o *LoadOption) IsBootCategory() bool

IsBootCategory indicates whether the attributes has the LOAD_OPTION_CATEGORY_BOOT flag set. These applications are typically part of the boot process.

func (*LoadOption) IsVisible added in v0.9.6

func (o *LoadOption) IsVisible() bool

IsVisible indicates whether the attributes does not have the LOAD_OPTION_HIDDEN flag set.

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

LoadOptionAttributes corresponds to the attributes of a load option

func (LoadOptionAttributes) IsAppCategory added in v0.9.6

func (a LoadOptionAttributes) IsAppCategory() bool

IsAppCategory indicates whether the attributes has the LOAD_OPTION_CATEGORY_APP flag set.

func (LoadOptionAttributes) IsBootCategory added in v0.9.6

func (a LoadOptionAttributes) IsBootCategory() bool

IsBootCategory indicates whether the attributes has the LOAD_OPTION_CATEGORY_BOOT flag set. These applications are typically part of the boot process.

type LoadOptionClass added in v0.9.6

type LoadOptionClass string

LoadOptionClass describes a class of load option

const (
	// LoadOptionClassDriver corresponds to drivers that are processed before
	// normal boot options and before the initial ready to boot signal.
	LoadOptionClassDriver LoadOptionClass = "Driver"

	// LadOptionClassSysPrep corresponds to system preparation applications that
	// are processed before normal boot options and before the initial
	// ready to boot signal.
	LoadOptionClassSysPrep LoadOptionClass = "SysPrep"

	// LoadOptionClassBoot corresponds to normal boot applicationds.
	LoadOptionClassBoot LoadOptionClass = "Boot"

	// LoadOptionClassPlatformRecovery corresponds to platform supplied recovery
	// applications.
	LoadOptionClassPlatformRecovery LoadOptionClass = "PlatformRecovery"
)

type MBRHardDriveSignature added in v0.3.0

type MBRHardDriveSignature uint32

MBRHardDriveSignature is a HardDriveSignature for legacy MBR drives.

func (MBRHardDriveSignature) Data added in v0.3.0

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

Data implements [HardDriveSignature.Data].

func (MBRHardDriveSignature) String added in v0.3.0

func (s MBRHardDriveSignature) String() string

func (MBRHardDriveSignature) Type added in v0.3.0

Type implements [HardDriveSignature.Type].

type MBRType

type MBRType uint8

MBRType describes a disk header type

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 // Namespace identifier
	NamespaceUUID uint64 // EUI-64 (extended unique identifier). This is set to 0 where not supported
}

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 OSIndications added in v0.9.6

type OSIndications uint64

OSIndications provides a way for the firmware to advertise features to the OS and a way to request the firmware perform a specific action on the next boot.

func ReadOSIndicationsSupportedVariable added in v0.9.6

func ReadOSIndicationsSupportedVariable(ctx context.Context) (OSIndications, error)

ReadOSIndicationsSupportedVariable returns the value of the OSIndicationsSupported variable in the global namespace. In general DefaultVarContext should be supplied to this.

type PCIDevicePathNode

type PCIDevicePathNode struct {
	Function uint8 // Function of device
	Device   uint8 // Device number of PCI bus
}

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 // The zero indexed port number on the HBA
	PortMultiplierPortNumber uint16 // The port multiplier (or 0xFFFF if the device is connected directly to the HBA)
	LUN                      uint16 // Logical unit number
}

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 // Target ID on the SCSI bus
	LUN uint16 // Logical unit number
}

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 SecureBootMode added in v0.9.6

type SecureBootMode int

SecureBootMode describes the secure boot mode of a platform.

const (
	// SetupMode indicates that a platform is in setup mode. In this mode, no platform
	// key is enrolled and secure boot cannot be enabled. Writes to secure boot
	// variables other than PK can be performed without authentication.
	//
	// SetupMode can transition to UserMode by enrolling a platform key, which can be
	// done from the OS by performing a self-signed authenticated write to the PK
	// global variable.
	//
	// Since UEFI 2.5, SetupMode can transition to AuditMode by writing 1 to the
	// AuditMode global variable before ExitBootServices.
	SetupMode SecureBootMode = iota + 1

	// AuditMode indicates that a platform is in audit mode. This mode implies setup
	// mode - no platform key is enrolled and secure boot cannot be enabled. Writes to
	// secure boot variables other than PK can be performed without authentication.
	//
	// AuditMode provides a way of ensuring that the current signature database
	// configuration is able to authenticate an OS without preventing it from booting
	// if authentication fails.
	//
	// AuditMode can transition to DeployedMode by enrolling a platform key, which can be
	// done from the OS by performing a self-signed authenticated write to the PK
	// global variable.
	//
	// AuditMode only exists since UEFI 2.5.
	AuditMode

	// UserMode indicates that a platform is in user mode. In this mode, a platform
	// key is enrolled and secure boot can be enabled (but may be disabled using some
	// platform specific mechanism). Writes to secure boot variables require authentication.
	//
	// UserMode can transition to SetupMode by erasing the platform key, either via
	// some platform specific mechanism or by an authenticated write of an empty payload
	// to the PK global variable.
	//
	// Since UEFI 2.5, UserMode can transition to AuditMode by writing 1 to the AuditMode
	// global variable before ExitBootServices.
	//
	// Since UEFI 2.5, UserMode can transition to DeployedMode by writing 1 to the
	// DeployedMode global variable before ExitBootServices.
	UserMode

	// DeployedMode indicates that a platform is in deployed mode. In this mode, a
	// platform key is enrolled and secure boot can be enabled (but may be disabled using
	// some platform specific mechanism. Writes to secure boot variables require
	// authentication. This is the most secure mode.
	//
	// DeployedMode may transition back to UserMode by some optional platform specific
	// mechanism which clears the DeployedMode variable.
	//
	// DeployedMode exists since UEFI 2.5.
	DeployedMode
)

func ComputeSecureBootMode added in v0.9.6

func ComputeSecureBootMode(ctx context.Context) (SecureBootMode, error)

ComputeSecureBootMode determines the secure boot mode of a platform. In general, DefaultVarContext should be supplied to this.

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 ReadSignatureDatabaseVariable added in v0.9.6

func ReadSignatureDatabaseVariable(ctx context.Context, desc VariableDescriptor) (SignatureDatabase, error)

ReadSignatureDatabaseVariable reads the signature database from the supplied variable. In general, DefaultVarContext should be supplied to this.

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(ctx context.Context, name string, guid GUID) ([]byte, VariableAttributes, error)

ReadVariable returns the value and attributes of the EFI variable with the specified name and GUID. In general, DefaultVarContext or the result of WithDefaultVarsBackend should be supplied to this. This will return an error if the context is done.

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.

var (
	// PKVariable corresponds to the PK global variable
	PKVariable VariableDescriptor = VariableDescriptor{Name: "PK", GUID: GlobalVariable}

	// KEKVariable corresponds to the KEK global variable
	KEKVariable VariableDescriptor = VariableDescriptor{Name: "KEK", GUID: GlobalVariable}

	// DbVariable corresponds to the authorized signature database variable
	DbVariable VariableDescriptor = VariableDescriptor{Name: "db", GUID: ImageSecurityDatabaseGuid}

	// DbxVariable corresponds to the forbidden signature database variable
	DbxVariable VariableDescriptor = VariableDescriptor{Name: "dbx", GUID: ImageSecurityDatabaseGuid}
)

func ListVariables added in v0.1.2

func ListVariables(ctx context.Context) ([]VariableDescriptor, error)

ListVariables returns a sorted list of variables that can be accessed. In general, DefaultVarContext or the result of WithDefaultVarsBackend should be supplied to this. This will return an error if the context is done.

type VarsBackend added in v0.9.6

type VarsBackend interface {
	Get(name string, guid GUID) (VariableAttributes, []byte, error)
	Set(name string, guid GUID, attrs VariableAttributes, data []byte) error
	List() ([]VariableDescriptor, error)
}

VarsBackend is used by the ReadVariable, WriteVariable and ListVariables functions, and indirectly by other functions in this package to abstract access to a specific backend. A default backend is initialized at process initialization and is available via DefaultVarContext.

type VarsBackend2 added in v1.2.0

type VarsBackend2 interface {
	Get(ctx context.Context, name string, guid GUID) (VariableAttributes, []byte, error)
	Set(ctx context.Context, name string, guid GUID, attrs VariableAttributes, data []byte) error
	List(ctx context.Context) ([]VariableDescriptor, error)
}

VarsBackend2 is like VarsBackend only it takes a context that the backend can use for deadlines or cancellation - this is paricularly applicable on systems where there may be multiple writers and writes have to be serialized by the operating system to some degree.

type VarsBackendKey added in v1.0.0

type VarsBackendKey struct{}

VarsBackendKey is used to key a VarsBackend or VarsBackend2 on a context.Context.

type VendorDevicePathNode

type VendorDevicePathNode struct {
	Type DevicePathType // The type of this node
	GUID GUID           // The vendor specific GUID
	Data []byte         // Vendor specific data
}

VendorDevicePathNode corresponds to a vendor specific node.

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 deprecated 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.

Deprecated: use [CertWithIDLikelyTrustAnchor].

func (*WinCertificateAuthenticode) CertWithIDLikelyTrustAnchor added in v1.4.0

func (c *WinCertificateAuthenticode) CertWithIDLikelyTrustAnchor(cert X509CertID) bool

CertWithIDLikelyTrustAnchor 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.

Deprecate: use [CertWithIDLikelyTrustAnchor].

func (*WinCertificatePKCS7) CertWithIDLikelyTrustAnchor added in v1.4.0

func (c *WinCertificatePKCS7) CertWithIDLikelyTrustAnchor(cert X509CertID) bool

CertWithIDLikelyTrustAnchor 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
)

type X509CertID added in v1.4.0

type X509CertID interface {
	Subject() []byte                             // The encoded subject
	SubjectKeyId() []byte                        // The subject key ID
	PublicKeyAlgorithm() x509.PublicKeyAlgorithm // The certificate's public key algorithm

	Issuer() []byte                              // The encoded issuer
	AuthorityKeyId() []byte                      // The authority key ID
	SignatureAlgorithm() x509.SignatureAlgorithm // The algorithm the issuer used to sign the certificate
}

type X509CertID represents the identity of a X.509 certificate.

func NewX509CertIDFromCertificate added in v1.4.0

func NewX509CertIDFromCertificate(cert *x509.Certificate) X509CertID

NewX509CertIDFromCertificate returns a new X509CertID from the supplied certificate.

Directories

Path Synopsis
cmd
Package guids provides a way to map well known firmware volume and file GUIDs to readable names.
Package guids provides a way to map well known firmware volume and file GUIDs to readable names.
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