]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Library/AuthVariableLib/AuthServiceInternal.h
SecurityPkg: Add default value for TPM action question
[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
15Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
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
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 set.\r
91///\r
92/// GUID: gEfiCertDbGuid\r
93///\r
94/// We need maintain atomicity.\r
95///\r
96/// Format:\r
97/// +----------------------------+\r
98/// | UINT32 | <-- CertDbListSize, including this UINT32\r
99/// +----------------------------+\r
100/// | AUTH_CERT_DB_DATA | <-- First CERT\r
101/// +----------------------------+\r
102/// | ........ |\r
103/// +----------------------------+\r
104/// | AUTH_CERT_DB_DATA | <-- Last CERT\r
105/// +----------------------------+\r
106///\r
107#define EFI_CERT_DB_NAME L"certdb"\r
108\r
109#pragma pack(1)\r
110typedef struct {\r
111 EFI_GUID VendorGuid;\r
112 UINT32 CertNodeSize;\r
113 UINT32 NameSize;\r
114 UINT32 CertDataSize;\r
115 /// CHAR16 VariableName[NameSize];\r
116 /// UINT8 CertData[CertDataSize];\r
117} AUTH_CERT_DB_DATA;\r
118#pragma pack()\r
119\r
120extern UINT8 *mPubKeyStore;\r
121extern UINT32 mPubKeyNumber;\r
122extern UINT32 mMaxKeyNumber;\r
123extern UINT32 mMaxKeyDbSize;\r
124extern UINT8 *mCertDbStore;\r
125extern UINT32 mMaxCertDbSize;\r
126extern UINT32 mPlatformMode;\r
127extern UINT8 mVendorKeyState;\r
128\r
129extern VOID *mHashCtx;\r
130\r
131extern AUTH_VAR_LIB_CONTEXT_IN *mAuthVarLibContextIn;\r
132\r
133/**\r
134 Process variable with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set\r
135\r
136 Caution: This function may receive untrusted input.\r
137 This function may be invoked in SMM mode, and datasize and data are external input.\r
138 This function will do basic validation, before parse the data.\r
139 This function will parse the authentication carefully to avoid security issues, like\r
140 buffer overflow, integer overflow.\r
141\r
142 @param[in] VariableName Name of Variable to be found.\r
143 @param[in] VendorGuid Variable vendor GUID.\r
144 @param[in] Data Data pointer.\r
145 @param[in] DataSize Size of Data found. If size is less than the\r
146 data, this value contains the required size.\r
147 @param[in] Attributes Attribute value of the variable.\r
148 @param[in] AuthVarType Verify against PK, KEK database, private database or certificate in data payload.\r
149 @param[out] VarDel Delete the variable or not.\r
150\r
151 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
152 @retval EFI_SECURITY_VIOLATION The variable does NOT pass the validation\r
153 check carried out by the firmware.\r
154 @retval EFI_OUT_OF_RESOURCES Failed to process variable due to lack\r
155 of resources.\r
156 @retval EFI_SUCCESS Variable pass validation successfully.\r
157\r
158**/\r
159EFI_STATUS\r
160VerifyTimeBasedPayloadAndUpdate (\r
161 IN CHAR16 *VariableName,\r
162 IN EFI_GUID *VendorGuid,\r
163 IN VOID *Data,\r
164 IN UINTN DataSize,\r
165 IN UINT32 Attributes,\r
166 IN AUTHVAR_TYPE AuthVarType,\r
167 OUT BOOLEAN *VarDel\r
168 );\r
169\r
170/**\r
171 Delete matching signer's certificates when deleting common authenticated\r
172 variable by corresponding VariableName and VendorGuid from "certdb".\r
173\r
174 @param[in] VariableName Name of authenticated Variable.\r
175 @param[in] VendorGuid Vendor GUID of authenticated Variable.\r
176\r
177 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.\r
178 @retval EFI_NOT_FOUND Fail to find "certdb" or matching certs.\r
179 @retval EFI_OUT_OF_RESOURCES The operation is failed due to lack of resources.\r
180 @retval EFI_SUCCESS The operation is completed successfully.\r
181\r
182**/\r
183EFI_STATUS\r
184DeleteCertsFromDb (\r
185 IN CHAR16 *VariableName,\r
186 IN EFI_GUID *VendorGuid\r
187 );\r
188\r
189/**\r
190 Filter out the duplicated EFI_SIGNATURE_DATA from the new data by comparing to the original data.\r
191\r
192 @param[in] Data Pointer to original EFI_SIGNATURE_LIST.\r
193 @param[in] DataSize Size of Data buffer.\r
194 @param[in, out] NewData Pointer to new EFI_SIGNATURE_LIST.\r
195 @param[in, out] NewDataSize Size of NewData buffer.\r
196\r
197**/\r
198EFI_STATUS\r
199FilterSignatureList (\r
200 IN VOID *Data,\r
201 IN UINTN DataSize,\r
202 IN OUT VOID *NewData,\r
203 IN OUT UINTN *NewDataSize\r
204 );\r
205\r
206/**\r
207 Process variable with platform key for verification.\r
208\r
209 Caution: This function may receive untrusted input.\r
210 This function may be invoked in SMM mode, and datasize and data are external input.\r
211 This function will do basic validation, before parse the data.\r
212 This function will parse the authentication carefully to avoid security issues, like\r
213 buffer overflow, integer overflow.\r
214 This function will check attribute carefully to avoid authentication bypass.\r
215\r
216 @param[in] VariableName Name of Variable to be found.\r
217 @param[in] VendorGuid Variable vendor GUID.\r
218 @param[in] Data Data pointer.\r
219 @param[in] DataSize Size of Data found. If size is less than the\r
220 data, this value contains the required size.\r
221 @param[in] Attributes Attribute value of the variable\r
222 @param[in] IsPk Indicate whether it is to process pk.\r
223\r
224 @return EFI_INVALID_PARAMETER Invalid parameter.\r
225 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation.\r
226 check carried out by the firmware.\r
227 @return EFI_SUCCESS Variable passed validation successfully.\r
228\r
229**/\r
230EFI_STATUS\r
231ProcessVarWithPk (\r
232 IN CHAR16 *VariableName,\r
233 IN EFI_GUID *VendorGuid,\r
234 IN VOID *Data,\r
235 IN UINTN DataSize,\r
236 IN UINT32 Attributes OPTIONAL,\r
237 IN BOOLEAN IsPk\r
238 );\r
239\r
240/**\r
241 Process variable with key exchange key for verification.\r
242\r
243 Caution: This function may receive untrusted input.\r
244 This function may be invoked in SMM mode, and datasize and data are external input.\r
245 This function will do basic validation, before parse the data.\r
246 This function will parse the authentication carefully to avoid security issues, like\r
247 buffer overflow, integer overflow.\r
248 This function will check attribute carefully to avoid authentication bypass.\r
249\r
250 @param[in] VariableName Name of Variable to be found.\r
251 @param[in] VendorGuid Variable vendor GUID.\r
252 @param[in] Data Data pointer.\r
253 @param[in] DataSize Size of Data found. If size is less than the\r
254 data, this value contains the required size.\r
255 @param[in] Attributes Attribute value of the variable.\r
256\r
257 @return EFI_INVALID_PARAMETER Invalid parameter.\r
258 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation\r
259 check carried out by the firmware.\r
260 @return EFI_SUCCESS Variable pass validation successfully.\r
261\r
262**/\r
263EFI_STATUS\r
264ProcessVarWithKek (\r
265 IN CHAR16 *VariableName,\r
266 IN EFI_GUID *VendorGuid,\r
267 IN VOID *Data,\r
268 IN UINTN DataSize,\r
269 IN UINT32 Attributes OPTIONAL\r
270 );\r
271\r
272/**\r
273 Process variable with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS/EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set\r
274\r
275 Caution: This function may receive untrusted input.\r
276 This function may be invoked in SMM mode, and datasize and data are external input.\r
277 This function will do basic validation, before parse the data.\r
278 This function will parse the authentication carefully to avoid security issues, like\r
279 buffer overflow, integer overflow.\r
280 This function will check attribute carefully to avoid authentication bypass.\r
281\r
282 @param[in] VariableName Name of the variable.\r
283 @param[in] VendorGuid Variable vendor GUID.\r
284 @param[in] Data Data pointer.\r
285 @param[in] DataSize Size of Data.\r
286 @param[in] Attributes Attribute value of the variable.\r
287\r
288 @return EFI_INVALID_PARAMETER Invalid parameter.\r
289 @return EFI_WRITE_PROTECTED Variable is write-protected and needs authentication with\r
290 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS set.\r
291 @return EFI_OUT_OF_RESOURCES The Database to save the public key is full.\r
292 @return EFI_SECURITY_VIOLATION The variable is with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS\r
293 set, but the AuthInfo does NOT pass the validation\r
294 check carried out by the firmware.\r
295 @return EFI_SUCCESS Variable is not write-protected or pass validation successfully.\r
296\r
297**/\r
298EFI_STATUS\r
299ProcessVariable (\r
300 IN CHAR16 *VariableName,\r
301 IN EFI_GUID *VendorGuid,\r
302 IN VOID *Data,\r
303 IN UINTN DataSize,\r
304 IN UINT32 Attributes OPTIONAL\r
305 );\r
306\r
307/**\r
308 Finds variable in storage blocks of volatile and non-volatile storage areas.\r
309\r
310 This code finds variable in storage blocks of volatile and non-volatile storage areas.\r
311 If VariableName is an empty string, then we just return the first\r
312 qualified variable without comparing VariableName and VendorGuid.\r
313\r
314 @param[in] VariableName Name of the variable to be found.\r
315 @param[in] VendorGuid Variable vendor GUID to be found.\r
316 @param[out] Data Pointer to data address.\r
317 @param[out] DataSize Pointer to data size.\r
318\r
319 @retval EFI_INVALID_PARAMETER If VariableName is not an empty string,\r
320 while VendorGuid is NULL.\r
321 @retval EFI_SUCCESS Variable successfully found.\r
322 @retval EFI_NOT_FOUND Variable not found\r
323\r
324**/\r
325EFI_STATUS\r
326AuthServiceInternalFindVariable (\r
327 IN CHAR16 *VariableName,\r
328 IN EFI_GUID *VendorGuid,\r
329 OUT VOID **Data,\r
330 OUT UINTN *DataSize\r
331 );\r
332\r
333/**\r
334 Update the variable region with Variable information.\r
335\r
336 @param[in] VariableName Name of variable.\r
337 @param[in] VendorGuid Guid of variable.\r
338 @param[in] Data Data pointer.\r
339 @param[in] DataSize Size of Data.\r
340 @param[in] Attributes Attribute value of the variable.\r
341\r
342 @retval EFI_SUCCESS The update operation is success.\r
343 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
344 @retval EFI_WRITE_PROTECTED Variable is write-protected.\r
345 @retval EFI_OUT_OF_RESOURCES There is not enough resource.\r
346\r
347**/\r
348EFI_STATUS\r
349AuthServiceInternalUpdateVariable (\r
350 IN CHAR16 *VariableName,\r
351 IN EFI_GUID *VendorGuid,\r
352 IN VOID *Data,\r
353 IN UINTN DataSize,\r
354 IN UINT32 Attributes\r
355 );\r
356\r
357/**\r
358 Update the variable region with Variable information.\r
359\r
360 @param[in] VariableName Name of variable.\r
361 @param[in] VendorGuid Guid of variable.\r
362 @param[in] Data Data pointer.\r
363 @param[in] DataSize Size of Data.\r
364 @param[in] Attributes Attribute value of the variable.\r
365 @param[in] KeyIndex Index of associated public key.\r
366 @param[in] MonotonicCount Value of associated monotonic count.\r
367\r
368 @retval EFI_SUCCESS The update operation is success.\r
369 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
370 @retval EFI_WRITE_PROTECTED Variable is write-protected.\r
371 @retval EFI_OUT_OF_RESOURCES There is not enough resource.\r
372\r
373**/\r
374EFI_STATUS\r
375AuthServiceInternalUpdateVariableWithMonotonicCount (\r
376 IN CHAR16 *VariableName,\r
377 IN EFI_GUID *VendorGuid,\r
378 IN VOID *Data,\r
379 IN UINTN DataSize,\r
380 IN UINT32 Attributes,\r
381 IN UINT32 KeyIndex,\r
382 IN UINT64 MonotonicCount\r
383 );\r
384\r
385/**\r
386 Update the variable region with Variable information.\r
387\r
388 @param[in] VariableName Name of variable.\r
389 @param[in] VendorGuid Guid of variable.\r
390 @param[in] Data Data pointer.\r
391 @param[in] DataSize Size of Data.\r
392 @param[in] Attributes Attribute value of the variable.\r
393 @param[in] TimeStamp Value of associated TimeStamp.\r
394\r
395 @retval EFI_SUCCESS The update operation is success.\r
396 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
397 @retval EFI_WRITE_PROTECTED Variable is write-protected.\r
398 @retval EFI_OUT_OF_RESOURCES There is not enough resource.\r
399\r
400**/\r
401EFI_STATUS\r
402AuthServiceInternalUpdateVariableWithTimeStamp (\r
403 IN CHAR16 *VariableName,\r
404 IN EFI_GUID *VendorGuid,\r
405 IN VOID *Data,\r
406 IN UINTN DataSize,\r
407 IN UINT32 Attributes,\r
408 IN EFI_TIME *TimeStamp\r
409 );\r
410\r
411#endif\r