TianoCore EDK2 master
Loading...
Searching...
No Matches
SecureBootVariableLib.c File Reference

Go to the source code of this file.

Functions

STATIC EFI_STATUS CreateSigList (IN VOID *Data, IN UINTN Size, OUT EFI_SIGNATURE_LIST **SigList)
 
STATIC EFI_STATUS ConcatenateSigList (IN EFI_SIGNATURE_LIST *SigLists, IN EFI_SIGNATURE_LIST *SigListAppend, OUT EFI_SIGNATURE_LIST **SigListOut, IN OUT UINTN *SigListsSize)
 
EFI_STATUS EFIAPI SecureBootCreateDataFromInput (OUT UINTN *SigListsSize, OUT EFI_SIGNATURE_LIST **SigListOut, IN UINTN KeyInfoCount, IN CONST SECURE_BOOT_CERTIFICATE_INFO *KeyInfo)
 
EFI_STATUS EFIAPI CreateTimeBasedPayload (IN OUT UINTN *DataSize, IN OUT UINT8 **Data, IN EFI_TIME *Time)
 
EFI_STATUS EFIAPI DeleteVariable (IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid)
 
EFI_STATUS EFIAPI SetSecureBootMode (IN UINT8 SecureBootMode)
 
EFI_STATUS EFIAPI GetSetupMode (OUT UINT8 *SetupMode)
 
BOOLEAN EFIAPI IsSecureBootEnabled (VOID)
 
EFI_STATUS EFIAPI DeleteDb (VOID)
 
EFI_STATUS EFIAPI DeleteDbx (VOID)
 
EFI_STATUS EFIAPI DeleteDbt (VOID)
 
EFI_STATUS EFIAPI DeleteKEK (VOID)
 
EFI_STATUS EFIAPI DeletePlatformKey (VOID)
 
EFI_STATUS EFIAPI DeleteSecureBootVariables (VOID)
 
EFI_STATUS EFIAPI EnrollFromInput (IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINTN DataSize, IN VOID *Data)
 
EFI_STATUS EFIAPI SetSecureBootVariablesToDefault (IN CONST SECURE_BOOT_PAYLOAD_INFO *SecureBootPayload)
 

Variables

EFI_TIME mMaxTimestamp
 
EFI_TIME mDefaultPayloadTimestamp
 

Detailed Description

This library provides helper functions to set/clear Secure Boot keys and databases.

Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.
(C) Copyright 2018 Hewlett Packard Enterprise Development LP
Copyright (c) 2021, ARM Ltd. All rights reserved.
Copyright (c) 2021, Semihalf All rights reserved.
Copyright (c) Microsoft Corporation. SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file SecureBootVariableLib.c.

Function Documentation

◆ ConcatenateSigList()

STATIC EFI_STATUS ConcatenateSigList ( IN EFI_SIGNATURE_LIST SigLists,
IN EFI_SIGNATURE_LIST SigListAppend,
OUT EFI_SIGNATURE_LIST **  SigListOut,
IN OUT UINTN SigListsSize 
)

Adds new signature list to signature database.

Parameters
[in]SigListsA pointer to signature database.
[in]SigListAppendA signature list to be added.
[out]*SigListOutCreated signature database.
[in,out]SigListsSizeA size of created signature database.
Return values
EFI_SUCCESSSignature List was added successfully.
EFI_OUT_OF_RESOURCESFailed to allocate memory.

Definition at line 121 of file SecureBootVariableLib.c.

◆ CreateSigList()

STATIC EFI_STATUS CreateSigList ( IN VOID *  Data,
IN UINTN  Size,
OUT EFI_SIGNATURE_LIST **  SigList 
)

Creates EFI Signature List structure.

Parameters
[in]DataA pointer to signature data.
[in]SizeSize of signature data.
[out]SigListCreated Signature List.
Return values
EFI_SUCCESSSignature List was created successfully.
EFI_OUT_OF_RESOURCESFailed to allocate memory.

Definition at line 70 of file SecureBootVariableLib.c.

◆ CreateTimeBasedPayload()

EFI_STATUS EFIAPI CreateTimeBasedPayload ( IN OUT UINTN DataSize,
IN OUT UINT8 **  Data,
IN EFI_TIME Time 
)

Create a time based data payload by concatenating the EFI_VARIABLE_AUTHENTICATION_2 descriptor with the input data. NO authentication is required in this function.

Parameters
[in,out]DataSizeOn input, the size of Data buffer in bytes. On output, the size of data returned in Data buffer in bytes.
[in,out]DataOn input, Pointer to data buffer to be wrapped or pointer to NULL to wrap an empty payload. On output, Pointer to the new payload date buffer allocated from pool, it's caller's responsibility to free the memory when finish using it.
[in]TimePointer to time information to created time based payload.
Return values
EFI_SUCCESSCreate time based payload successfully.
EFI_OUT_OF_RESOURCESThere are not enough memory resources to create time based payload.
EFI_INVALID_PARAMETERThe parameter is invalid.
OthersUnexpected error happens.

Definition at line 266 of file SecureBootVariableLib.c.

◆ DeleteDb()

EFI_STATUS EFIAPI DeleteDb ( VOID  )

Clears the content of the 'db' variable.

Return values
EFI_OUT_OF_RESOURCESIf memory allocation for EFI_VARIABLE_AUTHENTICATION_2 fails while VendorGuid is NULL.
otherErrors from GetVariable2 (), GetTime () and SetVariable ()

Definition at line 482 of file SecureBootVariableLib.c.

◆ DeleteDbt()

EFI_STATUS EFIAPI DeleteDbt ( VOID  )

Clears the content of the 'dbt' variable.

Return values
EFI_OUT_OF_RESOURCESIf memory allocation for EFI_VARIABLE_AUTHENTICATION_2 fails while VendorGuid is NULL.
otherErrors from GetVariable2 (), GetTime () and SetVariable ()

Definition at line 528 of file SecureBootVariableLib.c.

◆ DeleteDbx()

EFI_STATUS EFIAPI DeleteDbx ( VOID  )

Clears the content of the 'dbx' variable.

Return values
EFI_OUT_OF_RESOURCESIf memory allocation for EFI_VARIABLE_AUTHENTICATION_2 fails while VendorGuid is NULL.
otherErrors from GetVariable2 (), GetTime () and SetVariable ()

Definition at line 505 of file SecureBootVariableLib.c.

◆ DeleteKEK()

EFI_STATUS EFIAPI DeleteKEK ( VOID  )

Clears the content of the 'KEK' variable.

Return values
EFI_OUT_OF_RESOURCESIf memory allocation for EFI_VARIABLE_AUTHENTICATION_2 fails while VendorGuid is NULL.
otherErrors from GetVariable2 (), GetTime () and SetVariable ()

Definition at line 551 of file SecureBootVariableLib.c.

◆ DeletePlatformKey()

EFI_STATUS EFIAPI DeletePlatformKey ( VOID  )

Remove the PK variable.

Return values
EFI_SUCCESSDelete PK successfully.
OthersCould not allow to delete PK.

Definition at line 574 of file SecureBootVariableLib.c.

◆ DeleteSecureBootVariables()

EFI_STATUS EFIAPI DeleteSecureBootVariables ( VOID  )

This function will delete the secure boot keys, thus disabling secure boot.

Returns
EFI_SUCCESS or underlying failure code.

Definition at line 600 of file SecureBootVariableLib.c.

◆ DeleteVariable()

EFI_STATUS EFIAPI DeleteVariable ( IN CHAR16 *  VariableName,
IN EFI_GUID VendorGuid 
)

Internal helper function to delete a Variable given its name and GUID, NO authentication required.

Parameters
[in]VariableNameName of the Variable.
[in]VendorGuidGUID of the Variable.
Return values
EFI_SUCCESSVariable deleted successfully.
OthersThe driver failed to start the device.

Definition at line 335 of file SecureBootVariableLib.c.

◆ EnrollFromInput()

EFI_STATUS EFIAPI EnrollFromInput ( IN CHAR16 *  VariableName,
IN EFI_GUID VendorGuid,
IN UINTN  DataSize,
IN VOID *  Data 
)

A helper function to take in a variable payload, wrap it in the proper authenticated variable structure, and install it in the EFI variable space.

Parameters
[in]VariableNameThe name of the key/database.
[in]VendorGuidThe namespace (ie. vendor GUID) of the variable
[in]DataSizeSize parameter for target secure boot variable.
[in]DataPointer to signature list formatted secure boot variable content.
Return values
EFI_SUCCESSThe enrollment for authenticated variable was successful.
EFI_OUT_OF_RESOURCESThere are not enough memory resources to create time based payload.
EFI_INVALID_PARAMETERThe parameter is invalid.
OthersUnexpected error happens.

Definition at line 693 of file SecureBootVariableLib.c.

◆ GetSetupMode()

EFI_STATUS EFIAPI GetSetupMode ( OUT UINT8 *  SetupMode)

Fetches the value of SetupMode variable.

Parameters
[out]SetupModePointer to UINT8 for SetupMode output
Return values
otherRetval from GetVariable.

Definition at line 413 of file SecureBootVariableLib.c.

◆ IsSecureBootEnabled()

BOOLEAN EFIAPI IsSecureBootEnabled ( VOID  )

Helper function to quickly determine whether SecureBoot is enabled.

Return values
TRUESecureBoot is verifiably enabled.
FALSESecureBoot is either disabled or an error prevented checking.

Definition at line 444 of file SecureBootVariableLib.c.

◆ SecureBootCreateDataFromInput()

EFI_STATUS EFIAPI SecureBootCreateDataFromInput ( OUT UINTN SigListsSize,
OUT EFI_SIGNATURE_LIST **  SigListOut,
IN UINTN  KeyInfoCount,
IN CONST SECURE_BOOT_CERTIFICATE_INFO KeyInfo 
)

Create a EFI Signature List with data supplied from input argument. The input certificates from KeyInfo parameter should be DER-encoded format.

Parameters
[out]SigListsSizeA pointer to size of signature list
[out]SigListOutA pointer to a callee-allocated buffer with signature lists
[in]KeyInfoCountThe number of certificate pointer and size pairs inside KeyInfo.
[in]KeyInfoA pointer to all certificates, in the format of DER-encoded, to be concatenated into signature lists.
Return values
EFI_SUCCESSCreated signature list from payload successfully.
EFI_NOT_FOUNDSection with key has not been found.
EFI_INVALID_PARAMETEREmbedded key has a wrong format or input pointers are NULL.
OthersUnexpected error happens.

Definition at line 169 of file SecureBootVariableLib.c.

◆ SetSecureBootMode()

EFI_STATUS EFIAPI SetSecureBootMode ( IN UINT8  SecureBootMode)

Set the platform secure boot mode into "Custom" or "Standard" mode.

Parameters
[in]SecureBootModeNew secure boot mode: STANDARD_SECURE_BOOT_MODE or CUSTOM_SECURE_BOOT_MODE.
Returns
EFI_SUCCESS The platform has switched to the special mode successfully.
other Fail to operate the secure boot mode.

Definition at line 391 of file SecureBootVariableLib.c.

◆ SetSecureBootVariablesToDefault()

EFI_STATUS EFIAPI SetSecureBootVariablesToDefault ( IN CONST SECURE_BOOT_PAYLOAD_INFO SecureBootPayload)

Similar to DeleteSecureBootVariables, this function is used to unilaterally force the state of related SB variables (db, dbx, dbt, KEK, PK, etc.) to be the built-in, hardcoded default vars.

Parameters
[in]SecureBootPayloadPayload information for secure boot related keys.
Return values
EFI_SUCCESSSecureBoot keys are now set to defaults.
EFI_ABORTEDSecureBoot keys are not empty. Please delete keys first or follow standard methods of altering keys (ie. use the signing system).
EFI_SECURITY_VIOLATIONFailed to create the PK.
OthersSomething failed in one of the subfunctions.

Definition at line 790 of file SecureBootVariableLib.c.

Variable Documentation

◆ mDefaultPayloadTimestamp

EFI_TIME mDefaultPayloadTimestamp
Initial value:
= {
1970,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0
}

Definition at line 45 of file SecureBootVariableLib.c.

◆ mMaxTimestamp

EFI_TIME mMaxTimestamp
Initial value:
= {
0xFFFF,
0xFF,
0xFF,
0xFF,
0xFF,
0xFF,
0x00,
0x00000000,
0,
0,
0x00
}

Definition at line 27 of file SecureBootVariableLib.c.