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