From nobody Thu Apr 25 01:48:19 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+100830+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 1678260063089475.80613202698635; Tue, 7 Mar 2023 23:21:03 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id kbMMYY1788612xYYi0LSA7gg; Tue, 07 Mar 2023 23:21:02 -0800 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.78]) by mx.groups.io with SMTP id smtpd.web10.1713.1678260061845361535 for ; Tue, 07 Mar 2023 23:21:02 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NbPIr1WySvlOxHyej83dB8mHiljsPRLMu3qeNyn336OEgI19urRzMFlwF9fi5xD9Gb9J5yqz8eQ+ojrCI5PP1WPjIAxZ+7eCPVUO76UTUDSowTE2a0Hf5r8ZOKuEWz7WqLnuMgo2Bcdez2UvXQo3bgAKnDWrfVr4FjX2/L3dvdkulGrv2a+tU/zUbx+r20b7HcF6H55uvnzlvuv9xnrffqPNdWMJw2mXE8LwjGMOGavZCZtlU5GxAJqEOGbyy0wqzgTWV9Lleqt1ffVyyqID0kwWJMC9/SP/8xQvKQJNg4SHPN51q7ME86vcKYnlxMlo/Pi33JtILYWya1VoviZGrA== 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=b5ZrTwmKjinmmLAlm1UNAjLvtzOX8M4wnS9n9lszmAY=; b=alzbiIgY1uIvCX/NJKVaVlp9V78gIo7SuQap1/jX7g2x4+z0XrfdFQzlhcTYVJpT8ElB5tDD9ccowbtigK7yCqt1yNgFqy8CV6by6ob4KdI4jNLPZFt+bqmZaEpa6rRJUUJbKvJ9d8OE/kG+tDS43zkpJPmU/X9G+5YXKXJy81tbGu0B+q0M25UU1lLud6U5jsp1JBzuk46uv0mqwjlEf38gH3jwUvXtVXfSYzOTLPGgqeoTgaO1AzelT3YSY9KK903XnMg5eRCfEif1c7RZ+d4zhg//84URjSUBPQBcACZ4s/nsyABoi38STlDLjIiV5yXissrjpnkLbw4yOkAO2w== 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 CY5PR19CA0024.namprd19.prod.outlook.com (2603:10b6:930:15::17) by DS0PR12MB8454.namprd12.prod.outlook.com (2603:10b6:8:15e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.29; Wed, 8 Mar 2023 07:20:58 +0000 X-Received: from CY4PEPF0000C978.namprd02.prod.outlook.com (2603:10b6:930:15:cafe::50) by CY5PR19CA0024.outlook.office365.com (2603:10b6:930:15::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.17 via Frontend Transport; Wed, 8 Mar 2023 07:20:58 +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+100830+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 CY4PEPF0000C978.mail.protection.outlook.com (10.167.241.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.12 via Frontend Transport; Wed, 8 Mar 2023 07:20:57 +0000 X-Received: from rnnvmail202.nvidia.com (10.129.68.7) 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; Tue, 7 Mar 2023 23:20:49 -0800 X-Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Tue, 7 Mar 2023 23:20:48 -0800 X-Received: from NV-CL38DL3.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.5 via Frontend Transport; Tue, 7 Mar 2023 23:20:48 -0800 From: "Nickle Wang via groups.io" To: CC: Abner Chang , Igor Kulchytskyy , "Nick Ramirez" Subject: [edk2-devel] [PATCH] RedfishPkg/RedfishPlatformCredentialIpmiLib: IPMI implementation Date: Wed, 8 Mar 2023 15:20:48 +0800 Message-ID: <20230308072048.354-1-nicklew@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000C978:EE_|DS0PR12MB8454:EE_ X-MS-Office365-Filtering-Correlation-Id: 2e362081-f182-42ba-d319-08db1fa5a9aa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: D0wPSiEx3XCIWD/3LLyQfUhiDZm1lEkxRPeGMy7qux5kr9CcBv7BuB5gQqAB7ME+Jwo8JX+mt4aYT4UqDCOh/AkDOx7EwkAEL51gFMHrvmUR1Bb/0NitYQlun7lVi5vqZMDriIfzF4CXjHawAM6R9XutTLbvRezSIcjt6+UOql8iQm34p9BVHJl2cgxmgcbU4KvzSB+d5keaoMNILL3BHny6QAnivVijrwnE0KKsw8IUQcIZgKiMcC+lZwcHju+5kSiqMV6UB/cSl+hqvodM9uit1HxDLPVYzbMnW+CP06MBWkRBtE6mYAgmpkls3am76vmKs1iuMbfI4IuYA3yhF/zdoSUpNcplAFvF/mYbGXfaAhX9BEeKP52zGZayeE+UV8qfZLVQ5au4DEBbPlhfEo3JhSCofKVmdQgOKzCqYTVueQ38xyHrmB0tGNlKDcuGRvHHXHm6W1ytjVm5NtwR4ua3IYpspA2b2SBzvTodTPAh2oYVzbEJVnKdIVrBCeiOU3NpfosNl2UA4gyGUOu3NfhzBtz3aVrkl7+hWErCIbHTwR1JKGrjcxXkT0NDCyYTsqe6X9vutEbZ+kpiBSOZ1rSwgylCFGu6yFalWfzGD0/OvyoPWxu+Ai5HmivxVL01+MO0ho+rBUVx9sIZomoZDjmpUjEgxyuazJU2WIJ1YGN0HjhiFR3fw619uTqB5N3xY1pOjhyi4JbutrK7iP2rFxIE0V7l9Ukgkx/hyaUXkX9ycjAPDXqhBnbnUnrdtNvQxt6tvy0sZL8oprsaveYlyQ== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2023 07:20:57.8572 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2e362081-f182-42ba-d319-08db1fa5a9aa 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: CY4PEPF0000C978.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8454 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: c9Q0JjqcuiMYy2OMNMs9te1Wx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1678260062; bh=Fp1LVl6KGbVNB28E+clygfP4PH9insL/Tl6i9VFWIps=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=hBZ3ZA23Ee/kvpveQRNK8ZuYZ2gpCJm+zR2Im4Fbxc7e7M8iwyHEcU+c1FeZQZ0Gfwh Pzqe8bIEheGag1OGj+xO/0v3Qo7qazm7inXsbUpN8Oh+fqtNX1F3QGH8QWY/k1A0qwQsM c4z6TDmSd8QNo8GHejo5gwylVD/Fd8tuig4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1678260064807100002 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 --- .../RedfishPlatformCredentialIpmiLib.c | 443 ++++++++++++++++++ .../RedfishPlatformCredentialIpmiLib.h | 86 ++++ .../RedfishPlatformCredentialIpmiLib.inf | 42 ++ RedfishPkg/RedfishPkg.dec | 7 + RedfishPkg/RedfishPkg.dsc | 2 + 5 files changed, 580 insertions(+) create mode 100644 RedfishPkg/Library/RedfishPlatformCredentialIpmi/Redfis= hPlatformCredentialIpmiLib.c create mode 100644 RedfishPkg/Library/RedfishPlatformCredentialIpmi/Redfis= hPlatformCredentialIpmiLib.h create mode 100644 RedfishPkg/Library/RedfishPlatformCredentialIpmi/Redfis= hPlatformCredentialIpmiLib.inf diff --git a/RedfishPkg/Library/RedfishPlatformCredentialIpmi/RedfishPlatfo= rmCredentialIpmiLib.c b/RedfishPkg/Library/RedfishPlatformCredentialIpmi/Re= dfishPlatformCredentialIpmiLib.c new file mode 100644 index 0000000000..2706b8508b --- /dev/null +++ b/RedfishPkg/Library/RedfishPlatformCredentialIpmi/RedfishPlatformCrede= ntialIpmiLib.c @@ -0,0 +1,443 @@ +/** @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; + + // + // Notify BMC to disable credential bootstrapping support. + // + if (PcdGetBool (PcdRedfishDisableBootstrapCredentialService)) { + Status =3D GetBootstrapAccountCredentials (TRUE, NULL, NULL); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: fail to disable bootstrap credential: %r\n= ", __FUNCTION__, Status)); + return Status; + } + } + + // + // 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 the b= ootstrap credential + service to ensure no one else= gains credentials + FALSE Allow the bootstrap credentia= l service to continue + @param[in,out] BootstrapUsername + A pointer to a Ascii encoded string = for the credential username + When DisableBootstrapControl is TRUE= , this pointer can be NULL + + @param[in,out] BootstrapPassword + A pointer to a Ascii encoded string = for the credential password + When DisableBootstrapControl is TRUE= , this pointer can be NULL + + @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 + @retval EFI_DEVICE_ERROR An IPMI failure occurred +**/ +EFI_STATUS +GetBootstrapAccountCredentials ( + IN BOOLEAN DisableBootstrapControl, + IN OUT CHAR8 *BootstrapUsername, OPTIONAL + IN OUT CHAR8 *BootstrapPassword OPTIONAL + ) +{ + 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; + } + + 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,out] BootstrapPassword A pointer to a Ascii encoded string = for the credential password + + @retval EFI_SUCCESS Credentials were successfully fetche= d and returned + @retval EFI_INVALID_PARAMETER BootstrapUsername or BootstrapPasswo= rd is NULL + @retval EFI_NOT_FOUND No variable found for account and cr= edentials +**/ +EFI_STATUS +GetBootstrapAccountCredentialsFromVariable ( + IN OUT CHAR8 *BootstrapUsername, + IN OUT CHAR8 *BootstrapPassword + ) +{ + EFI_STATUS Status; + BOOTSTRAP_CREDENTIALS_VARIABLE *CredentialVariable; + VOID *Data; + UINTN DataSize; + + if ((BootstrapUsername =3D=3D NULL) || (BootstrapPassword =3D=3D NULL)) { + 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 + // + if (DeleteVariable) { + 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); + } + + 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); + + // + // Check if variable exists already. If yes, remove it first. + // + 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); + } + + Status =3D gRT->SetVariable (CREDENTIAL_VARIABLE_NAME, &gEfiRedfishVaria= bleGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS, sizeof (BOOTSTRAP_CREDENTIALS_VAR= IABLE), (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; + + if ((AuthMethod =3D=3D NULL) || (UserId =3D=3D NULL) || (Password =3D=3D= NULL)) { + return EFI_INVALID_PARAMETER; + } + + *UserId =3D NULL; + *Password =3D NULL; + + 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, *Passwor= d); + if (!EFI_ERROR (Status)) { + return EFI_SUCCESS; + } + + // + // Make a IPMI query + // + Status =3D GetBootstrapAccountCredentials (FALSE, *UserId, *Password); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: fail to get bootstrap credential: %r\n", __F= UNCTION__, Status)); + return Status; + } + + 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; +} diff --git a/RedfishPkg/Library/RedfishPlatformCredentialIpmi/RedfishPlatfo= rmCredentialIpmiLib.h b/RedfishPkg/Library/RedfishPlatformCredentialIpmi/Re= dfishPlatformCredentialIpmiLib.h new file mode 100644 index 0000000000..5325767eab --- /dev/null +++ b/RedfishPkg/Library/RedfishPlatformCredentialIpmi/RedfishPlatformCrede= ntialIpmiLib.h @@ -0,0 +1,86 @@ +/** @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 the b= ootstrap credential + service to ensure no one else= gains credentials + FALSE Allow the bootstrap credentia= l service to continue + @param[out] BootstrapUsername + A pointer to a Ascii encoded string = for the credential username + When DisableBootstrapControl is TRUE= , this pointer can be NULL + + @param[out] BootstrapPassword + A pointer to a Ascii encoded string = for the credential password + When DisableBootstrapControl is TRUE= , this pointer can be NULL + + @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 + @retval EFI_DEVICE_ERROR An IPMI failure occurred +**/ +EFI_STATUS +GetBootstrapAccountCredentials ( + IN BOOLEAN DisableBootstrapControl, + IN OUT CHAR8 *BootstrapUsername, + IN OUT CHAR8 *BootstrapPassword + ); + +/** + 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/RedfishPlatformCredentialIpmi/RedfishPlatfo= rmCredentialIpmiLib.inf b/RedfishPkg/Library/RedfishPlatformCredentialIpmi/= RedfishPlatformCredentialIpmiLib.inf new file mode 100644 index 0000000000..694e401ad9 --- /dev/null +++ b/RedfishPkg/Library/RedfishPlatformCredentialIpmi/RedfishPlatformCrede= ntialIpmiLib.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 + IpmiBaseLib + MemoryAllocationLib + BaseMemoryLib + UefiRuntimeServicesTableLib + +[Pcd] + gEfiRedfishPkgTokenSpaceGuid.PcdRedfishDisableBootstrapCredentialService + +[Guids] + gEfiRedfishVariableGuid + +[Depex] + TRUE diff --git a/RedfishPkg/RedfishPkg.dec b/RedfishPkg/RedfishPkg.dec index 53e52c2b00..86102b8ffd 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. @@ -113,3 +116,7 @@ # Default is set to not add. # gEfiRedfishPkgTokenSpaceGuid.PcdRedfishRestExAddingExpect|FALSE|BOOLEAN|= 0x00001004 + # + # This PCD indicates that if BMC bootstrap credential service will be di= sabled by BIOS or not. + # + gEfiRedfishPkgTokenSpaceGuid.PcdRedfishDisableBootstrapCredentialService= |FALSE|BOOLEAN|0x00001005 diff --git a/RedfishPkg/RedfishPkg.dsc b/RedfishPkg/RedfishPkg.dsc index cf25b63cc2..f2ca212bea 100644 --- a/RedfishPkg/RedfishPkg.dsc +++ b/RedfishPkg/RedfishPkg.dsc @@ -3,6 +3,7 @@ # # Copyright (c) 2019 - 2021, Intel Corporation. All rights reserved.
# (C) Copyright 2021 Hewlett-Packard Enterprise Development LP. +# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -52,6 +53,7 @@ [Components] RedfishPkg/Library/PlatformHostInterfaceLibNull/PlatformHostInterfaceLib= Null.inf RedfishPkg/Library/PlatformCredentialLibNull/PlatformCredentialLibNull.i= nf + RedfishPkg/Library/RedfishPlatformCredentialIpmi/RedfishPlatformCredenti= alIpmiLib.inf RedfishPkg/Library/RedfishContentCodingLibNull/RedfishContentCodingLibNu= ll.inf RedfishPkg/Library/DxeRestExLib/DxeRestExLib.inf RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf --=20 2.39.2.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 (#100830): https://edk2.groups.io/g/devel/message/100830 Mute This Topic: https://groups.io/mt/97468065/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-