From nobody Sun Feb 8 16:04:55 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+68978+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+68978+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=hpe.com ARC-Seal: i=1; a=rsa-sha256; t=1608133886; cv=none; d=zohomail.com; s=zohoarc; b=AD8CE1LMAFAa3Clx5Plh1N9oqRkRrFSjPA+ZJKd+gu0hEwHH6aiyEAoU+qt5hy3lsHph8eYGG+mP7XWVBKPQ2GVpKBpPAg1jYY8lvWEqJXVKBQh7mKtn6L1J25AF5AouGTzc125+Rc5jIGYSmoJSyublJLjg2NMRAdnc7DCYK8g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608133886; h=Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=DtX1iTMMxZus3qWAQD/jInAfS0T8K4RaD6LS96at4Vs=; b=SA/6sheZPAp/tfoFAONOvi9rxr+aFtkLEFr10hGzWNJ/RoZGfIBB5zHUK597IeKLygGZZ5TUTDYB9il6ZEgXFGN0R+AgjKLTOFBsBQhhfo7cyN1yZ4u5xkW/ATUsASQcvBOq56Y7OSs9mb/KEjn2xQ8HLn0u7RaZ5y5hcjOE+/c= 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+68978+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608133886592735.3233942832306; Wed, 16 Dec 2020 07:51:26 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id d00CYY1788612xWI6PXIwAt0; Wed, 16 Dec 2020 07:51:21 -0800 X-Received: from mx0b-002e3701.pphosted.com (mx0b-002e3701.pphosted.com [148.163.143.35]) by mx.groups.io with SMTP id smtpd.web08.10170.1608133881055962190 for ; Wed, 16 Dec 2020 07:51:21 -0800 X-Received: from pps.filterd (m0134424.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0BGFYI7r032726; Wed, 16 Dec 2020 15:51:18 GMT X-Received: from g2t2352.austin.hpe.com (g2t2352.austin.hpe.com [15.233.44.25]) by mx0b-002e3701.pphosted.com with ESMTP id 35f2qd83re-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Dec 2020 15:51:18 +0000 X-Received: from g2t2360.austin.hpecorp.net (g2t2360.austin.hpecorp.net [16.196.225.135]) by g2t2352.austin.hpe.com (Postfix) with ESMTP id 2FC3CB0; Wed, 16 Dec 2020 15:51:18 +0000 (UTC) X-Received: from abner-virtual-machine.asiapacific.hpqcorp.net (abner-virtual-machine.asiapacific.hpqcorp.net [15.119.210.153]) by g2t2360.austin.hpecorp.net (Postfix) with ESMTP id CD57337; Wed, 16 Dec 2020 15:51:16 +0000 (UTC) From: "Abner Chang" To: devel@edk2.groups.io Cc: Jordan Justen , Andrew Fish , Ray Ni , Nickle Wang , Peter O'Hanley Subject: [edk2-devel] [PATCH] EmulatorPkg/library: RedfishPlatformCredentialLib Date: Wed, 16 Dec 2020 11:35:07 +0800 Message-Id: <20201216033507.10578-1-abner.chang@hpe.com> X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-HPE-SCL: -1 Precedence: Bulk List-Unsubscribe: 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,abner.chang@hpe.com X-Gm-Message-State: vOVWGQ7bJAHNwB91HvAsVSTix1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608133881; bh=utJaXLJZTWHW790z/JTJ+TNGn9l8poIpEDPWZrU7uUM=; h=Cc:Date:From:Reply-To:Subject:To; b=Z9I3Nm+LhRNAgqt8dzxVVUv4BPogqXDgbffvu2pNI+yJe18qW0CQHEZrIz9mToIWkyP ajx41Nm8v2jiHj9at1p3Q/IABb05/ijisfThBbF52Avr9FEuE5dx8crizuynj5DPn6Z7e YRx+RzwOt1t9HYwg0lS4YOyQplLZbL5MHMg= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Platform specific implementation of acquiring credential to access to Redfish service. This is the platform library which incorporates with Redfish Credential DXE driver under Redfish package. Signed-off-by: Abner Chang Cc: Jordan Justen Cc: Andrew Fish Cc: Ray Ni Cc: Nickle Wang Cc: Peter O'Hanley --- EmulatorPkg/EmulatorPkg.dec | 13 +- EmulatorPkg/EmulatorPkg.dsc | 1 + .../RedfishPlatformCredentialLib.c | 237 ++++++++++++++++++ .../RedfishPlatformCredentialLib.inf | 49 ++++ 4 files changed, 299 insertions(+), 1 deletion(-) create mode 100644 EmulatorPkg/Library/RedfishPlatformCredentialLib/Redfis= hPlatformCredentialLib.c create mode 100644 EmulatorPkg/Library/RedfishPlatformCredentialLib/Redfis= hPlatformCredentialLib.inf diff --git a/EmulatorPkg/EmulatorPkg.dec b/EmulatorPkg/EmulatorPkg.dec index 5d7fe6473e..b9c70b63b3 100644 --- a/EmulatorPkg/EmulatorPkg.dec +++ b/EmulatorPkg/EmulatorPkg.dec @@ -74,7 +74,18 @@ ## Size of the packet filter gEmulatorPkgTokenSpaceGuid.PcdNetworkPacketFilterSize|524288|UINT32|0x00= 00101c =20 - + ## Platform level Redfish Service control PCD + # These PCDs are used to stop the Redfish sevice when secure boot is dis= abled + # or exit boot service. + gEmulatorPkgTokenSpaceGuid.PcdRedfishServieStopIfSecureBootDisabled|TRUE= |BOOLEAN|0x00001020 + gEmulatorPkgTokenSpaceGuid.PcdRedfishServieStopIfExitbootService|TRUE|BO= OLEAN|0x00001021 + ## + # edk2 Redfish implementation on Emulator package is designed to access + # to Redfish simulator. + # https://github.com/DMTF/Redfish-Profile-Simulator + # The user ID and password are fixed as below. + gEmulatorPkgTokenSpaceGuid.PcdRedfishServieUserId|"admin"|VOID*|0x000010= 22 + gEmulatorPkgTokenSpaceGuid.PcdRedfishServiePassword|"pwd123456"|VOID*|0x= 00001023 =20 [PcdsFixedAtBuild, PcdsPatchableInModule] gEmulatorPkgTokenSpaceGuid.PcdEmuBootMode|1|UINT32|0x00001006 diff --git a/EmulatorPkg/EmulatorPkg.dsc b/EmulatorPkg/EmulatorPkg.dsc index de8144844c..6bd8ed8386 100644 --- a/EmulatorPkg/EmulatorPkg.dsc +++ b/EmulatorPkg/EmulatorPkg.dsc @@ -104,6 +104,7 @@ KeyMapLib|EmulatorPkg/Library/KeyMapLibNull/KeyMapLibNull.inf !if $(REDFISH_ENABLE) =3D=3D TRUE RedfishPlatformHostInterfaceLib|EmulatorPkg/Library/RedfishPlatformHos= tInterfaceLib/RedfishPlatformHostInterfaceLib.inf + RedfishPlatformCredentialLib|EmulatorPkg/Library/RedfishPlatformCreden= tialLib/RedfishPlatformCredentialLib.inf !endif # # Misc diff --git a/EmulatorPkg/Library/RedfishPlatformCredentialLib/RedfishPlatfo= rmCredentialLib.c b/EmulatorPkg/Library/RedfishPlatformCredentialLib/Redfis= hPlatformCredentialLib.c new file mode 100644 index 0000000000..5428aa324e --- /dev/null +++ b/EmulatorPkg/Library/RedfishPlatformCredentialLib/RedfishPlatformCrede= ntialLib.c @@ -0,0 +1,237 @@ +/** @file + EmulaotPkg RedfishPlatformCredentialLib instance + + (C) Copyright 2020 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +BOOLEAN mSecureBootDisabled =3D FALSE; +BOOLEAN mStopRedfishService =3D FALSE; + +EFI_STATUS +EFIAPI +LibStopRedfishService ( + IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This, + IN EDKII_REDFISH_CREDENTIAL_STOP_SERVICE_TYPE ServiceStopType +); + +/** + Return the credential for accessing to Redfish servcice. + + @param[out] AuthMethod The authentication method. + @param[out] UserId User ID. + @param[out] Password USer password. + + @retval EFI_SUCCESS Get the authentication information succ= essfully. + @retval EFI_OUT_OF_RESOURCES There are not enough memory resources. + +**/ +EFI_STATUS +GetRedfishCredential ( + OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod, + OUT CHAR8 **UserId, + OUT CHAR8 **Password +) +{ + UINTN UserIdSize; + UINTN PasswordSize; + + // + // AuthMethod set to HTTP Basic authentication. + // + *AuthMethod =3D AuthMethodHttpBasic; + + // + // User ID and Password. + // + UserIdSize =3D AsciiStrSize ((CHAR8 *)PcdGetPtr (PcdRedfishServieUserI= d)); + PasswordSize =3D AsciiStrSize ((CHAR8 *)PcdGetPtr (PcdRedfishServiePassw= ord)); + if (UserIdSize =3D=3D 0 || PasswordSize =3D=3D 0) { + DEBUG ((DEBUG_ERROR, "Incorrect string of UserID or Password for REdfi= sh service.\n")); + return EFI_INVALID_PARAMETER; + } + *UserId =3D AllocateZeroPool (UserIdSize); + if (*UserId =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + CopyMem (*UserId, (CHAR8 *)PcdGetPtr (PcdRedfishServieUserId), UserIdSiz= e); + + *Password =3D AllocateZeroPool (PasswordSize); + if (*Password =3D=3D NULL) { + FreePool (*UserId); + return EFI_OUT_OF_RESOURCES; + } + + CopyMem (*Password, (CHAR8 *)PcdGetPtr (PcdRedfishServiePassword), Passw= ordSize); + return EFI_SUCCESS; +} + +/** + Retrieve platform's Redfish authentication information. + + This functions returns the Redfish authentication method together with t= he user Id and + password. + - For AuthMethodNone, the UserId and Password could be used for HTTP hea= der authentication + as defined by RFC7235. + - For AuthMethodRedfishSession, the UserId and Password could be used fo= r Redfish + session login as defined by Redfish API specification (DSP0266). + + Callers are responsible for and freeing the returned string storage. + + @param[in] This Pointer to EDKII_REDFISH_CREDENTIAL_PRO= TOCOL instance. + @param[out] AuthMethod Type of Redfish authentication method. + @param[out] UserId The pointer to store the returned UserI= d string. + @param[out] Password The pointer to store the returned Passw= ord string. + + @retval EFI_SUCCESS Get the authentication information succ= essfully. + @retval EFI_ACCESS_DENIED SecureBoot is disabled after EndOfDxe. + @retval EFI_INVALID_PARAMETER This or AuthMethod or UserId or Passwor= d is NULL. + @retval EFI_OUT_OF_RESOURCES There are not enough memory resources. + @retval EFI_UNSUPPORTED Unsupported authentication method is fo= und. + +**/ +EFI_STATUS +EFIAPI +LibCredentialGetAuthInfo ( + IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This, + OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod, + OUT CHAR8 **UserId, + OUT CHAR8 **Password +) +{ + EFI_STATUS Status; + + if (This =3D=3D NULL || AuthMethod =3D=3D NULL || UserId =3D=3D NULL || = Password =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + if (mStopRedfishService) { + return EFI_ACCESS_DENIED; + } + + if (mSecureBootDisabled) { + Status =3D LibStopRedfishService (This, ServiceStopTypeSecureBootDisab= led); + if (EFI_ERROR (Status) && Status !=3D EFI_UNSUPPORTED) { + DEBUG ((DEBUG_ERROR, "SecureBoot has been disabled, but failed to st= op RedfishService - %r\n", Status)); + return Status; + } + } + + Status =3D GetRedfishCredential ( + AuthMethod, + UserId, + Password + ); + + return Status; +} + +/** + Notify the Redfish service to stop provide configuration service to this= platform. + + This function should be called when the platfrom is about to leave the s= afe environment. + It will notify the Redfish service provider to abort all logined session= , and prohibit + further login with original auth info. GetAuthInfo() will return EFI_UNS= UPPORTED once this + function is returned. + + @param[in] This Pointer to EDKII_REDFISH_CREDENTIAL_PRO= TOCOL instance. + @param[in] ServiceStopType Reason of stopping Redfish service. + + @retval EFI_SUCCESS Service has been stoped successfully. + @retval EFI_INVALID_PARAMETER This is NULL or given the worng Service= StopType. + @retval EFI_UNSUPPORTED Not support to stop Redfish service. + @retval Others Some error happened. + +**/ +EFI_STATUS +EFIAPI +LibStopRedfishService ( + IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This, + IN EDKII_REDFISH_CREDENTIAL_STOP_SERVICE_TYPE ServiceStopType +) +{ + if (ServiceStopType >=3D ServiceStopTypeMax) { + return EFI_INVALID_PARAMETER; + } + + if (ServiceStopType =3D=3D ServiceStopTypeSecureBootDisabled) { + // + // Check platform PCD to determine the action for stopping + // Redfish service due to secure boot is disabled. + // + if (!PcdGetBool (PcdRedfishServieStopIfSecureBootDisabled)) { + return EFI_UNSUPPORTED; + } else { + mStopRedfishService =3D TRUE; + DEBUG ((DEBUG_INFO, "EFI Redfish service is stopped due to SecureBoo= t is disabled!!\n")); + } + } else if (ServiceStopType =3D=3D ServiceStopTypeExitBootService) { + // + // Check platform PCD to determine the action for stopping + // Redfish service due to exit boot service. + // + if (PcdGetBool (PcdRedfishServieStopIfExitbootService)) { + return EFI_UNSUPPORTED; + } else { + mStopRedfishService =3D TRUE; + DEBUG ((DEBUG_INFO, "EFI Redfish service is stopped due to Exit Boot= Service!!\n")); + } + } else { + mStopRedfishService =3D TRUE; + DEBUG ((DEBUG_INFO, "EFI Redfish service is stopped without Redfish se= rvice stop type!!\n")); + } + return EFI_SUCCESS; +} +/** + Notification of Exit Boot Service. + + @param[in] This Pointer to EDKII_REDFISH_CREDENTIAL_PROTOCOL. +**/ +VOID +EFIAPI +LibCredentialExitBootServicesNotify ( + IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This +) +{ + LibStopRedfishService (This, ServiceStopTypeExitBootService); +} + +/** + Notification of End of DXE. + + @param[in] This Pointer to EDKII_REDFISH_CREDENTIAL_PROTOCOL. +**/ +VOID +EFIAPI +LibCredentialEndOfDxeNotify ( + IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This +) +{ + EFI_STATUS Status; + UINT8 *SecureBootVar; + + // + // Check Secure Boot status and lock Redfish service if Secure Boot is d= isabled. + // + Status =3D GetVariable2 (EFI_SECURE_BOOT_MODE_NAME, &gEfiGlobalVariableG= uid, (VOID**)&SecureBootVar, NULL); + if (EFI_ERROR (Status) || (*SecureBootVar !=3D SECURE_BOOT_MODE_ENABLE))= { + // + // Secure Boot is disabled + // + mSecureBootDisabled =3D TRUE; + LibStopRedfishService (This, ServiceStopTypeSecureBootDisabled); + } +} diff --git a/EmulatorPkg/Library/RedfishPlatformCredentialLib/RedfishPlatfo= rmCredentialLib.inf b/EmulatorPkg/Library/RedfishPlatformCredentialLib/Redf= ishPlatformCredentialLib.inf new file mode 100644 index 0000000000..41c389c4a2 --- /dev/null +++ b/EmulatorPkg/Library/RedfishPlatformCredentialLib/RedfishPlatformCrede= ntialLib.inf @@ -0,0 +1,49 @@ +## @file +# NT32 instance of RedfishPlatformCredentialLib +# +# (C) Copyright 2020 Hewlett Packard Enterprise Development LP
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x0001000b + BASE_NAME =3D RedfishPlatformCredentialLib + FILE_GUID =3D 00CF32A8-495C-3ED8-7C68-E9BB86810EE0 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D RedfishPlatformCredentialLib + +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[Sources] + RedfishPlatformCredentialLib.c + +[Packages] + EmulatorPkg/EmulatorPkg.dec + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + RedfishPkg/RedfishPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + PcdLib + UefiBootServicesTableLib + UefiLib + +[Pcd] + gEmulatorPkgTokenSpaceGuid.PcdRedfishServieStopIfSecureBootDisabled ## C= ONSUMES + gEmulatorPkgTokenSpaceGuid.PcdRedfishServieStopIfExitbootService ## C= ONSUMES + gEmulatorPkgTokenSpaceGuid.PcdRedfishServieUserId ## C= ONSUMES + gEmulatorPkgTokenSpaceGuid.PcdRedfishServiePassword ## C= ONSUMES + +[Guids] + gEfiGlobalVariableGuid + +[Depex] + gEfiVariableArchProtocolGuid + --=20 2.17.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 (#68978): https://edk2.groups.io/g/devel/message/68978 Mute This Topic: https://groups.io/mt/79003613/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-