]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | This library class defines a set of interfaces to abstract the policy of\r | |
3 | security measurement by managing the different security measurement services.\r | |
4 | The library instances can be implemented according to the different security policy.\r | |
5 | \r | |
6 | Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r | |
7 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
8 | \r | |
9 | **/\r | |
10 | \r | |
11 | #ifndef __SECURITY_MANAGEMENT_LIB_H__\r | |
12 | #define __SECURITY_MANAGEMENT_LIB_H__\r | |
13 | \r | |
14 | //\r | |
15 | // Authentication Operation defintions for User Identity (UID), Measured and Secure boot.\r | |
16 | //\r | |
17 | #define EFI_AUTH_OPERATION_NONE 0x00\r | |
18 | #define EFI_AUTH_OPERATION_VERIFY_IMAGE 0x01\r | |
19 | #define EFI_AUTH_OPERATION_DEFER_IMAGE_LOAD 0x02\r | |
20 | #define EFI_AUTH_OPERATION_MEASURE_IMAGE 0x04\r | |
21 | #define EFI_AUTH_OPERATION_CONNECT_POLICY 0x08\r | |
22 | //\r | |
23 | // Authentication State Operation will check the authentication status of a file.\r | |
24 | //\r | |
25 | #define EFI_AUTH_OPERATION_AUTHENTICATION_STATE 0x10\r | |
26 | \r | |
27 | ///\r | |
28 | /// Image buffer is required by the security handler.\r | |
29 | ///\r | |
30 | #define EFI_AUTH_OPERATION_IMAGE_REQUIRED 0x80000000\r | |
31 | \r | |
32 | /**\r | |
33 | The security handler is used to abstract platform-specific policy\r | |
34 | from the DXE core response to an attempt to use a file that returns a\r | |
35 | given status for the authentication check from the section extraction protocol.\r | |
36 | \r | |
37 | The possible responses in a given SAP implementation may include locking\r | |
38 | flash upon failure to authenticate, attestation logging for all signed drivers,\r | |
39 | and other exception operations. The File parameter allows for possible logging\r | |
40 | within the SAP of the driver.\r | |
41 | \r | |
42 | If File is NULL, then EFI_INVALID_PARAMETER is returned.\r | |
43 | \r | |
44 | If the file specified by File with an authentication status specified by\r | |
45 | AuthenticationStatus is safe for the DXE Core to use, then EFI_SUCCESS is returned.\r | |
46 | \r | |
47 | If the file specified by File with an authentication status specified by\r | |
48 | AuthenticationStatus is not safe for the DXE Core to use under any circumstances,\r | |
49 | then EFI_ACCESS_DENIED is returned.\r | |
50 | \r | |
51 | If the file specified by File with an authentication status specified by\r | |
52 | AuthenticationStatus is not safe for the DXE Core to use at the time, but it\r | |
53 | might be possible to use it at a future time, then EFI_SECURITY_VIOLATION is\r | |
54 | returned.\r | |
55 | \r | |
56 | FileBuffer will be NULL and FileSize will be 0 if the handler being called\r | |
57 | did not set EFI_AUTH_OPERATION_IMAGE_REQUIRED when it was registered.\r | |
58 | \r | |
59 | @param[in] AuthenticationStatus\r | |
60 | The authentication status returned from the security\r | |
61 | measurement services for the input file.\r | |
62 | @param[in] File The pointer to the device path of the file that is\r | |
63 | being dispatched. This will optionally be used for logging.\r | |
64 | @param[in] FileBuffer The file buffer matches the input file device path.\r | |
65 | @param[in] FileSize The size of File buffer matches the input file device path.\r | |
66 | \r | |
67 | @retval EFI_SUCCESS The file specified by File did authenticate, and the\r | |
68 | platform policy dictates that the DXE Core may use File.\r | |
69 | @retval EFI_INVALID_PARAMETER The file is NULL.\r | |
70 | @retval EFI_SECURITY_VIOLATION The file specified by File did not authenticate, and\r | |
71 | the platform policy dictates that File should be placed\r | |
72 | in the untrusted state. A file may be promoted from\r | |
73 | the untrusted to the trusted state at a future time\r | |
74 | with a call to the Trust() DXE Service.\r | |
75 | @retval EFI_ACCESS_DENIED The file specified by File did not authenticate, and\r | |
76 | the platform policy dictates that File should not be\r | |
77 | used for any purpose.\r | |
78 | \r | |
79 | **/\r | |
80 | typedef\r | |
81 | EFI_STATUS\r | |
82 | (EFIAPI *SECURITY_FILE_AUTHENTICATION_STATE_HANDLER)(\r | |
83 | IN OUT UINT32 AuthenticationStatus,\r | |
84 | IN CONST EFI_DEVICE_PATH_PROTOCOL *File,\r | |
85 | IN VOID *FileBuffer,\r | |
86 | IN UINTN FileSize\r | |
87 | );\r | |
88 | \r | |
89 | /**\r | |
90 | Register security measurement handler with its operation type. Different\r | |
91 | handlers with the same operation can all be registered.\r | |
92 | \r | |
93 | If SecurityHandler is NULL, then ASSERT().\r | |
94 | If no enough resources available to register new handler, then ASSERT().\r | |
95 | If AuthenticationOperation is not recongnized, then ASSERT().\r | |
96 | If the previous register handler can't be executed before the later register handler, then ASSERT().\r | |
97 | \r | |
98 | @param[in] SecurityHandler The security measurement service handler to be registered.\r | |
99 | @param[in] AuthenticationOperation Theoperation type is specified for the registered handler.\r | |
100 | \r | |
101 | @retval EFI_SUCCESS The handlers were registered successfully.\r | |
102 | **/\r | |
103 | EFI_STATUS\r | |
104 | EFIAPI\r | |
105 | RegisterSecurityHandler (\r | |
106 | IN SECURITY_FILE_AUTHENTICATION_STATE_HANDLER SecurityHandler,\r | |
107 | IN UINT32 AuthenticationOperation\r | |
108 | );\r | |
109 | \r | |
110 | /**\r | |
111 | Execute registered handlers until one returns an error and that error is returned.\r | |
112 | If none of the handlers return an error, then EFI_SUCCESS is returned.\r | |
113 | \r | |
114 | Before exectue handler, get the image buffer by file device path if a handler\r | |
115 | requires the image file. And return the image buffer to each handler when exectue handler.\r | |
116 | \r | |
117 | The handlers are executed in same order to their registered order.\r | |
118 | \r | |
119 | @param[in] AuthenticationStatus\r | |
120 | This is the authentication type returned from the Section\r | |
121 | Extraction protocol. See the Section Extraction Protocol\r | |
122 | Specification for details on this type.\r | |
123 | @param[in] FilePath This is a pointer to the device path of the file that is\r | |
124 | being dispatched. This will optionally be used for logging.\r | |
125 | \r | |
126 | @retval EFI_SUCCESS The file specified by File authenticated when more\r | |
127 | than one security handler services were registered,\r | |
128 | or the file did not authenticate when no security\r | |
129 | handler service was registered. And the platform policy\r | |
130 | dictates that the DXE Core may use File.\r | |
131 | @retval EFI_INVALID_PARAMETER File is NULL.\r | |
132 | @retval EFI_SECURITY_VIOLATION The file specified by File did not authenticate, and\r | |
133 | the platform policy dictates that File should be placed\r | |
134 | in the untrusted state. A file may be promoted from\r | |
135 | the untrusted to the trusted state at a future time\r | |
136 | with a call to the Trust() DXE Service.\r | |
137 | @retval EFI_ACCESS_DENIED The file specified by File did not authenticate, and\r | |
138 | the platform policy dictates that File should not be\r | |
139 | used for any purpose.\r | |
140 | **/\r | |
141 | EFI_STATUS\r | |
142 | EFIAPI\r | |
143 | ExecuteSecurityHandlers (\r | |
144 | IN UINT32 AuthenticationStatus,\r | |
145 | IN CONST EFI_DEVICE_PATH_PROTOCOL *FilePath\r | |
146 | );\r | |
147 | \r | |
148 | /**\r | |
149 | The security handler is used to abstracts security-specific functions from the DXE\r | |
150 | Foundation of UEFI Image Verification, Trusted Computing Group (TCG) measured boot,\r | |
151 | User Identity policy for image loading and consoles, and for purposes of\r | |
152 | handling GUIDed section encapsulations.\r | |
153 | \r | |
154 | @param[in] AuthenticationStatus\r | |
155 | The authentication status for the input file.\r | |
156 | @param[in] File The pointer to the device path of the file that is\r | |
157 | being dispatched. This will optionally be used for logging.\r | |
158 | @param[in] FileBuffer A pointer to the buffer with the UEFI file image\r | |
159 | @param[in] FileSize The size of File buffer.\r | |
160 | @param[in] BootPolicy A boot policy that was used to call LoadImage() UEFI service.\r | |
161 | \r | |
162 | @retval EFI_SUCCESS The file specified by DevicePath and non-NULL\r | |
163 | FileBuffer did authenticate, and the platform policy dictates\r | |
164 | that the DXE Foundation may use the file.\r | |
165 | @retval EFI_SUCCESS The device path specified by NULL device path DevicePath\r | |
166 | and non-NULL FileBuffer did authenticate, and the platform\r | |
167 | policy dictates that the DXE Foundation may execute the image in\r | |
168 | FileBuffer.\r | |
169 | @retval EFI_SUCCESS FileBuffer is NULL and current user has permission to start\r | |
170 | UEFI device drivers on the device path specified by DevicePath.\r | |
171 | @retval EFI_SECURITY_VIOLATION The file specified by DevicePath and FileBuffer did not\r | |
172 | authenticate, and the platform policy dictates that the file should be\r | |
173 | placed in the untrusted state. The image has been added to the file\r | |
174 | execution table.\r | |
175 | @retval EFI_ACCESS_DENIED The file specified by File and FileBuffer did not\r | |
176 | authenticate, and the platform policy dictates that the DXE\r | |
177 | Foundation may not use File.\r | |
178 | @retval EFI_SECURITY_VIOLATION FileBuffer is NULL and the user has no\r | |
179 | permission to start UEFI device drivers on the device path specified\r | |
180 | by DevicePath.\r | |
181 | @retval EFI_SECURITY_VIOLATION FileBuffer is not NULL and the user has no permission to load\r | |
182 | drivers from the device path specified by DevicePath. The\r | |
183 | image has been added into the list of the deferred images.\r | |
184 | **/\r | |
185 | typedef\r | |
186 | EFI_STATUS\r | |
187 | (EFIAPI *SECURITY2_FILE_AUTHENTICATION_HANDLER) (\r | |
188 | IN UINT32 AuthenticationStatus,\r | |
189 | IN CONST EFI_DEVICE_PATH_PROTOCOL *File,\r | |
190 | IN VOID *FileBuffer,\r | |
191 | IN UINTN FileSize,\r | |
192 | IN BOOLEAN BootPolicy\r | |
193 | );\r | |
194 | \r | |
195 | /**\r | |
196 | Register security measurement handler with its operation type. Different\r | |
197 | handlers with the same operation can all be registered.\r | |
198 | \r | |
199 | If SecurityHandler is NULL, then ASSERT().\r | |
200 | If no enough resources available to register new handler, then ASSERT().\r | |
201 | If AuthenticationOperation is not recongnized, then ASSERT().\r | |
202 | If AuthenticationOperation is EFI_AUTH_OPERATION_NONE, then ASSERT().\r | |
203 | If the previous register handler can't be executed before the later register handler, then ASSERT().\r | |
204 | \r | |
205 | @param[in] Security2Handler The security measurement service handler to be registered.\r | |
206 | @param[in] AuthenticationOperation The operation type is specified for the registered handler.\r | |
207 | \r | |
208 | @retval EFI_SUCCESS The handlers were registered successfully.\r | |
209 | **/\r | |
210 | EFI_STATUS\r | |
211 | EFIAPI\r | |
212 | RegisterSecurity2Handler (\r | |
213 | IN SECURITY2_FILE_AUTHENTICATION_HANDLER Security2Handler,\r | |
214 | IN UINT32 AuthenticationOperation\r | |
215 | );\r | |
216 | \r | |
217 | /**\r | |
218 | Execute registered handlers based on input AuthenticationOperation until\r | |
219 | one returns an error and that error is returned.\r | |
220 | \r | |
221 | If none of the handlers return an error, then EFI_SUCCESS is returned.\r | |
222 | The handlers those satisfy AuthenticationOperation will only be executed.\r | |
223 | The handlers are executed in same order to their registered order.\r | |
224 | \r | |
225 | @param[in] AuthenticationOperation\r | |
226 | The operation type specifies which handlers will be executed.\r | |
227 | @param[in] AuthenticationStatus\r | |
228 | The authentication status for the input file.\r | |
229 | @param[in] File This is a pointer to the device path of the file that is\r | |
230 | being dispatched. This will optionally be used for logging.\r | |
231 | @param[in] FileBuffer A pointer to the buffer with the UEFI file image\r | |
232 | @param[in] FileSize The size of File buffer.\r | |
233 | @param[in] BootPolicy A boot policy that was used to call LoadImage() UEFI service.\r | |
234 | \r | |
235 | @retval EFI_SUCCESS The file specified by DevicePath and non-NULL\r | |
236 | FileBuffer did authenticate, and the platform policy dictates\r | |
237 | that the DXE Foundation may use the file.\r | |
238 | @retval EFI_SUCCESS The device path specified by NULL device path DevicePath\r | |
239 | and non-NULL FileBuffer did authenticate, and the platform\r | |
240 | policy dictates that the DXE Foundation may execute the image in\r | |
241 | FileBuffer.\r | |
242 | @retval EFI_SUCCESS FileBuffer is NULL and current user has permission to start\r | |
243 | UEFI device drivers on the device path specified by DevicePath.\r | |
244 | @retval EFI_SECURITY_VIOLATION The file specified by DevicePath and FileBuffer did not\r | |
245 | authenticate, and the platform policy dictates that the file should be\r | |
246 | placed in the untrusted state. The image has been added to the file\r | |
247 | execution table.\r | |
248 | @retval EFI_ACCESS_DENIED The file specified by File and FileBuffer did not\r | |
249 | authenticate, and the platform policy dictates that the DXE\r | |
250 | Foundation may not use File.\r | |
251 | @retval EFI_SECURITY_VIOLATION FileBuffer is NULL and the user has no\r | |
252 | permission to start UEFI device drivers on the device path specified\r | |
253 | by DevicePath.\r | |
254 | @retval EFI_SECURITY_VIOLATION FileBuffer is not NULL and the user has no permission to load\r | |
255 | drivers from the device path specified by DevicePath. The\r | |
256 | image has been added into the list of the deferred images.\r | |
257 | @retval EFI_INVALID_PARAMETER File and FileBuffer are both NULL.\r | |
258 | **/\r | |
259 | EFI_STATUS\r | |
260 | EFIAPI\r | |
261 | ExecuteSecurity2Handlers (\r | |
262 | IN UINT32 AuthenticationOperation,\r | |
263 | IN UINT32 AuthenticationStatus,\r | |
264 | IN CONST EFI_DEVICE_PATH_PROTOCOL *File,\r | |
265 | IN VOID *FileBuffer,\r | |
266 | IN UINTN FileSize,\r | |
267 | IN BOOLEAN BootPolicy\r | |
268 | );\r | |
269 | \r | |
270 | #endif\r |