DxeImageAuthenticationStatusLib.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /** @file
  2. Implement image authentication status check in UEFI2.3.1.
  3. Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <PiDxe.h>
  7. #include <Library/SecurityManagementLib.h>
  8. /**
  9. Check image authentication status returned from Section Extraction Protocol
  10. @param[in] AuthenticationStatus This is the authentication status returned from
  11. the Section Extraction Protocol when reading the input file.
  12. @param[in] File This is a pointer to the device path of the file that is
  13. being dispatched. This will optionally be used for logging.
  14. @param[in] FileBuffer File buffer matches the input file device path.
  15. @param[in] FileSize Size of File buffer matches the input file device path.
  16. @param[in] BootPolicy A boot policy that was used to call LoadImage() UEFI service.
  17. @retval EFI_SUCCESS The input file specified by File did authenticate, and the
  18. platform policy dictates that the DXE Core may use File.
  19. @retval EFI_ACCESS_DENIED The file specified by File and FileBuffer did not
  20. authenticate, and the platform policy dictates that the DXE
  21. Foundation many not use File.
  22. **/
  23. EFI_STATUS
  24. EFIAPI
  25. DxeImageAuthenticationStatusHandler (
  26. IN UINT32 AuthenticationStatus,
  27. IN CONST EFI_DEVICE_PATH_PROTOCOL *File,
  28. IN VOID *FileBuffer,
  29. IN UINTN FileSize,
  30. IN BOOLEAN BootPolicy
  31. )
  32. {
  33. if ((AuthenticationStatus & EFI_AUTH_STATUS_IMAGE_SIGNED) != 0) {
  34. if ((AuthenticationStatus & (EFI_AUTH_STATUS_TEST_FAILED | EFI_AUTH_STATUS_NOT_TESTED)) != 0) {
  35. return EFI_ACCESS_DENIED;
  36. }
  37. }
  38. return EFI_SUCCESS;
  39. }
  40. /**
  41. Register image authentication status check handler.
  42. @param ImageHandle ImageHandle of the loaded driver.
  43. @param SystemTable Pointer to the EFI System Table.
  44. @retval EFI_SUCCESS The handlers were registered successfully.
  45. **/
  46. EFI_STATUS
  47. EFIAPI
  48. DxeImageAuthenticationStatusLibConstructor (
  49. IN EFI_HANDLE ImageHandle,
  50. IN EFI_SYSTEM_TABLE *SystemTable
  51. )
  52. {
  53. return RegisterSecurity2Handler (
  54. DxeImageAuthenticationStatusHandler,
  55. EFI_AUTH_OPERATION_AUTHENTICATION_STATE
  56. );
  57. }