From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mx.groups.io with SMTP id smtpd.web12.13562.1651255521776053976 for ; Fri, 29 Apr 2022 11:05:21 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=PXPpMjE/; spf=pass (domain: intel.com, ip: 134.134.136.65, mailfrom: judah.vang@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651255521; x=1682791521; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zL7dnOTqCBwo1PGu+u+ri7y5mRHYBUXq5yelqNBB9EM=; b=PXPpMjE/GZ8MuxlxlLoCcnhEHY/LBVsqBJvskLKZnk+a21m32gtkFA5u RfD8s+6YP1sE2d3e5+ByOo2rTNxi8Fk9OrbpW66qwJz/AIEq7KrojxvPv XA/kJakqqeYI5lPVsJU0zcF6jJxxlOF2BEU+kf5UTzI6zyEhOHRcPU8Yk tbhqI+8p5lzyalEi852XgpwsODaGRUVprkLDzKUb4V/A5ZQ6IW5r3IDOL 0sVMeI7LY1cU1CtmutOqq/EJK2Ktstw68btFYR25IeaDjmDtvYvAJFJf0 MWwauO/Nt6f/yb5mX2dW1c2IpcQuuBtRV3IIcEzdqxm69mkCsXBaKd7+l w==; X-IronPort-AV: E=McAfee;i="6400,9594,10332"; a="266550644" X-IronPort-AV: E=Sophos;i="5.91,186,1647327600"; d="scan'208";a="266550644" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2022 11:05:20 -0700 X-IronPort-AV: E=Sophos;i="5.91,186,1647327600"; d="scan'208";a="514955733" Received: from jvang-mobl.amr.corp.intel.com ([10.212.198.238]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2022 11:05:19 -0700 From: "Judah Vang" To: devel@edk2.groups.io Cc: Jian J Wang , Jiewen Yao , Nishant C Mistry Subject: [Patch v2 15/28] SecurityPkg: Add VariableKey library function Date: Fri, 29 Apr 2022 11:04:17 -0700 Message-Id: <20220429180430.3292-16-judah.vang@intel.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220429180430.3292-1-judah.vang@intel.com> References: <20220429180430.3292-1-judah.vang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2594 Provide function that retrieves the key for protected variables. Cc: Jian J Wang Cc: Jiewen Yao Cc: Nishant C Mistry Signed-off-by: Jian J Wang Signed-off-by: Nishant C Mistry Signed-off-by: Judah Vang --- SecurityPkg/Library/VariableKeyLib/VariableKeyLib.inf | 36 ++++++++++++ SecurityPkg/Library/VariableKeyLib/VariableKeyLib.c | 59 ++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/SecurityPkg/Library/VariableKeyLib/VariableKeyLib.inf b/SecurityPkg/Library/VariableKeyLib/VariableKeyLib.inf new file mode 100644 index 000000000000..f62c80ce9943 --- /dev/null +++ b/SecurityPkg/Library/VariableKeyLib/VariableKeyLib.inf @@ -0,0 +1,36 @@ +## @file +# Provides default implementation of VariableKeyLib. +# +# Copyright (c) 2022, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x00010029 + BASE_NAME = VariableKeyLib + FILE_GUID = 7DF5A0BA-1DBB-4E67-A9F7-9FCCB1F9D250 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = VariableKeyLib + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 Arm AArch64 +# + +[Sources] + VariableKeyLib.c + +[Packages] + MdePkg/MdePkg.dec + SecurityPkg/SecurityPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + +[PpiS] + gKeyServicePpiGuid ## CONSUMES + diff --git a/SecurityPkg/Library/VariableKeyLib/VariableKeyLib.c b/SecurityPkg/Library/VariableKeyLib/VariableKeyLib.c new file mode 100644 index 000000000000..31b22782cb0c --- /dev/null +++ b/SecurityPkg/Library/VariableKeyLib/VariableKeyLib.c @@ -0,0 +1,59 @@ +/** @file + VariableKeyLib implementation. + +Copyright (c) 2022, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include +#include +#include + +#include + +#define VAR_KEY_SALT L"Key for RPMC Variable" +#define VAR_KEY_SALT_SIZE sizeof (VAR_KEY_SALT) + +/** + Retrieves the key for integrity and/or confidentiality of variables. + + @param[out] VariableKey A pointer to pointer for the variable key buffer. + @param[in] VariableKeySize The size in bytes of the variable key. + + @retval EFI_SUCCESS The variable key was returned. + @retval EFI_DEVICE_ERROR An error occurred while attempting to get the variable key. + @retval EFI_ACCESS_DENIED The function was invoked after locking the key interface. + @retval EFI_UNSUPPORTED The variable key is not supported in the current boot configuration. +**/ +EFI_STATUS +EFIAPI +GetVariableKey ( + OUT VOID *VariableKey, + IN UINTN VariableKeySize + ) +{ + EFI_STATUS Status; + KEY_SERVICE_PPI *KeyService; + + Status = PeiServicesLocatePpi ( + &gKeyServicePpiGuid, + 0, + NULL, + (void **)&KeyService + ); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return Status; + } + + Status = KeyService->GenerateKey ( + (UINT8 *)VAR_KEY_SALT, + VAR_KEY_SALT_SIZE, + VariableKey, + VariableKeySize + ); + return Status; +} -- 2.35.1.windows.2