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