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