Re: [edk2-devel] [PATCH v2 3/6] SecurityPkg: Add SecureBootDefaultKeysDxe driver

2021-06-04 Thread Sunny Wang
Internally reviewed this patch before sending the edk2 mailing list and It 
looks good to me. Please also address Pete's good catches/comments.
Reviewed-by: Sunny Wang 

-Original Message-
From: Grzegorz Bernacki 
Sent: Tuesday, June 1, 2021 9:12 PM
To: devel@edk2.groups.io
Cc: l...@nuviainc.com; ardb+tianoc...@kernel.org; Samer El-Haj-Mahmoud 
; Sunny Wang ; 
m...@semihalf.com; upstr...@semihalf.com; jiewen@intel.com; 
jian.j.w...@intel.com; min.m...@intel.com; ler...@redhat.com; Grzegorz Bernacki 

Subject: [PATCH v2 3/6] SecurityPkg: Add SecureBootDefaultKeysDxe driver

This driver initializes default Secure Boot keys and databases
based on keys embedded in flash.

Signed-off-by: Grzegorz Bernacki 
---
 
SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.inf
 | 46 +
 
SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.c
   | 69 
 
SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.uni
 | 17 +
 3 files changed, 132 insertions(+)
 create mode 100644 
SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.inf
 create mode 100644 
SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.c
 create mode 100644 
SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.uni

diff --git 
a/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.inf
 
b/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.inf
new file mode 100644
index 00..27345eab2e
--- /dev/null
+++ 
b/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.inf
@@ -0,0 +1,46 @@
+## @file
+#  Initializes Secure Boot default keys
+#
+#  Copyright (c) 2021, ARM Ltd. All rights reserved.
+#  Copyright (c) 2021, Semihalf All rights reserved.
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+[Defines]
+  INF_VERSION = 0x00010005
+  BASE_NAME   = SecureBootDefaultKeysDxe
+  FILE_GUID   = C937FCB7-25AC-4376-89A2-4EA8B317DE83
+  MODULE_TYPE = DXE_DRIVER
+  ENTRY_POINT = SecureBootDefaultKeysEntryPoint
+
+#
+#  VALID_ARCHITECTURES   = IA32 X64 AARCH64
+#
+[Sources]
+  SecureBootDefaultKeysDxe.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  SecurityPkg/SecurityPkg.dec
+
+[LibraryClasses]
+  BaseLib
+  BaseMemoryLib
+  MemoryAllocationLib
+  UefiDriverEntryPoint
+  DebugLib
+  SecureBootVariableLib
+
+[Guids]
+  ## SOMETIMES_PRODUCES  ## Variable:L"PKDefault"
+  ## SOMETIMES_PRODUCES  ## Variable:L"KEKDefault"
+  ## SOMETIMES_PRODUCES  ## Variable:L"dbDefault"
+  ## SOMETIMES_PRODUCES  ## Variable:L"dbtDefault"
+  ## SOMETIMES_PRODUCES  ## Variable:L"dbxDefault"
+  gEfiGlobalVariableGuid
+
+[Depex]
+  gEfiVariableArchProtocolGuid  AND
+  gEfiVariableWriteArchProtocolGuid
+
diff --git 
a/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.c
 
b/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.c
new file mode 100644
index 00..0928489e15
--- /dev/null
+++ 
b/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.c
@@ -0,0 +1,69 @@
+/** @file
+  This driver init default Secure Boot variables
+
+Copyright (c) 2021, ARM Ltd. All rights reserved.
+Copyright (c) 2021, Semihalf All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+  The entry point for SecureBootDefaultKeys driver.
+
+  @param[in]  ImageHandleThe image handle of the driver.
+  @param[in]  SystemTableThe system table.
+
+  @retval EFI_ALREADY_STARTEDThe driver already exists in system.
+  @retval EFI_OUT_OF_RESOURCES   Fail to execute entry point due to lack of 
resources.
+  @retval EFI_SUCCESSAll the related protocols are installed on 
the driver.
+  @retval Others Fail to get the SecureBootEnable variable.
+
+**/
+EFI_STATUS
+EFIAPI
+SecureBootDefaultKeysEntryPoint (
+  IN EFI_HANDLE  ImageHandle,
+  IN EFI_SYSTEM_TABLE*SystemTable
+  )
+{
+  EFI_STATUS  Status;
+
+  Status = SecureBootInitPKDefault ();
+  if (EFI_ERROR (Status)) {
+DEBUG((DEBUG_ERROR, "%a: Cannot initialize PKDefault: %r\n", __FUNCTION__, 
Status));
+return Status;
+  }
+
+  Status = SecureBootInitKEKDefault ();
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, "%a: Cannot initialize KEKDefault: %r\n", 
__FUNCTION__, Status));
+return Status;
+  }
+  Status = SecureBootInitdbDefault ();
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, "%a: Cannot initialize dbDefault: %r\n", 
__FUNCTION__, Status));
+return Status;
+  }
+
+  Status = SecureBootInitdbtDefault ();
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_INFO, "%a: dbtDefault not 

Re: [edk2-devel] [PATCH v2 3/6] SecurityPkg: Add SecureBootDefaultKeysDxe driver

2021-06-04 Thread Min Xu
On June 1, 2021 9:12 PM, Grzegorz Bernacki Wrote:
> This driver initializes default Secure Boot keys and databases based on keys
> embedded in flash.
> 
> Signed-off-by: Grzegorz Bernacki 
> ---
> 
> SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootD
> efaultKeysDxe.inf | 46 +
> 
> SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootD
> efaultKeysDxe.c   | 69 
> 
> SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootD
> efaultKeysDxe.uni | 17 +
>  3 files changed, 132 insertions(+)
>  create mode 100644
> SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootD
> efaultKeysDxe.inf
>  create mode 100644
> SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootD
> efaultKeysDxe.c
>  create mode 100644
> SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootD
> efaultKeysDxe.uni
> 
> diff --git
> a/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBoo
> tDefaultKeysDxe.inf
> b/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBoo
> tDefaultKeysDxe.inf
> new file mode 100644
> index 00..27345eab2e
> --- /dev/null
> +++
> b/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureB
> +++ ootDefaultKeysDxe.inf
> @@ -0,0 +1,46 @@
> +## @file
> +#  Initializes Secure Boot default keys # #  Copyright (c) 2021, ARM
> +Ltd. All rights reserved. #  Copyright (c) 2021, Semihalf All
> +rights reserved. #  SPDX-License-Identifier: BSD-2-Clause-Patent #
> +## [Defines]
> +  INF_VERSION = 0x00010005
> +  BASE_NAME   = SecureBootDefaultKeysDxe
> +  FILE_GUID   = C937FCB7-25AC-4376-89A2-4EA8B317DE83
> +  MODULE_TYPE = DXE_DRIVER
> +  ENTRY_POINT = SecureBootDefaultKeysEntryPoint
> +
> +#
> +#  VALID_ARCHITECTURES   = IA32 X64 AARCH64
> +#
> +[Sources]
> +  SecureBootDefaultKeysDxe.c
> +
> +[Packages]
> +  MdePkg/MdePkg.dec
> +  MdeModulePkg/MdeModulePkg.dec
> +  SecurityPkg/SecurityPkg.dec
> +
> +[LibraryClasses]
> +  BaseLib
> +  BaseMemoryLib
> +  MemoryAllocationLib
> +  UefiDriverEntryPoint
> +  DebugLib
> +  SecureBootVariableLib
> +
> +[Guids]
> +  ## SOMETIMES_PRODUCES  ## Variable:L"PKDefault"
> +  ## SOMETIMES_PRODUCES  ## Variable:L"KEKDefault"
> +  ## SOMETIMES_PRODUCES  ## Variable:L"dbDefault"
> +  ## SOMETIMES_PRODUCES  ## Variable:L"dbtDefault"
> +  ## SOMETIMES_PRODUCES  ## Variable:L"dbxDefault"
> +  gEfiGlobalVariableGuid
> +
> +[Depex]
> +  gEfiVariableArchProtocolGuid  AND
> +  gEfiVariableWriteArchProtocolGuid
> +
> diff --git
> a/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBoo
> tDefaultKeysDxe.c
> b/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBoo
> tDefaultKeysDxe.c
> new file mode 100644
> index 00..0928489e15
> --- /dev/null
> +++
> b/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureB
> +++ ootDefaultKeysDxe.c
> @@ -0,0 +1,69 @@
> +/** @file
> +  This driver init default Secure Boot variables
> +
> +Copyright (c) 2021, ARM Ltd. All rights reserved. Copyright (c)
> +2021, Semihalf All rights reserved.
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include  #include
> +
> +#include 
> +#include 
> +
> +/**
> +  The entry point for SecureBootDefaultKeys driver.
> +
> +  @param[in]  ImageHandleThe image handle of the driver.
> +  @param[in]  SystemTableThe system table.
> +
> +  @retval EFI_ALREADY_STARTEDThe driver already exists in system.
> +  @retval EFI_OUT_OF_RESOURCES   Fail to execute entry point due to lack
> of resources.
> +  @retval EFI_SUCCESSAll the related protocols are installed on 
> the
> driver.
> +  @retval Others Fail to get the SecureBootEnable variable.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +SecureBootDefaultKeysEntryPoint (
> +  IN EFI_HANDLE  ImageHandle,
> +  IN EFI_SYSTEM_TABLE*SystemTable
> +  )
> +{
> +  EFI_STATUS  Status;
> +
> +  Status = SecureBootInitPKDefault ();
> +  if (EFI_ERROR (Status)) {
> +DEBUG((DEBUG_ERROR, "%a: Cannot initialize PKDefault: %r\n",
> __FUNCTION__, Status));
> +return Status;
> +  }
> +
> +  Status = SecureBootInitKEKDefault ();  if (EFI_ERROR (Status)) {
> +DEBUG ((DEBUG_ERROR, "%a: Cannot initialize KEKDefault: %r\n",
> __FUNCTION__, Status));
> +return Status;
> +  }
> +  Status = SecureBootInitdbDefault ();
> +  if (EFI_ERROR (Status)) {
> +DEBUG ((DEBUG_ERROR, "%a: Cannot initialize dbDefault: %r\n",
> __FUNCTION__, Status));
> +return Status;
> +  }
> +
> +  Status = SecureBootInitdbtDefault ();  if (EFI_ERROR (Status)) {
> +DEBUG ((DEBUG_INFO, "%a: dbtDefault not initialized\n",
> + __FUNCTION__));  }
> +
> +  Status = SecureBootInitdbxDefault ();  if (EFI_ERROR (Status)) {
> +DEBUG ((DEBUG_INFO, "%a: dbxDefault not initialized\n",
> + __FUNCTION__));  }
> +
> +  return Status;
> +}
> +
> diff 

Re: [edk2-devel] [PATCH v2 3/6] SecurityPkg: Add SecureBootDefaultKeysDxe driver

2021-06-02 Thread Pete Batard

3 very minor remarks below:

On 2021.06.01 14:12, Grzegorz Bernacki wrote:

This driver initializes default Secure Boot keys and databases
based on keys embedded in flash.

Signed-off-by: Grzegorz Bernacki 
---
  
SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.inf
 | 46 +
  
SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.c
   | 69 
  
SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.uni
 | 17 +
  3 files changed, 132 insertions(+)
  create mode 100644 
SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.inf
  create mode 100644 
SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.c
  create mode 100644 
SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.uni

diff --git 
a/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.inf
 
b/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.inf
new file mode 100644
index 00..27345eab2e
--- /dev/null
+++ 
b/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.inf
@@ -0,0 +1,46 @@
+## @file
+#  Initializes Secure Boot default keys
+#
+#  Copyright (c) 2021, ARM Ltd. All rights reserved.
+#  Copyright (c) 2021, Semihalf All rights reserved.
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+[Defines]
+  INF_VERSION = 0x00010005
+  BASE_NAME   = SecureBootDefaultKeysDxe
+  FILE_GUID   = C937FCB7-25AC-4376-89A2-4EA8B317DE83
+  MODULE_TYPE = DXE_DRIVER
+  ENTRY_POINT = SecureBootDefaultKeysEntryPoint
+
+#
+#  VALID_ARCHITECTURES   = IA32 X64 AARCH64
+#
+[Sources]
+  SecureBootDefaultKeysDxe.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  SecurityPkg/SecurityPkg.dec
+
+[LibraryClasses]
+  BaseLib
+  BaseMemoryLib
+  MemoryAllocationLib
+  UefiDriverEntryPoint
+  DebugLib
+  SecureBootVariableLib
+
+[Guids]
+  ## SOMETIMES_PRODUCES  ## Variable:L"PKDefault"
+  ## SOMETIMES_PRODUCES  ## Variable:L"KEKDefault"
+  ## SOMETIMES_PRODUCES  ## Variable:L"dbDefault"
+  ## SOMETIMES_PRODUCES  ## Variable:L"dbtDefault"
+  ## SOMETIMES_PRODUCES  ## Variable:L"dbxDefault"
+  gEfiGlobalVariableGuid
+
+[Depex]
+  gEfiVariableArchProtocolGuid  AND
+  gEfiVariableWriteArchProtocolGuid
+


This adds an extra trailing blank line.


diff --git 
a/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.c
 
b/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.c
new file mode 100644
index 00..0928489e15
--- /dev/null
+++ 
b/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.c
@@ -0,0 +1,69 @@
+/** @file
+  This driver init default Secure Boot variables
+
+Copyright (c) 2021, ARM Ltd. All rights reserved.
+Copyright (c) 2021, Semihalf All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+  The entry point for SecureBootDefaultKeys driver.
+
+  @param[in]  ImageHandleThe image handle of the driver.
+  @param[in]  SystemTableThe system table.
+
+  @retval EFI_ALREADY_STARTEDThe driver already exists in system.
+  @retval EFI_OUT_OF_RESOURCES   Fail to execute entry point due to lack of 
resources.
+  @retval EFI_SUCCESSAll the related protocols are installed on 
the driver.
+  @retval Others Fail to get the SecureBootEnable variable.
+
+**/
+EFI_STATUS
+EFIAPI
+SecureBootDefaultKeysEntryPoint (
+  IN EFI_HANDLE  ImageHandle,
+  IN EFI_SYSTEM_TABLE*SystemTable
+  )
+{
+  EFI_STATUS  Status;
+
+  Status = SecureBootInitPKDefault ();
+  if (EFI_ERROR (Status)) {
+DEBUG((DEBUG_ERROR, "%a: Cannot initialize PKDefault: %r\n", __FUNCTION__, 
Status));
+return Status;
+  }
+
+  Status = SecureBootInitKEKDefault ();
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, "%a: Cannot initialize KEKDefault: %r\n", 
__FUNCTION__, Status));
+return Status;
+  }
+  Status = SecureBootInitdbDefault ();
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, "%a: Cannot initialize dbDefault: %r\n", 
__FUNCTION__, Status));
+return Status;
+  }
+
+  Status = SecureBootInitdbtDefault ();
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_INFO, "%a: dbtDefault not initialized\n", __FUNCTION__));
+  }
+
+  Status = SecureBootInitdbxDefault ();
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_INFO, "%a: dbxDefault not initialized\n", __FUNCTION__));
+  }
+
+  return Status;
+}
+


This adds an extra trailing blank line.


diff --git 
a/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.uni
 
b/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.uni
new file 

[edk2-devel] [PATCH v2 3/6] SecurityPkg: Add SecureBootDefaultKeysDxe driver

2021-06-01 Thread Grzegorz Bernacki
This driver initializes default Secure Boot keys and databases
based on keys embedded in flash.

Signed-off-by: Grzegorz Bernacki 
---
 
SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.inf
 | 46 +
 
SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.c
   | 69 
 
SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.uni
 | 17 +
 3 files changed, 132 insertions(+)
 create mode 100644 
SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.inf
 create mode 100644 
SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.c
 create mode 100644 
SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.uni

diff --git 
a/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.inf
 
b/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.inf
new file mode 100644
index 00..27345eab2e
--- /dev/null
+++ 
b/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.inf
@@ -0,0 +1,46 @@
+## @file
+#  Initializes Secure Boot default keys
+#
+#  Copyright (c) 2021, ARM Ltd. All rights reserved.
+#  Copyright (c) 2021, Semihalf All rights reserved.
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+[Defines]
+  INF_VERSION = 0x00010005
+  BASE_NAME   = SecureBootDefaultKeysDxe
+  FILE_GUID   = C937FCB7-25AC-4376-89A2-4EA8B317DE83
+  MODULE_TYPE = DXE_DRIVER
+  ENTRY_POINT = SecureBootDefaultKeysEntryPoint
+
+#
+#  VALID_ARCHITECTURES   = IA32 X64 AARCH64
+#
+[Sources]
+  SecureBootDefaultKeysDxe.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  SecurityPkg/SecurityPkg.dec
+
+[LibraryClasses]
+  BaseLib
+  BaseMemoryLib
+  MemoryAllocationLib
+  UefiDriverEntryPoint
+  DebugLib
+  SecureBootVariableLib
+
+[Guids]
+  ## SOMETIMES_PRODUCES  ## Variable:L"PKDefault"
+  ## SOMETIMES_PRODUCES  ## Variable:L"KEKDefault"
+  ## SOMETIMES_PRODUCES  ## Variable:L"dbDefault"
+  ## SOMETIMES_PRODUCES  ## Variable:L"dbtDefault"
+  ## SOMETIMES_PRODUCES  ## Variable:L"dbxDefault"
+  gEfiGlobalVariableGuid
+
+[Depex]
+  gEfiVariableArchProtocolGuid  AND
+  gEfiVariableWriteArchProtocolGuid
+
diff --git 
a/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.c
 
b/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.c
new file mode 100644
index 00..0928489e15
--- /dev/null
+++ 
b/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.c
@@ -0,0 +1,69 @@
+/** @file
+  This driver init default Secure Boot variables
+
+Copyright (c) 2021, ARM Ltd. All rights reserved.
+Copyright (c) 2021, Semihalf All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+  The entry point for SecureBootDefaultKeys driver.
+
+  @param[in]  ImageHandleThe image handle of the driver.
+  @param[in]  SystemTableThe system table.
+
+  @retval EFI_ALREADY_STARTEDThe driver already exists in system.
+  @retval EFI_OUT_OF_RESOURCES   Fail to execute entry point due to lack of 
resources.
+  @retval EFI_SUCCESSAll the related protocols are installed on 
the driver.
+  @retval Others Fail to get the SecureBootEnable variable.
+
+**/
+EFI_STATUS
+EFIAPI
+SecureBootDefaultKeysEntryPoint (
+  IN EFI_HANDLE  ImageHandle,
+  IN EFI_SYSTEM_TABLE*SystemTable
+  )
+{
+  EFI_STATUS  Status;
+
+  Status = SecureBootInitPKDefault ();
+  if (EFI_ERROR (Status)) {
+DEBUG((DEBUG_ERROR, "%a: Cannot initialize PKDefault: %r\n", __FUNCTION__, 
Status));
+return Status;
+  }
+
+  Status = SecureBootInitKEKDefault ();
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, "%a: Cannot initialize KEKDefault: %r\n", 
__FUNCTION__, Status));
+return Status;
+  }
+  Status = SecureBootInitdbDefault ();
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, "%a: Cannot initialize dbDefault: %r\n", 
__FUNCTION__, Status));
+return Status;
+  }
+
+  Status = SecureBootInitdbtDefault ();
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_INFO, "%a: dbtDefault not initialized\n", __FUNCTION__));
+  }
+
+  Status = SecureBootInitdbxDefault ();
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_INFO, "%a: dbxDefault not initialized\n", __FUNCTION__));
+  }
+
+  return Status;
+}
+
diff --git 
a/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.uni
 
b/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.uni
new file mode 100644
index 00..30f03aee5d
--- /dev/null
+++ 
b/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.uni
@@ -0,0 +1,17 @@
+//