EnrollDefaultKeys.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /** @file
  2. Type definitions and object declarations for the EnrollDefaultKeys
  3. application.
  4. Copyright (C) 2014-2019, Red Hat, Inc.
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #ifndef ENROLL_DEFAULT_KEYS_H_
  8. #define ENROLL_DEFAULT_KEYS_H_
  9. #include <Uefi/UefiBaseType.h>
  10. //
  11. // Convenience structure types for constructing "signature lists" for
  12. // authenticated UEFI variables.
  13. //
  14. // The most important thing about the variable payload is that it is a list of
  15. // lists, where the element size of any given *inner* list is constant.
  16. //
  17. // Since X509 certificates vary in size, each of our *inner* lists will contain
  18. // one element only (one X.509 certificate). This is explicitly mentioned in
  19. // the UEFI specification, in "28.4.1 Signature Database", in a Note.
  20. //
  21. // The list structure looks as follows:
  22. //
  23. // struct EFI_VARIABLE_AUTHENTICATION_2 { |
  24. // struct EFI_TIME { |
  25. // UINT16 Year; |
  26. // UINT8 Month; |
  27. // UINT8 Day; |
  28. // UINT8 Hour; |
  29. // UINT8 Minute; |
  30. // UINT8 Second; |
  31. // UINT8 Pad1; |
  32. // UINT32 Nanosecond; |
  33. // INT16 TimeZone; |
  34. // UINT8 Daylight; |
  35. // UINT8 Pad2; |
  36. // } TimeStamp; |
  37. // |
  38. // struct WIN_CERTIFICATE_UEFI_GUID { | |
  39. // struct WIN_CERTIFICATE { | |
  40. // UINT32 dwLength; ----------------------------------------+ |
  41. // UINT16 wRevision; | |
  42. // UINT16 wCertificateType; | |
  43. // } Hdr; | +- DataSize
  44. // | |
  45. // EFI_GUID CertType; | |
  46. // UINT8 CertData[1] = { <--- "struct hack" | |
  47. // struct EFI_SIGNATURE_LIST { | | |
  48. // EFI_GUID SignatureType; | | |
  49. // UINT32 SignatureListSize; -------------------------+ | |
  50. // UINT32 SignatureHeaderSize; | | |
  51. // UINT32 SignatureSize; ---------------------------+ | | |
  52. // UINT8 SignatureHeader[SignatureHeaderSize]; | | | |
  53. // v | | |
  54. // struct EFI_SIGNATURE_DATA { | | | |
  55. // EFI_GUID SignatureOwner; | | | |
  56. // UINT8 SignatureData[1] = { <--- "struct hack" | | | |
  57. // X.509 payload | | | |
  58. // } | | | |
  59. // } Signatures[]; | | |
  60. // } SigLists[]; | |
  61. // }; | |
  62. // } AuthInfo; | |
  63. // }; |
  64. //
  65. // Given that the "struct hack" invokes undefined behavior (which is why C99
  66. // introduced the flexible array member), and because subtracting those pesky
  67. // sizes of 1 is annoying, and because the format is fully specified in the
  68. // UEFI specification, we'll introduce two matching convenience structures that
  69. // are customized for our X.509 purposes.
  70. //
  71. #pragma pack (1)
  72. typedef struct {
  73. EFI_TIME TimeStamp;
  74. //
  75. // dwLength covers data below
  76. //
  77. UINT32 dwLength;
  78. UINT16 wRevision;
  79. UINT16 wCertificateType;
  80. EFI_GUID CertType;
  81. } SINGLE_HEADER;
  82. typedef struct {
  83. //
  84. // SignatureListSize covers data below
  85. //
  86. EFI_GUID SignatureType;
  87. UINT32 SignatureListSize;
  88. UINT32 SignatureHeaderSize; // constant 0
  89. UINT32 SignatureSize;
  90. //
  91. // SignatureSize covers data below
  92. //
  93. EFI_GUID SignatureOwner;
  94. //
  95. // X.509 certificate follows
  96. //
  97. } REPEATING_HEADER;
  98. #pragma pack ()
  99. //
  100. // A structure that collects the values of UEFI variables related to Secure
  101. // Boot.
  102. //
  103. typedef struct {
  104. UINT8 SetupMode;
  105. UINT8 SecureBoot;
  106. UINT8 SecureBootEnable;
  107. UINT8 CustomMode;
  108. UINT8 VendorKeys;
  109. } SETTINGS;
  110. //
  111. // Refer to "AuthData.c" for details on the following objects.
  112. //
  113. extern CONST UINT8 mMicrosoftKek[];
  114. extern CONST UINTN mSizeOfMicrosoftKek;
  115. extern CONST UINT8 mMicrosoftPca[];
  116. extern CONST UINTN mSizeOfMicrosoftPca;
  117. extern CONST UINT8 mMicrosoftUefiCa[];
  118. extern CONST UINTN mSizeOfMicrosoftUefiCa;
  119. extern CONST UINT8 mSha256OfDevNull[];
  120. extern CONST UINTN mSizeOfSha256OfDevNull;
  121. #endif /* ENROLL_DEFAULT_KEYS_H_ */