]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Library/AuthVariableLib/AuthServiceInternal.h
SecurityPkg: Fix spelling errors
[mirror_edk2.git] / SecurityPkg / Library / AuthVariableLib / AuthServiceInternal.h
CommitLineData
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 15Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
289b714b 16SPDX-License-Identifier: BSD-2-Clause-Patent\r
a6811666
SZ
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
c035e373
ZL
34#define TWO_BYTE_ENCODE 0x82\r
35\r
a6811666
SZ
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
40typedef 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
48typedef enum {\r
49 AuthVarTypePk,\r
50 AuthVarTypeKek,\r
51 AuthVarTypePriv,\r
52 AuthVarTypePayload\r
53} AUTHVAR_TYPE;\r
54\r
a6811666 55///\r
98c2d961
CZ
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
a6811666
SZ
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
98c2d961
CZ
76#define EFI_CERT_DB_NAME L"certdb"\r
77#define EFI_CERT_DB_VOLATILE_NAME L"certdbv"\r
a6811666
SZ
78\r
79#pragma pack(1)\r
80typedef 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
a6811666
SZ
90extern UINT8 *mCertDbStore;\r
91extern UINT32 mMaxCertDbSize;\r
92extern UINT32 mPlatformMode;\r
93extern UINT8 mVendorKeyState;\r
94\r
95extern VOID *mHashCtx;\r
96\r
97extern AUTH_VAR_LIB_CONTEXT_IN *mAuthVarLibContextIn;\r
98\r
4fc08e8d 99\r
a6811666
SZ
100/**\r
101 Process variable with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set\r
102\r
103 Caution: This function may receive untrusted input.\r
104 This function may be invoked in SMM mode, and datasize and data are external input.\r
105 This function will do basic validation, before parse the data.\r
106 This function will parse the authentication carefully to avoid security issues, like\r
107 buffer overflow, integer overflow.\r
108\r
109 @param[in] VariableName Name of Variable to be found.\r
110 @param[in] VendorGuid Variable vendor GUID.\r
111 @param[in] Data Data pointer.\r
112 @param[in] DataSize Size of Data found. If size is less than the\r
113 data, this value contains the required size.\r
114 @param[in] Attributes Attribute value of the variable.\r
115 @param[in] AuthVarType Verify against PK, KEK database, private database or certificate in data payload.\r
116 @param[out] VarDel Delete the variable or not.\r
117\r
118 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
119 @retval EFI_SECURITY_VIOLATION The variable does NOT pass the validation\r
120 check carried out by the firmware.\r
121 @retval EFI_OUT_OF_RESOURCES Failed to process variable due to lack\r
122 of resources.\r
123 @retval EFI_SUCCESS Variable pass validation successfully.\r
124\r
125**/\r
126EFI_STATUS\r
127VerifyTimeBasedPayloadAndUpdate (\r
128 IN CHAR16 *VariableName,\r
129 IN EFI_GUID *VendorGuid,\r
130 IN VOID *Data,\r
131 IN UINTN DataSize,\r
132 IN UINT32 Attributes,\r
133 IN AUTHVAR_TYPE AuthVarType,\r
134 OUT BOOLEAN *VarDel\r
135 );\r
136\r
137/**\r
138 Delete matching signer's certificates when deleting common authenticated\r
b3548d32 139 variable by corresponding VariableName and VendorGuid from "certdb" or\r
98c2d961 140 "certdbv" according to authenticated variable attributes.\r
a6811666
SZ
141\r
142 @param[in] VariableName Name of authenticated Variable.\r
143 @param[in] VendorGuid Vendor GUID of authenticated Variable.\r
98c2d961 144 @param[in] Attributes Attributes of authenticated variable.\r
a6811666
SZ
145\r
146 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.\r
98c2d961 147 @retval EFI_NOT_FOUND Fail to find "certdb"/"certdbv" or matching certs.\r
a6811666
SZ
148 @retval EFI_OUT_OF_RESOURCES The operation is failed due to lack of resources.\r
149 @retval EFI_SUCCESS The operation is completed successfully.\r
150\r
151**/\r
152EFI_STATUS\r
153DeleteCertsFromDb (\r
154 IN CHAR16 *VariableName,\r
98c2d961
CZ
155 IN EFI_GUID *VendorGuid,\r
156 IN UINT32 Attributes\r
a6811666
SZ
157 );\r
158\r
64b6a3ff
CZ
159/**\r
160 Clean up signer's certificates for common authenticated variable\r
161 by corresponding VariableName and VendorGuid from "certdb".\r
d6b926e7 162 System may break down during Timebased Variable update & certdb update,\r
b3548d32 163 make them inconsistent, this function is called in AuthVariable Init to ensure\r
64b6a3ff 164 consistency\r
b3548d32 165\r
64b6a3ff
CZ
166 @retval EFI_NOT_FOUND Fail to find matching certs.\r
167 @retval EFI_SUCCESS Find matching certs and output parameters.\r
168\r
169**/\r
170EFI_STATUS\r
171CleanCertsFromDb (\r
172 VOID\r
173 );\r
174\r
a6811666
SZ
175/**\r
176 Filter out the duplicated EFI_SIGNATURE_DATA from the new data by comparing to the original data.\r
177\r
178 @param[in] Data Pointer to original EFI_SIGNATURE_LIST.\r
179 @param[in] DataSize Size of Data buffer.\r
180 @param[in, out] NewData Pointer to new EFI_SIGNATURE_LIST.\r
181 @param[in, out] NewDataSize Size of NewData buffer.\r
182\r
183**/\r
184EFI_STATUS\r
185FilterSignatureList (\r
186 IN VOID *Data,\r
187 IN UINTN DataSize,\r
188 IN OUT VOID *NewData,\r
189 IN OUT UINTN *NewDataSize\r
190 );\r
191\r
192/**\r
193 Process variable with platform key for verification.\r
194\r
195 Caution: This function may receive untrusted input.\r
196 This function may be invoked in SMM mode, and datasize and data are external input.\r
197 This function will do basic validation, before parse the data.\r
198 This function will parse the authentication carefully to avoid security issues, like\r
199 buffer overflow, integer overflow.\r
200 This function will check attribute carefully to avoid authentication bypass.\r
201\r
202 @param[in] VariableName Name of Variable to be found.\r
203 @param[in] VendorGuid Variable vendor GUID.\r
204 @param[in] Data Data pointer.\r
205 @param[in] DataSize Size of Data found. If size is less than the\r
206 data, this value contains the required size.\r
207 @param[in] Attributes Attribute value of the variable\r
208 @param[in] IsPk Indicate whether it is to process pk.\r
209\r
210 @return EFI_INVALID_PARAMETER Invalid parameter.\r
211 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation.\r
212 check carried out by the firmware.\r
213 @return EFI_SUCCESS Variable passed validation successfully.\r
214\r
215**/\r
216EFI_STATUS\r
217ProcessVarWithPk (\r
218 IN CHAR16 *VariableName,\r
219 IN EFI_GUID *VendorGuid,\r
220 IN VOID *Data,\r
221 IN UINTN DataSize,\r
222 IN UINT32 Attributes OPTIONAL,\r
223 IN BOOLEAN IsPk\r
224 );\r
225\r
226/**\r
227 Process variable with key exchange key for verification.\r
228\r
229 Caution: This function may receive untrusted input.\r
230 This function may be invoked in SMM mode, and datasize and data are external input.\r
231 This function will do basic validation, before parse the data.\r
232 This function will parse the authentication carefully to avoid security issues, like\r
233 buffer overflow, integer overflow.\r
234 This function will check attribute carefully to avoid authentication bypass.\r
235\r
236 @param[in] VariableName Name of Variable to be found.\r
237 @param[in] VendorGuid Variable vendor GUID.\r
238 @param[in] Data Data pointer.\r
239 @param[in] DataSize Size of Data found. If size is less than the\r
240 data, this value contains the required size.\r
241 @param[in] Attributes Attribute value of the variable.\r
242\r
243 @return EFI_INVALID_PARAMETER Invalid parameter.\r
244 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation\r
245 check carried out by the firmware.\r
246 @return EFI_SUCCESS Variable pass validation successfully.\r
247\r
248**/\r
249EFI_STATUS\r
250ProcessVarWithKek (\r
251 IN CHAR16 *VariableName,\r
252 IN EFI_GUID *VendorGuid,\r
253 IN VOID *Data,\r
254 IN UINTN DataSize,\r
255 IN UINT32 Attributes OPTIONAL\r
256 );\r
257\r
258/**\r
0130fdde 259 Process variable with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set\r
a6811666
SZ
260\r
261 Caution: This function may receive untrusted input.\r
262 This function may be invoked in SMM mode, and datasize and data are external input.\r
263 This function will do basic validation, before parse the data.\r
264 This function will parse the authentication carefully to avoid security issues, like\r
265 buffer overflow, integer overflow.\r
266 This function will check attribute carefully to avoid authentication bypass.\r
267\r
268 @param[in] VariableName Name of the variable.\r
269 @param[in] VendorGuid Variable vendor GUID.\r
270 @param[in] Data Data pointer.\r
271 @param[in] DataSize Size of Data.\r
272 @param[in] Attributes Attribute value of the variable.\r
273\r
274 @return EFI_INVALID_PARAMETER Invalid parameter.\r
275 @return EFI_WRITE_PROTECTED Variable is write-protected and needs authentication with\r
0130fdde 276 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set.\r
a6811666 277 @return EFI_OUT_OF_RESOURCES The Database to save the public key is full.\r
0130fdde 278 @return EFI_SECURITY_VIOLATION The variable is with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS\r
a6811666
SZ
279 set, but the AuthInfo does NOT pass the validation\r
280 check carried out by the firmware.\r
281 @return EFI_SUCCESS Variable is not write-protected or pass validation successfully.\r
282\r
283**/\r
284EFI_STATUS\r
285ProcessVariable (\r
286 IN CHAR16 *VariableName,\r
287 IN EFI_GUID *VendorGuid,\r
288 IN VOID *Data,\r
289 IN UINTN DataSize,\r
98c2d961 290 IN UINT32 Attributes\r
a6811666
SZ
291 );\r
292\r
293/**\r
294 Finds variable in storage blocks of volatile and non-volatile storage areas.\r
295\r
296 This code finds variable in storage blocks of volatile and non-volatile storage areas.\r
297 If VariableName is an empty string, then we just return the first\r
298 qualified variable without comparing VariableName and VendorGuid.\r
299\r
300 @param[in] VariableName Name of the variable to be found.\r
301 @param[in] VendorGuid Variable vendor GUID to be found.\r
302 @param[out] Data Pointer to data address.\r
303 @param[out] DataSize Pointer to data size.\r
304\r
305 @retval EFI_INVALID_PARAMETER If VariableName is not an empty string,\r
306 while VendorGuid is NULL.\r
307 @retval EFI_SUCCESS Variable successfully found.\r
308 @retval EFI_NOT_FOUND Variable not found\r
309\r
310**/\r
311EFI_STATUS\r
312AuthServiceInternalFindVariable (\r
313 IN CHAR16 *VariableName,\r
314 IN EFI_GUID *VendorGuid,\r
315 OUT VOID **Data,\r
316 OUT UINTN *DataSize\r
317 );\r
318\r
319/**\r
320 Update the variable region with Variable information.\r
321\r
322 @param[in] VariableName Name of variable.\r
323 @param[in] VendorGuid Guid of variable.\r
324 @param[in] Data Data pointer.\r
325 @param[in] DataSize Size of Data.\r
326 @param[in] Attributes Attribute value of the variable.\r
327\r
328 @retval EFI_SUCCESS The update operation is success.\r
329 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
330 @retval EFI_WRITE_PROTECTED Variable is write-protected.\r
331 @retval EFI_OUT_OF_RESOURCES There is not enough resource.\r
332\r
333**/\r
334EFI_STATUS\r
335AuthServiceInternalUpdateVariable (\r
336 IN CHAR16 *VariableName,\r
337 IN EFI_GUID *VendorGuid,\r
338 IN VOID *Data,\r
339 IN UINTN DataSize,\r
340 IN UINT32 Attributes\r
341 );\r
342\r
a6811666
SZ
343/**\r
344 Update the variable region with Variable information.\r
345\r
346 @param[in] VariableName Name of variable.\r
347 @param[in] VendorGuid Guid of variable.\r
348 @param[in] Data Data pointer.\r
349 @param[in] DataSize Size of Data.\r
350 @param[in] Attributes Attribute value of the variable.\r
351 @param[in] TimeStamp Value of associated TimeStamp.\r
352\r
353 @retval EFI_SUCCESS The update operation is success.\r
354 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
355 @retval EFI_WRITE_PROTECTED Variable is write-protected.\r
356 @retval EFI_OUT_OF_RESOURCES There is not enough resource.\r
357\r
358**/\r
359EFI_STATUS\r
360AuthServiceInternalUpdateVariableWithTimeStamp (\r
361 IN CHAR16 *VariableName,\r
362 IN EFI_GUID *VendorGuid,\r
363 IN VOID *Data,\r
364 IN UINTN DataSize,\r
365 IN UINT32 Attributes,\r
366 IN EFI_TIME *TimeStamp\r
367 );\r
368\r
369#endif\r