From nobody Tue Feb 10 10:55:16 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+77777+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+77777+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1626265832; cv=none; d=zohomail.com; s=zohoarc; b=fC/PoyILhZhnoFoamFy57hti/zg+E2cNLz+4CU5Fzc7XELCoaXzDVcGdFrhhUkdMfUsPIzVCXCUTLh0MaIUXwCYyWKPC+Gz2XDVclaynLG3neQ4CXVaZVur0kJIFhWttsIF6rT3oW2KFRZeVmsUhADmwfbUcTcMleP014SkVpOw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1626265832; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=CUnlmNSQMTIHAt2keMIsgG7uBSzOulaXx21vr3DRdzY=; b=FyrpwIO7TPHwFi1gNFR4ZhY2eH1HnWnH8Gx5DjT1ZRGY/06tEJr/XEliBMoRXkPcErJya6X50fR1Hppjz9Jv8GlfgxS1pZHhoFjoR1FLN4YdPG6Y3BvIAPdVmPDrlySy5qwFV/atN4rXEyb6YqOlOkxmjfVD72ETnwW0YPdLcOM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+77777+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1626265832528499.2685384454054; Wed, 14 Jul 2021 05:30:32 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id qe4SYY1788612xybvnhlAIMV; Wed, 14 Jul 2021 05:30:32 -0700 X-Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) by mx.groups.io with SMTP id smtpd.web12.6059.1626265831324289269 for ; Wed, 14 Jul 2021 05:30:31 -0700 X-Received: by mail-lf1-f48.google.com with SMTP id q16so3300782lfa.5 for ; Wed, 14 Jul 2021 05:30:31 -0700 (PDT) X-Gm-Message-State: KWefWWHVB88zVusl5nw5liU9x1787277AA= X-Google-Smtp-Source: ABdhPJzfDn2Z21DNLjDDVnxDuDk+8iz6SWXKM6qJr/Nmtkx55Cbrr8w1gFph9riwNa1+8iEKw5EMsw== X-Received: by 2002:a05:6512:1326:: with SMTP id x38mr7667726lfu.62.1626265829407; Wed, 14 Jul 2021 05:30:29 -0700 (PDT) X-Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id j2sm224846ljc.49.2021.07.14.05.30.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 05:30:29 -0700 (PDT) From: "Grzegorz Bernacki" To: devel@edk2.groups.io Cc: leif@nuviainc.com, ardb+tianocore@kernel.org, Samer.El-Haj-Mahmoud@arm.com, sunny.Wang@arm.com, mw@semihalf.com, upstream@semihalf.com, jiewen.yao@intel.com, jian.j.wang@intel.com, min.m.xu@intel.com, lersek@redhat.com, sami.mujawar@arm.com, afish@apple.com, ray.ni@intel.com, jordan.l.justen@intel.com, rebecca@bsdio.com, grehan@freebsd.org, thomas.abraham@arm.com, chasel.chiu@intel.com, nathaniel.l.desimone@intel.com, gaoliming@byosoft.com.cn, eric.dong@intel.com, michael.d.kinney@intel.com, zailiang.sun@intel.com, yi.qian@intel.com, graeme@nuviainc.com, rad@semihalf.com, pete@akeo.ie, Grzegorz Bernacki , Jiewen Yao , Sunny Wang Subject: [edk2-devel] [PATCH v6 09/11] SecurityPkg: Add EnrollFromDefaultKeys application. Date: Wed, 14 Jul 2021 14:29:50 +0200 Message-Id: <20210714122952.1340890-10-gjb@semihalf.com> In-Reply-To: <20210714122952.1340890-1-gjb@semihalf.com> References: <20210714122952.1340890-1-gjb@semihalf.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,gjb@semihalf.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1626265832; bh=ITW7VDliWMThmo5bA26Jo/XgAPcQ0j8E4aOfZckVyn0=; h=Cc:Date:From:Reply-To:Subject:To; b=R/wIRwO1fNtTmeTO1hE9du99YLSUm+8pslJBA9BzLhTCDI43Ar0ghVlt94vorBZ6hH3 Eeqiydm0tpQRxM1LKH9U1hS0qqQwtbrrYtexKtJpEb6ryrbQ0z0yGg+kKP2GcQfkQ795C Ed2eAYiV4BIbShKsr+4zpodMi+0Q5o1JxJU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1626265834494100001 Content-Type: text/plain; charset="utf-8" This application allows user to force key enrollment from Secure Boot default variables. Signed-off-by: Grzegorz Bernacki Reviewed-by: Jiewen Yao Reviewed-by: Sunny Wang --- SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultKeysApp.inf | 48 ++= +++++++ SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultKeysApp.c | 110 ++= ++++++++++++++++++ 2 files changed, 158 insertions(+) create mode 100644 SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultK= eysApp.inf create mode 100644 SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultK= eysApp.c diff --git a/SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultKeysApp.= inf b/SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultKeysApp.inf new file mode 100644 index 0000000000..8675b30291 --- /dev/null +++ b/SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultKeysApp.inf @@ -0,0 +1,48 @@ +## @file +# Enroll PK, KEK, db, dbx from Default variables +# +# 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 =3D 1.28 + BASE_NAME =3D EnrollFromDefaultKeysApp + FILE_GUID =3D 6F18CB2F-1293-4BC1-ABB8-35F84C71812E + MODULE_TYPE =3D UEFI_APPLICATION + VERSION_STRING =3D 0.1 + ENTRY_POINT =3D UefiMain + +[Sources] + EnrollFromDefaultKeysApp.c + +[Packages] + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + SecurityPkg/SecurityPkg.dec + +[Guids] + gEfiCertPkcs7Guid + gEfiCertSha256Guid + gEfiCertX509Guid + gEfiCustomModeEnableGuid + gEfiGlobalVariableGuid + gEfiImageSecurityDatabaseGuid + gEfiSecureBootEnableDisableGuid + +[Protocols] + gEfiSmbiosProtocolGuid ## CONSUMES + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + PrintLib + UefiApplicationEntryPoint + UefiBootServicesTableLib + UefiLib + UefiRuntimeServicesTableLib + SecureBootVariableLib + SecureBootVariableProvisionLib diff --git a/SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultKeysApp.= c b/SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultKeysApp.c new file mode 100644 index 0000000000..13b7c61732 --- /dev/null +++ b/SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultKeysApp.c @@ -0,0 +1,110 @@ +/** @file + Enroll default PK, KEK, db, dbx. + +Copyright (c) 2021, ARM Ltd. All rights reserved.
+Copyright (c) 2021, Semihalf All rights reserved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include // gEfiCustomModeEnableGu= id +#include // EFI_SETUP_MODE_NAME +#include // EFI_IMAGE_SECURITY_DAT= ABASE +#include // GUID_STRING_LENGTH +#include // CopyGuid() +#include // ASSERT() +#include // FreePool() +#include // AsciiSPrint() +#include // gBS +#include // AsciiPrint() +#include // gRT +#include +#include +#include + +/** + Entry point function of this shell application. +**/ +EFI_STATUS +EFIAPI +UefiMain ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + UINT8 SetupMode; + + Status =3D GetSetupMode (&SetupMode); + if (EFI_ERROR (Status)) { + AsciiPrint ("EnrollFromDefaultKeysApp: Cannot get SetupMode variable: = %r\n", Status); + return 1; + } + + if (SetupMode =3D=3D USER_MODE) { + AsciiPrint ("EnrollFromDefaultKeysApp: Skipped - USER_MODE\n"); + return 1; + } + + Status =3D SetSecureBootMode (CUSTOM_SECURE_BOOT_MODE); + if (EFI_ERROR (Status)) { + AsciiPrint ("EnrollFromDefaultKeysApp: Cannot set CUSTOM_SECURE_BOOT_M= ODE: %r\n", Status); + return 1; + } + + Status =3D EnrollDbFromDefault (); + if (EFI_ERROR (Status)) { + AsciiPrint ("EnrollFromDefaultKeysApp: Cannot enroll db: %r\n", Status= ); + goto error; + } + + Status =3D EnrollDbxFromDefault (); + if (EFI_ERROR (Status)) { + AsciiPrint ("EnrollFromDefaultKeysApp: Cannot enroll dbt: %r\n", Statu= s); + } + + Status =3D EnrollDbtFromDefault (); + if (EFI_ERROR (Status)) { + AsciiPrint ("EnrollFromDefaultKeysApp: Cannot enroll dbx: %r\n", Statu= s); + } + + Status =3D EnrollKEKFromDefault (); + if (EFI_ERROR (Status)) { + AsciiPrint ("EnrollFromDefaultKeysApp: Cannot enroll KEK: %r\n", Statu= s); + goto cleardbs; + } + + Status =3D EnrollPKFromDefault (); + if (EFI_ERROR (Status)) { + AsciiPrint ("EnrollFromDefaultKeysApp: Cannot enroll PK: %r\n", Status= ); + goto clearKEK; + } + + Status =3D SetSecureBootMode (STANDARD_SECURE_BOOT_MODE); + if (EFI_ERROR (Status)) { + AsciiPrint ( + "EnrollFromDefaultKeysApp: Cannot set CustomMode to STANDARD_SECURE_= BOOT_MODE\n" + "Please do it manually, otherwise system can be easily compromised\n" + ); + } + return 0; + +clearKEK: + DeleteKEK (); + +cleardbs: + DeleteDbt (); + DeleteDbx (); + DeleteDb (); + +error: + Status =3D SetSecureBootMode (STANDARD_SECURE_BOOT_MODE); + if (EFI_ERROR (Status)) { + AsciiPrint ( + "EnrollFromDefaultKeysApp: Cannot set CustomMode to STANDARD_SECURE_= BOOT_MODE\n" + "Please do it manually, otherwise system can be easily compromised\n" + ); + } + + return 1; +} --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#77777): https://edk2.groups.io/g/devel/message/77777 Mute This Topic: https://groups.io/mt/84200226/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-