]> git.proxmox.com Git - mirror_edk2.git/commitdiff
EmulatorPkg/library: RedfishPlatformCredentialLib
authorAbner Chang <abner.chang@hpe.com>
Mon, 16 Nov 2020 07:21:09 +0000 (15:21 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sat, 16 Jan 2021 03:35:31 +0000 (03:35 +0000)
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 <abner.chang@hpe.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Andrew Fish <afish@apple.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Nickle Wang <nickle.wang@hpe.com>
Cc: Peter O'Hanley <peter.ohanley@hpe.com>
Acked-by: Ray Ni <ray.ni@intel.com>
EmulatorPkg/EmulatorPkg.dec
EmulatorPkg/EmulatorPkg.dsc
EmulatorPkg/Library/RedfishPlatformCredentialLib/RedfishPlatformCredentialLib.c [new file with mode: 0644]
EmulatorPkg/Library/RedfishPlatformCredentialLib/RedfishPlatformCredentialLib.inf [new file with mode: 0644]

index 5d7fe6473e35a47b0754ba665124efb819fa7ce5..b9c70b63b3ab3f71d90308cdcf89b47df77e21b3 100644 (file)
   ## Size of the packet filter\r
   gEmulatorPkgTokenSpaceGuid.PcdNetworkPacketFilterSize|524288|UINT32|0x0000101c\r
 \r
-\r
+  ## Platform level Redfish Service control PCD\r
+  # These PCDs are used to stop the Redfish sevice when secure boot is disabled\r
+  # or exit boot service.\r
+  gEmulatorPkgTokenSpaceGuid.PcdRedfishServieStopIfSecureBootDisabled|TRUE|BOOLEAN|0x00001020\r
+  gEmulatorPkgTokenSpaceGuid.PcdRedfishServieStopIfExitbootService|TRUE|BOOLEAN|0x00001021\r
+  ##\r
+  # edk2 Redfish implementation on Emulator package is designed to access\r
+  # to Redfish simulator.\r
+  # https://github.com/DMTF/Redfish-Profile-Simulator\r
+  # The user ID and password are fixed as below.\r
+  gEmulatorPkgTokenSpaceGuid.PcdRedfishServieUserId|"admin"|VOID*|0x00001022\r
+  gEmulatorPkgTokenSpaceGuid.PcdRedfishServiePassword|"pwd123456"|VOID*|0x00001023\r
 \r
 [PcdsFixedAtBuild, PcdsPatchableInModule]\r
   gEmulatorPkgTokenSpaceGuid.PcdEmuBootMode|1|UINT32|0x00001006\r
index de8144844c577eee4d67d769612b1de4e9f8582c..6bd8ed8386bf949baa7bb7b9a033caed702ae8a9 100644 (file)
   KeyMapLib|EmulatorPkg/Library/KeyMapLibNull/KeyMapLibNull.inf\r
   !if $(REDFISH_ENABLE) == TRUE\r
     RedfishPlatformHostInterfaceLib|EmulatorPkg/Library/RedfishPlatformHostInterfaceLib/RedfishPlatformHostInterfaceLib.inf\r
+    RedfishPlatformCredentialLib|EmulatorPkg/Library/RedfishPlatformCredentialLib/RedfishPlatformCredentialLib.inf\r
   !endif\r
   #\r
   # Misc\r
diff --git a/EmulatorPkg/Library/RedfishPlatformCredentialLib/RedfishPlatformCredentialLib.c b/EmulatorPkg/Library/RedfishPlatformCredentialLib/RedfishPlatformCredentialLib.c
new file mode 100644 (file)
index 0000000..5428aa3
--- /dev/null
@@ -0,0 +1,237 @@
+/** @file\r
+  EmulaotPkg RedfishPlatformCredentialLib instance\r
+\r
+  (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>\r
+\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+#include <Uefi.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiLib.h>\r
+\r
+#include <Protocol/EdkIIRedfishCredential.h>\r
+\r
+#include <Guid/GlobalVariable.h>\r
+#include <Guid/ImageAuthentication.h>\r
+\r
+BOOLEAN mSecureBootDisabled = FALSE;\r
+BOOLEAN mStopRedfishService = FALSE;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+LibStopRedfishService (\r
+  IN EDKII_REDFISH_CREDENTIAL_PROTOCOL          *This,\r
+  IN EDKII_REDFISH_CREDENTIAL_STOP_SERVICE_TYPE ServiceStopType\r
+);\r
+\r
+/**\r
+  Return the credential for accessing to Redfish servcice.\r
+\r
+  @param[out]  AuthMethod     The authentication method.\r
+  @param[out]  UserId         User ID.\r
+  @param[out]  Password       USer password.\r
+\r
+  @retval EFI_SUCCESS              Get the authentication information successfully.\r
+  @retval EFI_OUT_OF_RESOURCES     There are not enough memory resources.\r
+\r
+**/\r
+EFI_STATUS\r
+GetRedfishCredential (\r
+  OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod,\r
+  OUT CHAR8 **UserId,\r
+  OUT CHAR8 **Password\r
+)\r
+{\r
+  UINTN  UserIdSize;\r
+  UINTN  PasswordSize;\r
+\r
+  //\r
+  // AuthMethod set to HTTP Basic authentication.\r
+  //\r
+  *AuthMethod = AuthMethodHttpBasic;\r
+\r
+  //\r
+  // User ID and Password.\r
+  //\r
+  UserIdSize   = AsciiStrSize ((CHAR8 *)PcdGetPtr (PcdRedfishServieUserId));\r
+  PasswordSize = AsciiStrSize ((CHAR8 *)PcdGetPtr (PcdRedfishServiePassword));\r
+  if (UserIdSize == 0 || PasswordSize == 0) {\r
+    DEBUG ((DEBUG_ERROR, "Incorrect string of UserID or Password for REdfish service.\n"));\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  *UserId = AllocateZeroPool (UserIdSize);\r
+  if (*UserId == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  CopyMem (*UserId, (CHAR8 *)PcdGetPtr (PcdRedfishServieUserId), UserIdSize);\r
+\r
+  *Password = AllocateZeroPool (PasswordSize);\r
+  if (*Password == NULL) {\r
+    FreePool (*UserId);\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  CopyMem (*Password, (CHAR8 *)PcdGetPtr (PcdRedfishServiePassword), PasswordSize);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Retrieve platform's Redfish authentication information.\r
+\r
+  This functions returns the Redfish authentication method together with the user Id and\r
+  password.\r
+  - For AuthMethodNone, the UserId and Password could be used for HTTP header authentication\r
+    as defined by RFC7235.\r
+  - For AuthMethodRedfishSession, the UserId and Password could be used for Redfish\r
+    session login as defined by  Redfish API specification (DSP0266).\r
+\r
+  Callers are responsible for and freeing the returned string storage.\r
+\r
+  @param[in]   This                Pointer to EDKII_REDFISH_CREDENTIAL_PROTOCOL instance.\r
+  @param[out]  AuthMethod          Type of Redfish authentication method.\r
+  @param[out]  UserId              The pointer to store the returned UserId string.\r
+  @param[out]  Password            The pointer to store the returned Password string.\r
+\r
+  @retval EFI_SUCCESS              Get the authentication information successfully.\r
+  @retval EFI_ACCESS_DENIED        SecureBoot is disabled after EndOfDxe.\r
+  @retval EFI_INVALID_PARAMETER    This or AuthMethod or UserId or Password is NULL.\r
+  @retval EFI_OUT_OF_RESOURCES     There are not enough memory resources.\r
+  @retval EFI_UNSUPPORTED          Unsupported authentication method is found.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+LibCredentialGetAuthInfo (\r
+  IN  EDKII_REDFISH_CREDENTIAL_PROTOCOL  *This,\r
+  OUT EDKII_REDFISH_AUTH_METHOD          *AuthMethod,\r
+  OUT CHAR8                              **UserId,\r
+  OUT CHAR8                              **Password\r
+)\r
+{\r
+  EFI_STATUS                   Status;\r
+\r
+  if (This == NULL || AuthMethod == NULL || UserId == NULL || Password == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (mStopRedfishService) {\r
+    return EFI_ACCESS_DENIED;\r
+  }\r
+\r
+  if (mSecureBootDisabled) {\r
+    Status = LibStopRedfishService (This, ServiceStopTypeSecureBootDisabled);\r
+    if (EFI_ERROR (Status) && Status != EFI_UNSUPPORTED) {\r
+      DEBUG ((DEBUG_ERROR, "SecureBoot has been disabled, but failed to stop RedfishService - %r\n", Status));\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  Status = GetRedfishCredential (\r
+             AuthMethod,\r
+             UserId,\r
+             Password\r
+             );\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Notify the Redfish service to stop provide configuration service to this platform.\r
+\r
+  This function should be called when the platfrom is about to leave the safe environment.\r
+  It will notify the Redfish service provider to abort all logined session, and prohibit\r
+  further login with original auth info. GetAuthInfo() will return EFI_UNSUPPORTED once this\r
+  function is returned.\r
+\r
+  @param[in]   This                Pointer to EDKII_REDFISH_CREDENTIAL_PROTOCOL instance.\r
+  @param[in]   ServiceStopType     Reason of stopping Redfish service.\r
+\r
+  @retval EFI_SUCCESS              Service has been stoped successfully.\r
+  @retval EFI_INVALID_PARAMETER    This is NULL or given the worng ServiceStopType.\r
+  @retval EFI_UNSUPPORTED          Not support to stop Redfish service.\r
+  @retval Others                   Some error happened.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+LibStopRedfishService (\r
+  IN EDKII_REDFISH_CREDENTIAL_PROTOCOL    *This,\r
+  IN EDKII_REDFISH_CREDENTIAL_STOP_SERVICE_TYPE ServiceStopType\r
+)\r
+{\r
+  if (ServiceStopType >= ServiceStopTypeMax) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (ServiceStopType == ServiceStopTypeSecureBootDisabled) {\r
+    //\r
+    // Check platform PCD to determine the action for stopping\r
+    // Redfish service due to secure boot is disabled.\r
+    //\r
+    if (!PcdGetBool (PcdRedfishServieStopIfSecureBootDisabled)) {\r
+      return EFI_UNSUPPORTED;\r
+    } else {\r
+      mStopRedfishService = TRUE;\r
+      DEBUG ((DEBUG_INFO, "EFI Redfish service is stopped due to SecureBoot is disabled!!\n"));\r
+    }\r
+  } else if (ServiceStopType == ServiceStopTypeExitBootService) {\r
+    //\r
+    // Check platform PCD to determine the action for stopping\r
+    // Redfish service due to exit boot service.\r
+    //\r
+    if (PcdGetBool (PcdRedfishServieStopIfExitbootService)) {\r
+      return EFI_UNSUPPORTED;\r
+    } else {\r
+      mStopRedfishService = TRUE;\r
+      DEBUG ((DEBUG_INFO, "EFI Redfish service is stopped due to Exit Boot Service!!\n"));\r
+    }\r
+  } else {\r
+    mStopRedfishService = TRUE;\r
+    DEBUG ((DEBUG_INFO, "EFI Redfish service is stopped without Redfish service stop type!!\n"));\r
+  }\r
+  return EFI_SUCCESS;\r
+}\r
+/**\r
+  Notification of Exit Boot Service.\r
+\r
+  @param[in]  This    Pointer to EDKII_REDFISH_CREDENTIAL_PROTOCOL.\r
+**/\r
+VOID\r
+EFIAPI\r
+LibCredentialExitBootServicesNotify (\r
+  IN  EDKII_REDFISH_CREDENTIAL_PROTOCOL  *This\r
+)\r
+{\r
+  LibStopRedfishService (This, ServiceStopTypeExitBootService);\r
+}\r
+\r
+/**\r
+  Notification of End of DXE.\r
+\r
+  @param[in]  This    Pointer to EDKII_REDFISH_CREDENTIAL_PROTOCOL.\r
+**/\r
+VOID\r
+EFIAPI\r
+LibCredentialEndOfDxeNotify (\r
+  IN  EDKII_REDFISH_CREDENTIAL_PROTOCOL  *This\r
+)\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT8  *SecureBootVar;\r
+\r
+  //\r
+  // Check Secure Boot status and lock Redfish service if Secure Boot is disabled.\r
+  //\r
+  Status = GetVariable2 (EFI_SECURE_BOOT_MODE_NAME, &gEfiGlobalVariableGuid, (VOID**)&SecureBootVar, NULL);\r
+  if (EFI_ERROR (Status) || (*SecureBootVar != SECURE_BOOT_MODE_ENABLE)) {\r
+    //\r
+    // Secure Boot is disabled\r
+    //\r
+    mSecureBootDisabled = TRUE;\r
+    LibStopRedfishService (This, ServiceStopTypeSecureBootDisabled);\r
+  }\r
+}\r
diff --git a/EmulatorPkg/Library/RedfishPlatformCredentialLib/RedfishPlatformCredentialLib.inf b/EmulatorPkg/Library/RedfishPlatformCredentialLib/RedfishPlatformCredentialLib.inf
new file mode 100644 (file)
index 0000000..41c389c
--- /dev/null
@@ -0,0 +1,49 @@
+## @file\r
+#  NT32 instance of RedfishPlatformCredentialLib\r
+#\r
+#  (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>\r
+#\r
+#  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x0001000b\r
+  BASE_NAME                      = RedfishPlatformCredentialLib\r
+  FILE_GUID                      = 00CF32A8-495C-3ED8-7C68-E9BB86810EE0\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = RedfishPlatformCredentialLib\r
+\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64\r
+#\r
+\r
+[Sources]\r
+  RedfishPlatformCredentialLib.c\r
+\r
+[Packages]\r
+  EmulatorPkg/EmulatorPkg.dec\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  RedfishPkg/RedfishPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  DebugLib\r
+  PcdLib\r
+  UefiBootServicesTableLib\r
+  UefiLib\r
+\r
+[Pcd]\r
+  gEmulatorPkgTokenSpaceGuid.PcdRedfishServieStopIfSecureBootDisabled ## CONSUMES\r
+  gEmulatorPkgTokenSpaceGuid.PcdRedfishServieStopIfExitbootService    ## CONSUMES\r
+  gEmulatorPkgTokenSpaceGuid.PcdRedfishServieUserId                   ## CONSUMES\r
+  gEmulatorPkgTokenSpaceGuid.PcdRedfishServiePassword                 ## CONSUMES\r
+\r
+[Guids]\r
+  gEfiGlobalVariableGuid\r
+\r
+[Depex]\r
+  gEfiVariableArchProtocolGuid\r
+\r