From nobody Fri Apr 26 00:56:49 2024 Delivered-To: importer@patchew.org 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+101988+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 167996774741378.1037168348247; Mon, 27 Mar 2023 18:42:27 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id DSwQYY1788612xDevsw0LSQO; Mon, 27 Mar 2023 18:42:27 -0700 X-Received: from NAM02-SN1-obe.outbound.protection.outlook.com (NAM02-SN1-obe.outbound.protection.outlook.com [40.107.96.65]) by mx.groups.io with SMTP id smtpd.web10.56253.1679967745238471624 for ; Mon, 27 Mar 2023 18:42:25 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IJEhoien1sNCpL0ISzIQ0QpP1amyvV6niWL8DSbnX/M8AVIzdAbACjjukdCZRgE3Qf/ZS4eIZxaf8howStKzgmWl+dXJZlXBqHSZ3XTDhdKZzkF81hCY1bpgdkZ1fN8pa1qJJRLWMISsEJcpFOw4FdJV9S0Q2InNuvmeC0TbuG1qdGiTWxxlMqLsV6GNuUwZFI6JW/1I/M7EMP6MZKcdK1JUnOJuxgUtSDB9rndz9JDW2UgeA3KallOm5JcMbmULfEs0dIzcIXCu4y+hhLLvxl/TIhNmXPbcOvZgGv09NqLpgb/2nJy70h0IVm+0sKNFXoRQjTtIaBvsbAZOaQJwig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=p3dQrk6HKNKd9J8J0Ar+p4NKpGMO/RY/5V7zy/H3BrI=; b=U/T2F6FJZXGvojHPWPFNDFNv6jRLsBQmULLFxHx1tJXZzB+5oljWY8VNeSEPXRultWfSDrScvUuuUmpc5zZl7IzR3ZYzPK7pncy5X23caPdIjv3x9WfTdBn/cXj3iv4VrnWDT60j2Cg6REsYAdf5PeJZxCidAWLFGT52loPMjnG27XqTR3hGYACxW2QVfN9hzWRgQcw4I30v24CrLzvjhaESRdleLjaNMC2MUr1nWuOS5567xyw/n1GGbWDxC2ZEe+X/IcnX4KpQGRG8e24fO6/ZZ9j0+HMr1RxqaCpUS2R90yyR+8p0RPNT+6/I/03ReovuS6lOxPJtd71XR1KOeg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none X-Received: from DS7PR03CA0311.namprd03.prod.outlook.com (2603:10b6:8:2b::23) by SA1PR12MB8697.namprd12.prod.outlook.com (2603:10b6:806:385::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37; Tue, 28 Mar 2023 01:42:22 +0000 X-Received: from DM6NAM11FT071.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2b:cafe::9c) by DS7PR03CA0311.outlook.office365.com (2603:10b6:8:2b::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.43 via Frontend Transport; Tue, 28 Mar 2023 01:42:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; 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+101988+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C X-Received: from mail.nvidia.com (216.228.117.161) by DM6NAM11FT071.mail.protection.outlook.com (10.13.173.48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6222.22 via Frontend Transport; Tue, 28 Mar 2023 01:42:22 +0000 X-Received: from rnnvmail205.nvidia.com (10.129.68.10) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Mon, 27 Mar 2023 18:42:09 -0700 X-Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Mon, 27 Mar 2023 18:42:08 -0700 X-Received: from NV-CL38DL3.nvidia.com (10.127.8.13) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.5 via Frontend Transport; Mon, 27 Mar 2023 18:42:07 -0700 From: "Nickle Wang via groups.io" To: CC: Abner Chang , Igor Kulchytskyy , "Nick Ramirez" Subject: [edk2-devel] [PATCH v3] RedfishPkg/RedfishPlatformCredentialIpmiLib: IPMI implementation Date: Tue, 28 Mar 2023 09:42:08 +0800 Message-ID: <20230328014208.48-1-nicklew@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT071:EE_|SA1PR12MB8697:EE_ X-MS-Office365-Filtering-Correlation-Id: 752952d8-650f-4372-2cf0-08db2f2dacda X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: Fi5U1XsICFcnL8KOT8XOvT3ehwWX10vZR9ZR23upTSV3KRAX2R27F1EGXpHsz7siEoIUimZ2iIXMv2oFbIryHJ/VryAA3KYrcsviJTRkE/hs8tDuTfR35XyDP1cvdmh05g26FVkaDMyp+FH3O1PThmRXoMoKifYWTJ2BNTRLSt6sQfmqVNFmJWSmolJ6FPvvAfVNkcokvg4usK4WV0tpdYby3ReqjpDmaU31J3r9dj8UGnnGPDwkxcHx++nnmjZn8LMXNQbJk0VEvGsBG7pxtJNRkk/VIjg+PK9BW/gSaJ8w78GZdnLEgyRfjPhQQtbQy0OIpkFkkC2RPFEMgakABiRwGTEt1SPNnobOvtNbBwqmAZASvLrWF+Oh4J5pitkBp5iiCvA6zdpgolZiiC90/eXE2R8vV/yNyleOIkUordEfnQkbRFxSk+55x9ewpeRsqmwZT0tjBgcO5N9TyAhCC2XFjsTvq7jJ/ElmGRYh7AN3IOS/I575BFp8xkGwkhjZeu2Q23YF5YneDDEWrMyL/WEMXOBXcoAqzvYvAsaMSb8aoCdRH39VnxreC0nleDSNJIPh8BcPG+qx0qobhhZi0dgtubGthiF4hOXrnDX12sEJFdCjOc9kUuS+KlDiYo9Sj98p6x3QtJYe2LoGyKyqL+WV2S9+4Qub0ruVIKRNT0JYBxBKfwhXNZ+tK4XJI8arNlgh2Qjp/ZGDF0VelgXHCbnGaR/Mmf7B+tOTYLu9mb1UuLmhNzPdjVl7Dd3mVH1z6TMamrduIl6OOZUA0S6LwtPKVBW4S85VY++xsqeo8qRcsBiVe8N9G/S5P+pTteAm753YJbjjR6jVkT610lAdyx0NxGD1ukdUckPhIjJgu5I= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Mar 2023 01:42:22.1664 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 752952d8-650f-4372-2cf0-08db2f2dacda X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT071.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8697 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,nicklew@nvidia.com X-Gm-Message-State: 13TYnpOC82aYfvXAHKsICJbLx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679967747; bh=AVgociFyQAlE1ox1q+4Wd3HP+4FKNsKqhxKc/g9d3d4=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=UTvmaMUQj0xtMdknvnGENdxHzwKbxE5ZczmNloRO3ulVyq8KCpsx/AAmXTSmQq2sEyB 4Nttd3eioWFLswYoxuCZnx8Y8EHKXeHIMDgzJ25MXhHskNyOi4hFpx0iEQTgd8qXtSsoL Lf+7BfhRwvXgew1kOf1dekleV5PN/PLtPaI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679967748117100002 Content-Type: text/plain; charset="utf-8" This library follows Redfish Host Interface specification and use IPMI command to get bootstrap account credential(NetFn 2Ch, Command 02h) from BMC. RedfishHostInterfaceDxe will use this credential for the following communication between BIOS and BMC. Signed-off-by: Nickle Wang Cc: Abner Chang Cc: Igor Kulchytskyy Cc: Nick Ramirez --- RedfishPkg/RedfishPkg.dec | 7 + RedfishPkg/RedfishLibs.dsc.inc | 1 + RedfishPkg/RedfishPkg.dsc | 2 + .../RedfishPlatformCredentialIpmiLib.inf | 42 ++ .../RedfishPlatformCredentialIpmiLib.h | 89 ++++ .../RedfishPlatformCredentialIpmiLib.c | 457 ++++++++++++++++++ 6 files changed, 598 insertions(+) create mode 100644 RedfishPkg/Library/RedfishPlatformCredentialIpmiLib/Red= fishPlatformCredentialIpmiLib.inf create mode 100644 RedfishPkg/Library/RedfishPlatformCredentialIpmiLib/Red= fishPlatformCredentialIpmiLib.h create mode 100644 RedfishPkg/Library/RedfishPlatformCredentialIpmiLib/Red= fishPlatformCredentialIpmiLib.c diff --git a/RedfishPkg/RedfishPkg.dec b/RedfishPkg/RedfishPkg.dec index 42d28d6dac..f171053aec 100644 --- a/RedfishPkg/RedfishPkg.dec +++ b/RedfishPkg/RedfishPkg.dec @@ -81,6 +81,9 @@ [Guids] gEfiRedfishPkgTokenSpaceGuid =3D { 0x4fdbccb7, 0xe829, 0x4b4c, { 0x= 88, 0x87, 0xb2, 0x3f, 0xd7, 0x25, 0x4b, 0x85 }} =20 + # Redfish variable guid + gEfiRedfishVariableGuid =3D { 0x85ef8dd3, 0xe606, 0x4b89, { 0x= 8b, 0xbd, 0x93, 0xbf, 0x5c, 0xbe, 0x1c, 0x18 } } + [PcdsFixedAtBuild, PcdsPatchableInModule] # # This PCD is the UEFI device path which is used as the Redfish host int= erface. @@ -123,3 +126,7 @@ # specification for that. # gEfiRedfishPkgTokenSpaceGuid.PcdRedfishServiceUuid|L"00000000-0000-0000-= 0000-000000000000"|VOID*|0x00001006 + # + # This PCD indicates that if BMC bootstrap credential service will be di= sabled by BIOS or not. + # + gEfiRedfishPkgTokenSpaceGuid.PcdRedfishDisableBootstrapCredentialService= |FALSE|BOOLEAN|0x00001007 diff --git a/RedfishPkg/RedfishLibs.dsc.inc b/RedfishPkg/RedfishLibs.dsc.inc index 84f52d4b27..110526738c 100644 --- a/RedfishPkg/RedfishLibs.dsc.inc +++ b/RedfishPkg/RedfishLibs.dsc.inc @@ -19,5 +19,6 @@ JsonLib|RedfishPkg/Library/JsonLib/JsonLib.inf RedfishLib|RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.inf RedfishDebugLib|RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.inf + RedfishPlatformCredentialLib|RedfishPkg/Library/RedfishPlatformCredentia= lIpmiLib/RedfishPlatformCredentialIpmiLib.inf !endif =20 diff --git a/RedfishPkg/RedfishPkg.dsc b/RedfishPkg/RedfishPkg.dsc index 223ab72c1d..5503e65de4 100644 --- a/RedfishPkg/RedfishPkg.dsc +++ b/RedfishPkg/RedfishPkg.dsc @@ -4,6 +4,7 @@ # Copyright (c) 2019 - 2021, Intel Corporation. All rights reserved.
# (C) Copyright 2021 Hewlett-Packard Enterprise Development LP. # Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved. +# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -59,6 +60,7 @@ RedfishPkg/Library/PlatformHostInterfaceLibNull/PlatformHostInterfaceLib= Null.inf RedfishPkg/Library/PlatformHostInterfaceBmcUsbNicLib/PlatformHostInterfa= ceBmcUsbNicLib.inf RedfishPkg/Library/PlatformCredentialLibNull/PlatformCredentialLibNull.i= nf + RedfishPkg/Library/RedfishPlatformCredentialIpmiLib/RedfishPlatformCrede= ntialIpmiLib.inf RedfishPkg/Library/RedfishContentCodingLibNull/RedfishContentCodingLibNu= ll.inf RedfishPkg/Library/DxeRestExLib/DxeRestExLib.inf RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf diff --git a/RedfishPkg/Library/RedfishPlatformCredentialIpmiLib/RedfishPla= tformCredentialIpmiLib.inf b/RedfishPkg/Library/RedfishPlatformCredentialIp= miLib/RedfishPlatformCredentialIpmiLib.inf new file mode 100644 index 0000000000..5c20ea22f8 --- /dev/null +++ b/RedfishPkg/Library/RedfishPlatformCredentialIpmiLib/RedfishPlatformCr= edentialIpmiLib.inf @@ -0,0 +1,42 @@ +## @file +# INF file for RedfishPlatformCredentialIpmiLib. +# +# Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights res= erved. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x0001000b + BASE_NAME =3D RedfishPlatformCredentialIpmiLib + FILE_GUID =3D 9C45D622-4C66-417F-814C-F76246D97233 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D RedfishPlatformCredentialIpmiLib + +[Sources] + RedfishPlatformCredentialIpmiLib.c + RedfishPlatformCredentialIpmiLib.h + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + RedfishPkg/RedfishPkg.dec + +[LibraryClasses] + UefiLib + DebugLib + IpmiLib + MemoryAllocationLib + BaseMemoryLib + UefiRuntimeServicesTableLib + +[Pcd] + gEfiRedfishPkgTokenSpaceGuid.PcdRedfishDisableBootstrapCredentialService + +[Guids] + gEfiRedfishVariableGuid + +[Depex] + TRUE diff --git a/RedfishPkg/Library/RedfishPlatformCredentialIpmiLib/RedfishPla= tformCredentialIpmiLib.h b/RedfishPkg/Library/RedfishPlatformCredentialIpmi= Lib/RedfishPlatformCredentialIpmiLib.h new file mode 100644 index 0000000000..898ee88844 --- /dev/null +++ b/RedfishPkg/Library/RedfishPlatformCredentialIpmiLib/RedfishPlatformCr= edentialIpmiLib.h @@ -0,0 +1,89 @@ +/** @file + Header file for RedfishPlatformCredentialIpmiLib. + + Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights rese= rved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef REDFISH_PLATFORM_CREDENTIAL_IPMI_LIB_H_ +#define REDFISH_PLATFORM_CREDENTIAL_IPMI_LIB_H_ + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define CREDENTIAL_VARIABLE_NAME L"Partstooblaitnederc" + +/// +/// The bootstrap credential keeping in UEFI variable +/// +typedef struct { + CHAR8 Username[USERNAME_MAX_SIZE]; + CHAR8 Password[PASSWORD_MAX_SIZE]; +} BOOTSTRAP_CREDENTIALS_VARIABLE; + +/** + Function to retrieve temporary user credentials for the UEFI redfish cli= ent. This function can + also disable bootstrap credential service in BMC. + + @param[in] DisableBootstrapControl TRUE - Tell the BMC to disable th= e bootstrap credential + service to ensure no one e= lse gains credentials + FALSE Allow the bootstrap creden= tial service to continue + @param[in,out] BootstrapUsername A pointer to a Ascii encoded stri= ng for the credential username + When DisableBootstrapControl is T= RUE, this pointer can be NULL + @param[in] BootstrapUsernameSize The size of BootstrapUsername inc= luding NULL terminator in bytes. + Per specification, the size is US= ERNAME_MAX_SIZE. + @param[in,out] BootstrapPassword A pointer to a Ascii encoded stri= ng for the credential password + When DisableBootstrapControl is T= RUE, this pointer can be NULL + @param[in] BootstrapPasswordSize The size of BootstrapPassword inc= luding NULL terminator in bytes. + Per specification, the size is PA= SSWORD_MAX_SIZE. + + @retval EFI_SUCCESS Credentials were successfully fetche= d and returned. When DisableBootstrapControl + is set to TRUE, the bootstrap creden= tial service is disabled successfully. + @retval EFI_INVALID_PARAMETER BootstrapUsername or BootstrapPasswo= rd is NULL when DisableBootstrapControl + is set to FALSE. BootstrapUsernameSi= ze or BootstrapPasswordSize is incorrect when + DisableBootstrapControl is set to FA= LSE. + @retval EFI_DEVICE_ERROR An IPMI failure occurred +**/ +EFI_STATUS +GetBootstrapAccountCredentials ( + IN BOOLEAN DisableBootstrapControl, + IN OUT CHAR8 *BootstrapUsername, OPTIONAL + IN UINTN BootstrapUsernameSize, + IN OUT CHAR8 *BootstrapPassword, OPTIONAL + IN UINTN BootstrapPasswordSize + ); + +/** + Function to save temporary user credentials into boot time variable. Whe= n DeleteVariable is True, + this function delete boot time variable. + + @param[in] BootstrapUsername A pointer to a Ascii encoded string f= or the credential username. + @param[in] BootstrapPassword A pointer to a Ascii encoded string f= or the credential password. + @param[in] DeleteVariable True to remove boot time variable. Fa= lse otherwise. + + @retval EFI_SUCCESS Credentials were successfully saved. + @retval EFI_INVALID_PARAMETER BootstrapUsername or BootstrapPasswo= rd is NULL + @retval Others Error occurs +**/ +EFI_STATUS +SetBootstrapAccountCredentialsToVariable ( + IN CHAR8 *BootstrapUsername, OPTIONAL + IN CHAR8 *BootstrapPassword, OPTIONAL + IN BOOLEAN DeleteVariable + ); + +#endif diff --git a/RedfishPkg/Library/RedfishPlatformCredentialIpmiLib/RedfishPla= tformCredentialIpmiLib.c b/RedfishPkg/Library/RedfishPlatformCredentialIpmi= Lib/RedfishPlatformCredentialIpmiLib.c new file mode 100644 index 0000000000..7fccf1795d --- /dev/null +++ b/RedfishPkg/Library/RedfishPlatformCredentialIpmiLib/RedfishPlatformCr= edentialIpmiLib.c @@ -0,0 +1,457 @@ +/** @file + Implementation of getting bootstrap credential via IPMI. + + Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights rese= rved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Specification Reference: + - Redfish Host Interface Specification + (https://www.dmtf.org/sites/default/files/standards/documents/DSP0270_1.= 3.0.pdf) +**/ + +#include "RedfishPlatformCredentialIpmiLib.h" + +// +// Global flag of controlling credential service +// +BOOLEAN mRedfishServiceStopped =3D FALSE; + +/** + Notify the Redfish service provide to stop provide configuration service= to this platform. + + This function should be called when the platform is about to leave the s= afe environment. + It will notify the Redfish service provider to abort all login 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. + @retval Others Some error happened. + +**/ +EFI_STATUS +EFIAPI +LibStopRedfishService ( + IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This, + IN EDKII_REDFISH_CREDENTIAL_STOP_SERVICE_TYPE ServiceStopType + ) +{ + EFI_STATUS Status; + + if ((ServiceStopType <=3D ServiceStopTypeNone) || (ServiceStopType >=3D = ServiceStopTypeMax)) { + return EFI_INVALID_PARAMETER; + } + + // + // Only stop credential service after leaving BIOS + // + if (ServiceStopType !=3D ServiceStopTypeExitBootService) { + return EFI_UNSUPPORTED; + } + + // + // Raise flag first + // + mRedfishServiceStopped =3D TRUE; + + // + // Delete cached variable + // + Status =3D SetBootstrapAccountCredentialsToVariable (NULL, NULL, TRUE); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: fail to remove bootstrap credential: %r\n", = __FUNCTION__, Status)); + } + + DEBUG ((DEBUG_INFO, "%a: bootstrap credential service stopped\n", __FUNC= TION__)); + + 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 + ) +{ + // + // Stop the credential support when system is about to enter OS. + // + 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 + ) +{ + // + // Do nothing now. + // We can stop credential support when system reach end-of-dxe for secur= ity reason. + // +} + +/** + Function to retrieve temporary user credentials for the UEFI redfish cli= ent. This function can + also disable bootstrap credential service in BMC. + + @param[in] DisableBootstrapControl TRUE - Tell the BMC to disable th= e bootstrap credential + service to ensure no one e= lse gains credentials + FALSE Allow the bootstrap creden= tial service to continue + @param[in,out] BootstrapUsername A pointer to a Ascii encoded stri= ng for the credential username + When DisableBootstrapControl is T= RUE, this pointer can be NULL + @param[in] BootstrapUsernameSize The size of BootstrapUsername inc= luding NULL terminator in bytes. + Per specification, the size is US= ERNAME_MAX_SIZE. + @param[in,out] BootstrapPassword A pointer to a Ascii encoded stri= ng for the credential password + When DisableBootstrapControl is T= RUE, this pointer can be NULL + @param[in] BootstrapPasswordSize The size of BootstrapPassword inc= luding NULL terminator in bytes. + Per specification, the size is PA= SSWORD_MAX_SIZE. + + @retval EFI_SUCCESS Credentials were successfully fetche= d and returned. When DisableBootstrapControl + is set to TRUE, the bootstrap creden= tial service is disabled successfully. + @retval EFI_INVALID_PARAMETER BootstrapUsername or BootstrapPasswo= rd is NULL when DisableBootstrapControl + is set to FALSE. BootstrapUsernameSi= ze or BootstrapPasswordSize is incorrect when + DisableBootstrapControl is set to FA= LSE. + @retval EFI_DEVICE_ERROR An IPMI failure occurred +**/ +EFI_STATUS +GetBootstrapAccountCredentials ( + IN BOOLEAN DisableBootstrapControl, + IN OUT CHAR8 *BootstrapUsername, OPTIONAL + IN UINTN BootstrapUsernameSize, + IN OUT CHAR8 *BootstrapPassword, OPTIONAL + IN UINTN BootstrapPasswordSize + ) +{ + EFI_STATUS Status; + IPMI_BOOTSTRAP_CREDENTIALS_COMMAND_DATA CommandData; + IPMI_BOOTSTRAP_CREDENTIALS_RESULT_RESPONSE ResponseData; + UINT32 ResponseSize; + + // + // NULL buffer check + // + if (!DisableBootstrapControl && ((BootstrapUsername =3D=3D NULL) || (Boo= tstrapPassword =3D=3D NULL))) { + return EFI_INVALID_PARAMETER; + } + + if ((BootstrapUsernameSize !=3D USERNAME_MAX_SIZE) || (BootstrapPassword= Size !=3D PASSWORD_MAX_SIZE)) { + return EFI_INVALID_PARAMETER; + } + + DEBUG ((DEBUG_VERBOSE, "%a: Disable bootstrap control: 0x%x\n", __FUNCTI= ON__, DisableBootstrapControl)); + + // + // IPMI callout to NetFn 2C, command 02 + // Request data: + // Byte 1: REDFISH_IPMI_GROUP_EXTENSION + // Byte 2: DisableBootstrapControl + // + CommandData.GroupExtensionId =3D REDFISH_IPMI_GROUP_EXTENSION; + CommandData.DisableBootstrapControl =3D (DisableBootstrapControl ? REDFI= SH_IPMI_BOOTSTRAP_CREDENTIAL_DISABLE : REDFISH_IPMI_BOOTSTRAP_CREDENTIAL_EN= ABLE); + + ResponseSize =3D sizeof (ResponseData); + + // + // Response data: + // Byte 1 : Completion code + // Byte 2 : REDFISH_IPMI_GROUP_EXTENSION + // Byte 3-18 : Username + // Byte 19-34: Password + // + Status =3D IpmiSubmitCommand ( + IPMI_NETFN_GROUP_EXT, + REDFISH_IPMI_GET_BOOTSTRAP_CREDENTIALS_CMD, + (UINT8 *)&CommandData, + sizeof (CommandData), + (UINT8 *)&ResponseData, + &ResponseSize + ); + + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: IPMI transaction failure. Returning\n", __FU= NCTION__)); + return Status; + } else { + if (ResponseData.CompletionCode !=3D IPMI_COMP_CODE_NORMAL) { + if (ResponseData.CompletionCode =3D=3D REDFISH_IPMI_COMP_CODE_BOOTST= RAP_CREDENTIAL_DISABLED) { + DEBUG ((DEBUG_ERROR, "%a: bootstrap credential support was disable= d\n", __FUNCTION__)); + return EFI_ACCESS_DENIED; + } + + DEBUG ((DEBUG_ERROR, "%a: Completion code =3D 0x%x. Returning\n", __= FUNCTION__, ResponseData.CompletionCode)); + return EFI_PROTOCOL_ERROR; + } else if (ResponseData.GroupExtensionId !=3D REDFISH_IPMI_GROUP_EXTEN= SION) { + DEBUG ((DEBUG_ERROR, "%a: Group Extension Response =3D 0x%x. Returni= ng\n", __FUNCTION__, ResponseData.GroupExtensionId)); + return EFI_DEVICE_ERROR; + } else { + if (BootstrapUsername !=3D NULL) { + CopyMem (BootstrapUsername, ResponseData.Username, USERNAME_MAX_LE= NGTH); + // + // Manually append null-terminator in case 16 characters username = returned. + // + BootstrapUsername[USERNAME_MAX_LENGTH] =3D '\0'; + } + + if (BootstrapPassword !=3D NULL) { + CopyMem (BootstrapPassword, ResponseData.Password, PASSWORD_MAX_LE= NGTH); + // + // Manually append null-terminator in case 16 characters password = returned. + // + BootstrapPassword[PASSWORD_MAX_LENGTH] =3D '\0'; + } + } + } + + DEBUG ((DEBUG_INFO, "%a: get bootstrap credential via IPMI: %r\n", __FUN= CTION__, Status)); + + return Status; +} + +/** + Function to retrieve temporary user credentials from cached boot time va= riable. + + @param[in,out] BootstrapUsername A pointer to a Ascii encoded string= for the credential username. + @param[in] BootstrapUsernameSize The size of BootstrapUsername inclu= ding NULL terminator in bytes. + Per specification, the size is USER= NAME_MAX_SIZE. + @param[in,out] BootstrapPassword A pointer to a Ascii encoded string= for the credential password. + @param[in] BootstrapPasswordSize The size of BootstrapPassword inclu= ding NULL terminator in bytes. + Per specification, the size is PASS= WORD_MAX_SIZE. + + @retval EFI_SUCCESS Credentials were successfully fetche= d and returned. + @retval EFI_INVALID_PARAMETER BootstrapUsername or BootstrapPasswo= rd is NULL. + BootstrapUsernameSize or BootstrapPa= sswordSize is incorrect. + @retval EFI_NOT_FOUND No variable found for account and cr= edentials. +**/ +EFI_STATUS +GetBootstrapAccountCredentialsFromVariable ( + IN OUT CHAR8 *BootstrapUsername, + IN UINTN BootstrapUsernameSize, + IN OUT CHAR8 *BootstrapPassword, + IN UINTN BootstrapPasswordSize + ) +{ + EFI_STATUS Status; + BOOTSTRAP_CREDENTIALS_VARIABLE *CredentialVariable; + VOID *Data; + UINTN DataSize; + + if ((BootstrapUsername =3D=3D NULL) || (BootstrapPassword =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + if ((BootstrapUsernameSize !=3D USERNAME_MAX_SIZE) || (BootstrapPassword= Size !=3D PASSWORD_MAX_SIZE)) { + return EFI_INVALID_PARAMETER; + } + + DataSize =3D 0; + Status =3D GetVariable2 ( + CREDENTIAL_VARIABLE_NAME, + &gEfiRedfishVariableGuid, + (VOID *)&Data, + &DataSize + ); + if (EFI_ERROR (Status)) { + return EFI_NOT_FOUND; + } + + if (DataSize !=3D sizeof (BOOTSTRAP_CREDENTIALS_VARIABLE)) { + DEBUG ((DEBUG_ERROR, "%a: data corruption. returned size: %d !=3D stru= cture size: %d\n", __FUNCTION__, DataSize, sizeof (BOOTSTRAP_CREDENTIALS_VA= RIABLE))); + return EFI_NOT_FOUND; + } + + CredentialVariable =3D (BOOTSTRAP_CREDENTIALS_VARIABLE *)Data; + + AsciiStrCpyS (BootstrapUsername, USERNAME_MAX_SIZE, CredentialVariable->= Username); + AsciiStrCpyS (BootstrapPassword, PASSWORD_MAX_SIZE, CredentialVariable->= Password); + + ZeroMem (CredentialVariable->Username, USERNAME_MAX_SIZE); + ZeroMem (CredentialVariable->Password, PASSWORD_MAX_SIZE); + + FreePool (Data); + + DEBUG ((DEBUG_INFO, "%a: get bootstrap credential from variable\n", __FU= NCTION__)); + + return EFI_SUCCESS; +} + +/** + Function to save temporary user credentials into boot time variable. Whe= n DeleteVariable is True, + this function delete boot time variable. + + @param[in] BootstrapUsername A pointer to a Ascii encoded string f= or the credential username. + @param[in] BootstrapPassword A pointer to a Ascii encoded string f= or the credential password. + @param[in] DeleteVariable True to remove boot time variable. Fa= lse otherwise. + + @retval EFI_SUCCESS Credentials were successfully saved. + @retval EFI_INVALID_PARAMETER BootstrapUsername or BootstrapPasswo= rd is NULL + @retval Others Error occurs +**/ +EFI_STATUS +SetBootstrapAccountCredentialsToVariable ( + IN CHAR8 *BootstrapUsername, OPTIONAL + IN CHAR8 *BootstrapPassword, OPTIONAL + IN BOOLEAN DeleteVariable + ) +{ + EFI_STATUS Status; + BOOTSTRAP_CREDENTIALS_VARIABLE CredentialVariable; + VOID *Data; + + if (!DeleteVariable && ((BootstrapUsername =3D=3D NULL) || (BootstrapUse= rname[0] =3D=3D '\0'))) { + return EFI_INVALID_PARAMETER; + } + + if (!DeleteVariable && ((BootstrapPassword =3D=3D NULL) || (BootstrapPas= sword[0] =3D=3D '\0'))) { + return EFI_INVALID_PARAMETER; + } + + // + // Delete variable + // + Status =3D GetVariable2 ( + CREDENTIAL_VARIABLE_NAME, + &gEfiRedfishVariableGuid, + (VOID *)&Data, + NULL + ); + if (!EFI_ERROR (Status)) { + FreePool (Data); + gRT->SetVariable ( + CREDENTIAL_VARIABLE_NAME, + &gEfiRedfishVariableGuid, + EFI_VARIABLE_BOOTSERVICE_ACCESS, + 0, + NULL + ); + } + + // + // This is request to delete credentials. We are done. + // + if (DeleteVariable) { + return EFI_SUCCESS; + } + + ZeroMem (CredentialVariable.Username, USERNAME_MAX_SIZE); + ZeroMem (CredentialVariable.Password, PASSWORD_MAX_SIZE); + + AsciiStrCpyS (CredentialVariable.Username, USERNAME_MAX_SIZE, BootstrapU= sername); + AsciiStrCpyS (CredentialVariable.Password, PASSWORD_MAX_SIZE, BootstrapP= assword); + + Status =3D gRT->SetVariable ( + CREDENTIAL_VARIABLE_NAME, + &gEfiRedfishVariableGuid, + EFI_VARIABLE_BOOTSERVICE_ACCESS, + sizeof (BOOTSTRAP_CREDENTIALS_VARIABLE), + (VOID *)&CredentialVariable + ); + + ZeroMem (CredentialVariable.Username, USERNAME_MAX_SIZE); + ZeroMem (CredentialVariable.Password, PASSWORD_MAX_SIZE); + + return Status; +} + +/** + 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; + BOOLEAN DisableCredentialService; + + if ((AuthMethod =3D=3D NULL) || (UserId =3D=3D NULL) || (Password =3D=3D= NULL)) { + return EFI_INVALID_PARAMETER; + } + + *UserId =3D NULL; + *Password =3D NULL; + DisableCredentialService =3D PcdGetBool (PcdRedfishDisableBootstrapCrede= ntialService); + + if (mRedfishServiceStopped) { + DEBUG ((DEBUG_ERROR, "%a: credential service is stopped due to securit= y reason\n", __FUNCTION__)); + return EFI_ACCESS_DENIED; + } + + *AuthMethod =3D AuthMethodHttpBasic; + + *UserId =3D AllocateZeroPool (sizeof (CHAR8) * USERNAME_MAX_SIZE); + if (*UserId =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + *Password =3D AllocateZeroPool (sizeof (CHAR8) * PASSWORD_MAX_SIZE); + if (*Password =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // + // Get bootstrap credential from variable first + // + Status =3D GetBootstrapAccountCredentialsFromVariable (*UserId, USERNAME= _MAX_SIZE, *Password, PASSWORD_MAX_SIZE); + if (!EFI_ERROR (Status)) { + return EFI_SUCCESS; + } + + // + // Make a IPMI query + // + Status =3D GetBootstrapAccountCredentials (DisableCredentialService, *Us= erId, USERNAME_MAX_SIZE, *Password, PASSWORD_MAX_SIZE); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: fail to get bootstrap credential: %r\n", __F= UNCTION__, Status)); + return Status; + } + + if (DisableCredentialService) { + DEBUG ((DEBUG_INFO, "%a: credential bootstrapping control disabled\n",= __FUNCTION__)); + } + + Status =3D SetBootstrapAccountCredentialsToVariable (*UserId, *Password,= FALSE); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: fail to cache bootstrap credential: %r\n", _= _FUNCTION__, Status)); + } + + return EFI_SUCCESS; +} --=20 2.40.0.windows.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 (#101988): https://edk2.groups.io/g/devel/message/101988 Mute This Topic: https://groups.io/mt/97897153/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-