]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | The internal header file includes the common header files, defines\r | |
3 | internal structure and functions used by AuthService module.\r | |
4 | \r | |
5 | Caution: This module requires additional review when modified.\r | |
6 | This driver will have external input - variable data. It may be input in SMM mode.\r | |
7 | This external input must be validated carefully to avoid security issue like\r | |
8 | buffer overflow, integer overflow.\r | |
9 | Variable attribute should also be checked to avoid authentication bypass.\r | |
10 | The whole SMM authentication variable design relies on the integrity of flash part and SMM.\r | |
11 | which is assumed to be protected by platform. All variable code and metadata in flash/SMM Memory\r | |
12 | may not be modified without authorization. If platform fails to protect these resources,\r | |
13 | the authentication service provided in this driver will be broken, and the behavior is undefined.\r | |
14 | \r | |
15 | Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r | |
16 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
17 | \r | |
18 | **/\r | |
19 | \r | |
20 | #ifndef _AUTHSERVICE_INTERNAL_H_\r | |
21 | #define _AUTHSERVICE_INTERNAL_H_\r | |
22 | \r | |
23 | #include <Library/AuthVariableLib.h>\r | |
24 | #include <Library/BaseLib.h>\r | |
25 | #include <Library/BaseMemoryLib.h>\r | |
26 | #include <Library/DebugLib.h>\r | |
27 | #include <Library/MemoryAllocationLib.h>\r | |
28 | #include <Library/BaseCryptLib.h>\r | |
29 | #include <Library/PlatformSecureLib.h>\r | |
30 | \r | |
31 | #include <Guid/AuthenticatedVariableFormat.h>\r | |
32 | #include <Guid/ImageAuthentication.h>\r | |
33 | \r | |
34 | #define TWO_BYTE_ENCODE 0x82\r | |
35 | \r | |
36 | ///\r | |
37 | /// Struct to record signature requirement defined by UEFI spec.\r | |
38 | /// For SigHeaderSize and SigDataSize, ((UINT32) ~0) means NO exact length requirement for this field.\r | |
39 | ///\r | |
40 | typedef struct {\r | |
41 | EFI_GUID SigType;\r | |
42 | // Expected SignatureHeader size in Bytes.\r | |
43 | UINT32 SigHeaderSize;\r | |
44 | // Expected SignatureData size in Bytes.\r | |
45 | UINT32 SigDataSize;\r | |
46 | } EFI_SIGNATURE_ITEM;\r | |
47 | \r | |
48 | typedef enum {\r | |
49 | AuthVarTypePk,\r | |
50 | AuthVarTypeKek,\r | |
51 | AuthVarTypePriv,\r | |
52 | AuthVarTypePayload\r | |
53 | } AUTHVAR_TYPE;\r | |
54 | \r | |
55 | ///\r | |
56 | /// "certdb" variable stores the signer's certificates for non PK/KEK/DB/DBX\r | |
57 | /// variables with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS|EFI_VARIABLE_NON_VOLATILE set.\r | |
58 | /// "certdbv" variable stores the signer's certificates for non PK/KEK/DB/DBX\r | |
59 | /// variables with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set\r | |
60 | ///\r | |
61 | /// GUID: gEfiCertDbGuid\r | |
62 | ///\r | |
63 | /// We need maintain atomicity.\r | |
64 | ///\r | |
65 | /// Format:\r | |
66 | /// +----------------------------+\r | |
67 | /// | UINT32 | <-- CertDbListSize, including this UINT32\r | |
68 | /// +----------------------------+\r | |
69 | /// | AUTH_CERT_DB_DATA | <-- First CERT\r | |
70 | /// +----------------------------+\r | |
71 | /// | ........ |\r | |
72 | /// +----------------------------+\r | |
73 | /// | AUTH_CERT_DB_DATA | <-- Last CERT\r | |
74 | /// +----------------------------+\r | |
75 | ///\r | |
76 | #define EFI_CERT_DB_NAME L"certdb"\r | |
77 | #define EFI_CERT_DB_VOLATILE_NAME L"certdbv"\r | |
78 | \r | |
79 | #pragma pack(1)\r | |
80 | typedef struct {\r | |
81 | EFI_GUID VendorGuid;\r | |
82 | UINT32 CertNodeSize;\r | |
83 | UINT32 NameSize;\r | |
84 | UINT32 CertDataSize;\r | |
85 | /// CHAR16 VariableName[NameSize];\r | |
86 | /// UINT8 CertData[CertDataSize];\r | |
87 | } AUTH_CERT_DB_DATA;\r | |
88 | #pragma pack()\r | |
89 | \r | |
90 | extern UINT8 *mCertDbStore;\r | |
91 | extern UINT32 mMaxCertDbSize;\r | |
92 | extern UINT32 mPlatformMode;\r | |
93 | extern UINT8 mVendorKeyState;\r | |
94 | \r | |
95 | extern VOID *mHashCtx;\r | |
96 | \r | |
97 | extern AUTH_VAR_LIB_CONTEXT_IN *mAuthVarLibContextIn;\r | |
98 | \r | |
99 | /**\r | |
100 | Process variable with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set\r | |
101 | \r | |
102 | Caution: This function may receive untrusted input.\r | |
103 | This function may be invoked in SMM mode, and datasize and data are external input.\r | |
104 | This function will do basic validation, before parse the data.\r | |
105 | This function will parse the authentication carefully to avoid security issues, like\r | |
106 | buffer overflow, integer overflow.\r | |
107 | \r | |
108 | @param[in] VariableName Name of Variable to be found.\r | |
109 | @param[in] VendorGuid Variable vendor GUID.\r | |
110 | @param[in] Data Data pointer.\r | |
111 | @param[in] DataSize Size of Data found. If size is less than the\r | |
112 | data, this value contains the required size.\r | |
113 | @param[in] Attributes Attribute value of the variable.\r | |
114 | @param[in] AuthVarType Verify against PK, KEK database, private database or certificate in data payload.\r | |
115 | @param[out] VarDel Delete the variable or not.\r | |
116 | \r | |
117 | @retval EFI_INVALID_PARAMETER Invalid parameter.\r | |
118 | @retval EFI_SECURITY_VIOLATION The variable does NOT pass the validation\r | |
119 | check carried out by the firmware.\r | |
120 | @retval EFI_OUT_OF_RESOURCES Failed to process variable due to lack\r | |
121 | of resources.\r | |
122 | @retval EFI_SUCCESS Variable pass validation successfully.\r | |
123 | \r | |
124 | **/\r | |
125 | EFI_STATUS\r | |
126 | VerifyTimeBasedPayloadAndUpdate (\r | |
127 | IN CHAR16 *VariableName,\r | |
128 | IN EFI_GUID *VendorGuid,\r | |
129 | IN VOID *Data,\r | |
130 | IN UINTN DataSize,\r | |
131 | IN UINT32 Attributes,\r | |
132 | IN AUTHVAR_TYPE AuthVarType,\r | |
133 | OUT BOOLEAN *VarDel\r | |
134 | );\r | |
135 | \r | |
136 | /**\r | |
137 | Delete matching signer's certificates when deleting common authenticated\r | |
138 | variable by corresponding VariableName and VendorGuid from "certdb" or\r | |
139 | "certdbv" according to authenticated variable attributes.\r | |
140 | \r | |
141 | @param[in] VariableName Name of authenticated Variable.\r | |
142 | @param[in] VendorGuid Vendor GUID of authenticated Variable.\r | |
143 | @param[in] Attributes Attributes of authenticated variable.\r | |
144 | \r | |
145 | @retval EFI_INVALID_PARAMETER Any input parameter is invalid.\r | |
146 | @retval EFI_NOT_FOUND Fail to find "certdb"/"certdbv" or matching certs.\r | |
147 | @retval EFI_OUT_OF_RESOURCES The operation is failed due to lack of resources.\r | |
148 | @retval EFI_SUCCESS The operation is completed successfully.\r | |
149 | \r | |
150 | **/\r | |
151 | EFI_STATUS\r | |
152 | DeleteCertsFromDb (\r | |
153 | IN CHAR16 *VariableName,\r | |
154 | IN EFI_GUID *VendorGuid,\r | |
155 | IN UINT32 Attributes\r | |
156 | );\r | |
157 | \r | |
158 | /**\r | |
159 | Clean up signer's certificates for common authenticated variable\r | |
160 | by corresponding VariableName and VendorGuid from "certdb".\r | |
161 | System may break down during Timebased Variable update & certdb update,\r | |
162 | make them inconsistent, this function is called in AuthVariable Init to ensure\r | |
163 | consistency\r | |
164 | \r | |
165 | @retval EFI_NOT_FOUND Fail to find matching certs.\r | |
166 | @retval EFI_SUCCESS Find matching certs and output parameters.\r | |
167 | \r | |
168 | **/\r | |
169 | EFI_STATUS\r | |
170 | CleanCertsFromDb (\r | |
171 | VOID\r | |
172 | );\r | |
173 | \r | |
174 | /**\r | |
175 | Filter out the duplicated EFI_SIGNATURE_DATA from the new data by comparing to the original data.\r | |
176 | \r | |
177 | @param[in] Data Pointer to original EFI_SIGNATURE_LIST.\r | |
178 | @param[in] DataSize Size of Data buffer.\r | |
179 | @param[in, out] NewData Pointer to new EFI_SIGNATURE_LIST.\r | |
180 | @param[in, out] NewDataSize Size of NewData buffer.\r | |
181 | \r | |
182 | **/\r | |
183 | EFI_STATUS\r | |
184 | FilterSignatureList (\r | |
185 | IN VOID *Data,\r | |
186 | IN UINTN DataSize,\r | |
187 | IN OUT VOID *NewData,\r | |
188 | IN OUT UINTN *NewDataSize\r | |
189 | );\r | |
190 | \r | |
191 | /**\r | |
192 | Process variable with platform key for verification.\r | |
193 | \r | |
194 | Caution: This function may receive untrusted input.\r | |
195 | This function may be invoked in SMM mode, and datasize and data are external input.\r | |
196 | This function will do basic validation, before parse the data.\r | |
197 | This function will parse the authentication carefully to avoid security issues, like\r | |
198 | buffer overflow, integer overflow.\r | |
199 | This function will check attribute carefully to avoid authentication bypass.\r | |
200 | \r | |
201 | @param[in] VariableName Name of Variable to be found.\r | |
202 | @param[in] VendorGuid Variable vendor GUID.\r | |
203 | @param[in] Data Data pointer.\r | |
204 | @param[in] DataSize Size of Data found. If size is less than the\r | |
205 | data, this value contains the required size.\r | |
206 | @param[in] Attributes Attribute value of the variable\r | |
207 | @param[in] IsPk Indicate whether it is to process pk.\r | |
208 | \r | |
209 | @return EFI_INVALID_PARAMETER Invalid parameter.\r | |
210 | @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation.\r | |
211 | check carried out by the firmware.\r | |
212 | @return EFI_SUCCESS Variable passed validation successfully.\r | |
213 | \r | |
214 | **/\r | |
215 | EFI_STATUS\r | |
216 | ProcessVarWithPk (\r | |
217 | IN CHAR16 *VariableName,\r | |
218 | IN EFI_GUID *VendorGuid,\r | |
219 | IN VOID *Data,\r | |
220 | IN UINTN DataSize,\r | |
221 | IN UINT32 Attributes OPTIONAL,\r | |
222 | IN BOOLEAN IsPk\r | |
223 | );\r | |
224 | \r | |
225 | /**\r | |
226 | Process variable with key exchange key for verification.\r | |
227 | \r | |
228 | Caution: This function may receive untrusted input.\r | |
229 | This function may be invoked in SMM mode, and datasize and data are external input.\r | |
230 | This function will do basic validation, before parse the data.\r | |
231 | This function will parse the authentication carefully to avoid security issues, like\r | |
232 | buffer overflow, integer overflow.\r | |
233 | This function will check attribute carefully to avoid authentication bypass.\r | |
234 | \r | |
235 | @param[in] VariableName Name of Variable to be found.\r | |
236 | @param[in] VendorGuid Variable vendor GUID.\r | |
237 | @param[in] Data Data pointer.\r | |
238 | @param[in] DataSize Size of Data found. If size is less than the\r | |
239 | data, this value contains the required size.\r | |
240 | @param[in] Attributes Attribute value of the variable.\r | |
241 | \r | |
242 | @return EFI_INVALID_PARAMETER Invalid parameter.\r | |
243 | @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation\r | |
244 | check carried out by the firmware.\r | |
245 | @return EFI_SUCCESS Variable pass validation successfully.\r | |
246 | \r | |
247 | **/\r | |
248 | EFI_STATUS\r | |
249 | ProcessVarWithKek (\r | |
250 | IN CHAR16 *VariableName,\r | |
251 | IN EFI_GUID *VendorGuid,\r | |
252 | IN VOID *Data,\r | |
253 | IN UINTN DataSize,\r | |
254 | IN UINT32 Attributes OPTIONAL\r | |
255 | );\r | |
256 | \r | |
257 | /**\r | |
258 | Process variable with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set\r | |
259 | \r | |
260 | Caution: This function may receive untrusted input.\r | |
261 | This function may be invoked in SMM mode, and datasize and data are external input.\r | |
262 | This function will do basic validation, before parse the data.\r | |
263 | This function will parse the authentication carefully to avoid security issues, like\r | |
264 | buffer overflow, integer overflow.\r | |
265 | This function will check attribute carefully to avoid authentication bypass.\r | |
266 | \r | |
267 | @param[in] VariableName Name of the variable.\r | |
268 | @param[in] VendorGuid Variable vendor GUID.\r | |
269 | @param[in] Data Data pointer.\r | |
270 | @param[in] DataSize Size of Data.\r | |
271 | @param[in] Attributes Attribute value of the variable.\r | |
272 | \r | |
273 | @return EFI_INVALID_PARAMETER Invalid parameter.\r | |
274 | @return EFI_WRITE_PROTECTED Variable is write-protected and needs authentication with\r | |
275 | EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set.\r | |
276 | @return EFI_OUT_OF_RESOURCES The Database to save the public key is full.\r | |
277 | @return EFI_SECURITY_VIOLATION The variable is with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS\r | |
278 | set, but the AuthInfo does NOT pass the validation\r | |
279 | check carried out by the firmware.\r | |
280 | @return EFI_SUCCESS Variable is not write-protected or pass validation successfully.\r | |
281 | \r | |
282 | **/\r | |
283 | EFI_STATUS\r | |
284 | ProcessVariable (\r | |
285 | IN CHAR16 *VariableName,\r | |
286 | IN EFI_GUID *VendorGuid,\r | |
287 | IN VOID *Data,\r | |
288 | IN UINTN DataSize,\r | |
289 | IN UINT32 Attributes\r | |
290 | );\r | |
291 | \r | |
292 | /**\r | |
293 | Finds variable in storage blocks of volatile and non-volatile storage areas.\r | |
294 | \r | |
295 | This code finds variable in storage blocks of volatile and non-volatile storage areas.\r | |
296 | If VariableName is an empty string, then we just return the first\r | |
297 | qualified variable without comparing VariableName and VendorGuid.\r | |
298 | \r | |
299 | @param[in] VariableName Name of the variable to be found.\r | |
300 | @param[in] VendorGuid Variable vendor GUID to be found.\r | |
301 | @param[out] Data Pointer to data address.\r | |
302 | @param[out] DataSize Pointer to data size.\r | |
303 | \r | |
304 | @retval EFI_INVALID_PARAMETER If VariableName is not an empty string,\r | |
305 | while VendorGuid is NULL.\r | |
306 | @retval EFI_SUCCESS Variable successfully found.\r | |
307 | @retval EFI_NOT_FOUND Variable not found\r | |
308 | \r | |
309 | **/\r | |
310 | EFI_STATUS\r | |
311 | AuthServiceInternalFindVariable (\r | |
312 | IN CHAR16 *VariableName,\r | |
313 | IN EFI_GUID *VendorGuid,\r | |
314 | OUT VOID **Data,\r | |
315 | OUT UINTN *DataSize\r | |
316 | );\r | |
317 | \r | |
318 | /**\r | |
319 | Update the variable region with Variable information.\r | |
320 | \r | |
321 | @param[in] VariableName Name of variable.\r | |
322 | @param[in] VendorGuid Guid of variable.\r | |
323 | @param[in] Data Data pointer.\r | |
324 | @param[in] DataSize Size of Data.\r | |
325 | @param[in] Attributes Attribute value of the variable.\r | |
326 | \r | |
327 | @retval EFI_SUCCESS The update operation is success.\r | |
328 | @retval EFI_INVALID_PARAMETER Invalid parameter.\r | |
329 | @retval EFI_WRITE_PROTECTED Variable is write-protected.\r | |
330 | @retval EFI_OUT_OF_RESOURCES There is not enough resource.\r | |
331 | \r | |
332 | **/\r | |
333 | EFI_STATUS\r | |
334 | AuthServiceInternalUpdateVariable (\r | |
335 | IN CHAR16 *VariableName,\r | |
336 | IN EFI_GUID *VendorGuid,\r | |
337 | IN VOID *Data,\r | |
338 | IN UINTN DataSize,\r | |
339 | IN UINT32 Attributes\r | |
340 | );\r | |
341 | \r | |
342 | /**\r | |
343 | Update the variable region with Variable information.\r | |
344 | \r | |
345 | @param[in] VariableName Name of variable.\r | |
346 | @param[in] VendorGuid Guid of variable.\r | |
347 | @param[in] Data Data pointer.\r | |
348 | @param[in] DataSize Size of Data.\r | |
349 | @param[in] Attributes Attribute value of the variable.\r | |
350 | @param[in] TimeStamp Value of associated TimeStamp.\r | |
351 | \r | |
352 | @retval EFI_SUCCESS The update operation is success.\r | |
353 | @retval EFI_INVALID_PARAMETER Invalid parameter.\r | |
354 | @retval EFI_WRITE_PROTECTED Variable is write-protected.\r | |
355 | @retval EFI_OUT_OF_RESOURCES There is not enough resource.\r | |
356 | \r | |
357 | **/\r | |
358 | EFI_STATUS\r | |
359 | AuthServiceInternalUpdateVariableWithTimeStamp (\r | |
360 | IN CHAR16 *VariableName,\r | |
361 | IN EFI_GUID *VendorGuid,\r | |
362 | IN VOID *Data,\r | |
363 | IN UINTN DataSize,\r | |
364 | IN UINT32 Attributes,\r | |
365 | IN EFI_TIME *TimeStamp\r | |
366 | );\r | |
367 | \r | |
368 | #endif\r |