2 The internal header file includes the common header files, defines
3 internal structure and functions used by AuthService module.
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.
15 Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
16 This program and the accompanying materials
17 are licensed and made available under the terms and conditions of the BSD License
18 which accompanies this distribution. The full text of the license may be found at
19 http://opensource.org/licenses/bsd-license.php
21 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
22 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
26 #ifndef _AUTHSERVICE_INTERNAL_H_
27 #define _AUTHSERVICE_INTERNAL_H_
29 #include <Library/AuthVariableLib.h>
30 #include <Library/BaseLib.h>
31 #include <Library/BaseMemoryLib.h>
32 #include <Library/DebugLib.h>
33 #include <Library/MemoryAllocationLib.h>
34 #include <Library/BaseCryptLib.h>
35 #include <Library/PlatformSecureLib.h>
37 #include <Guid/AuthenticatedVariableFormat.h>
38 #include <Guid/ImageAuthentication.h>
40 #define TWO_BYTE_ENCODE 0x82
43 /// Struct to record signature requirement defined by UEFI spec.
44 /// For SigHeaderSize and SigDataSize, ((UINT32) ~0) means NO exact length requirement for this field.
48 // Expected SignatureHeader size in Bytes.
50 // Expected SignatureData size in Bytes.
62 /// "certdb" variable stores the signer's certificates for non PK/KEK/DB/DBX
63 /// variables with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS|EFI_VARIABLE_NON_VOLATILE set.
64 /// "certdbv" variable stores the signer's certificates for non PK/KEK/DB/DBX
65 /// variables with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set
67 /// GUID: gEfiCertDbGuid
69 /// We need maintain atomicity.
72 /// +----------------------------+
73 /// | UINT32 | <-- CertDbListSize, including this UINT32
74 /// +----------------------------+
75 /// | AUTH_CERT_DB_DATA | <-- First CERT
76 /// +----------------------------+
78 /// +----------------------------+
79 /// | AUTH_CERT_DB_DATA | <-- Last CERT
80 /// +----------------------------+
82 #define EFI_CERT_DB_NAME L"certdb"
83 #define EFI_CERT_DB_VOLATILE_NAME L"certdbv"
91 /// CHAR16 VariableName[NameSize];
92 /// UINT8 CertData[CertDataSize];
96 extern UINT8
*mCertDbStore
;
97 extern UINT32 mMaxCertDbSize
;
98 extern UINT32 mPlatformMode
;
99 extern UINT8 mVendorKeyState
;
101 extern VOID
*mHashCtx
;
103 extern AUTH_VAR_LIB_CONTEXT_IN
*mAuthVarLibContextIn
;
107 Process variable with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set
109 Caution: This function may receive untrusted input.
110 This function may be invoked in SMM mode, and datasize and data are external input.
111 This function will do basic validation, before parse the data.
112 This function will parse the authentication carefully to avoid security issues, like
113 buffer overflow, integer overflow.
115 @param[in] VariableName Name of Variable to be found.
116 @param[in] VendorGuid Variable vendor GUID.
117 @param[in] Data Data pointer.
118 @param[in] DataSize Size of Data found. If size is less than the
119 data, this value contains the required size.
120 @param[in] Attributes Attribute value of the variable.
121 @param[in] AuthVarType Verify against PK, KEK database, private database or certificate in data payload.
122 @param[out] VarDel Delete the variable or not.
124 @retval EFI_INVALID_PARAMETER Invalid parameter.
125 @retval EFI_SECURITY_VIOLATION The variable does NOT pass the validation
126 check carried out by the firmware.
127 @retval EFI_OUT_OF_RESOURCES Failed to process variable due to lack
129 @retval EFI_SUCCESS Variable pass validation successfully.
133 VerifyTimeBasedPayloadAndUpdate (
134 IN CHAR16
*VariableName
,
135 IN EFI_GUID
*VendorGuid
,
138 IN UINT32 Attributes
,
139 IN AUTHVAR_TYPE AuthVarType
,
144 Delete matching signer's certificates when deleting common authenticated
145 variable by corresponding VariableName and VendorGuid from "certdb" or
146 "certdbv" according to authenticated variable attributes.
148 @param[in] VariableName Name of authenticated Variable.
149 @param[in] VendorGuid Vendor GUID of authenticated Variable.
150 @param[in] Attributes Attributes of authenticated variable.
152 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
153 @retval EFI_NOT_FOUND Fail to find "certdb"/"certdbv" or matching certs.
154 @retval EFI_OUT_OF_RESOURCES The operation is failed due to lack of resources.
155 @retval EFI_SUCCESS The operation is completed successfully.
160 IN CHAR16
*VariableName
,
161 IN EFI_GUID
*VendorGuid
,
166 Clean up signer's certificates for common authenticated variable
167 by corresponding VariableName and VendorGuid from "certdb".
168 Sytem may break down during Timebased Variable update & certdb update,
169 make them inconsistent, this function is called in AuthVariable Init to ensure
172 @retval EFI_NOT_FOUND Fail to find matching certs.
173 @retval EFI_SUCCESS Find matching certs and output parameters.
182 Filter out the duplicated EFI_SIGNATURE_DATA from the new data by comparing to the original data.
184 @param[in] Data Pointer to original EFI_SIGNATURE_LIST.
185 @param[in] DataSize Size of Data buffer.
186 @param[in, out] NewData Pointer to new EFI_SIGNATURE_LIST.
187 @param[in, out] NewDataSize Size of NewData buffer.
191 FilterSignatureList (
194 IN OUT VOID
*NewData
,
195 IN OUT UINTN
*NewDataSize
199 Process variable with platform key for verification.
201 Caution: This function may receive untrusted input.
202 This function may be invoked in SMM mode, and datasize and data are external input.
203 This function will do basic validation, before parse the data.
204 This function will parse the authentication carefully to avoid security issues, like
205 buffer overflow, integer overflow.
206 This function will check attribute carefully to avoid authentication bypass.
208 @param[in] VariableName Name of Variable to be found.
209 @param[in] VendorGuid Variable vendor GUID.
210 @param[in] Data Data pointer.
211 @param[in] DataSize Size of Data found. If size is less than the
212 data, this value contains the required size.
213 @param[in] Attributes Attribute value of the variable
214 @param[in] IsPk Indicate whether it is to process pk.
216 @return EFI_INVALID_PARAMETER Invalid parameter.
217 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation.
218 check carried out by the firmware.
219 @return EFI_SUCCESS Variable passed validation successfully.
224 IN CHAR16
*VariableName
,
225 IN EFI_GUID
*VendorGuid
,
228 IN UINT32 Attributes OPTIONAL
,
233 Process variable with key exchange key for verification.
235 Caution: This function may receive untrusted input.
236 This function may be invoked in SMM mode, and datasize and data are external input.
237 This function will do basic validation, before parse the data.
238 This function will parse the authentication carefully to avoid security issues, like
239 buffer overflow, integer overflow.
240 This function will check attribute carefully to avoid authentication bypass.
242 @param[in] VariableName Name of Variable to be found.
243 @param[in] VendorGuid Variable vendor GUID.
244 @param[in] Data Data pointer.
245 @param[in] DataSize Size of Data found. If size is less than the
246 data, this value contains the required size.
247 @param[in] Attributes Attribute value of the variable.
249 @return EFI_INVALID_PARAMETER Invalid parameter.
250 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation
251 check carried out by the firmware.
252 @return EFI_SUCCESS Variable pass validation successfully.
257 IN CHAR16
*VariableName
,
258 IN EFI_GUID
*VendorGuid
,
261 IN UINT32 Attributes OPTIONAL
265 Process variable with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set
267 Caution: This function may receive untrusted input.
268 This function may be invoked in SMM mode, and datasize and data are external input.
269 This function will do basic validation, before parse the data.
270 This function will parse the authentication carefully to avoid security issues, like
271 buffer overflow, integer overflow.
272 This function will check attribute carefully to avoid authentication bypass.
274 @param[in] VariableName Name of the variable.
275 @param[in] VendorGuid Variable vendor GUID.
276 @param[in] Data Data pointer.
277 @param[in] DataSize Size of Data.
278 @param[in] Attributes Attribute value of the variable.
280 @return EFI_INVALID_PARAMETER Invalid parameter.
281 @return EFI_WRITE_PROTECTED Variable is write-protected and needs authentication with
282 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set.
283 @return EFI_OUT_OF_RESOURCES The Database to save the public key is full.
284 @return EFI_SECURITY_VIOLATION The variable is with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
285 set, but the AuthInfo does NOT pass the validation
286 check carried out by the firmware.
287 @return EFI_SUCCESS Variable is not write-protected or pass validation successfully.
292 IN CHAR16
*VariableName
,
293 IN EFI_GUID
*VendorGuid
,
300 Finds variable in storage blocks of volatile and non-volatile storage areas.
302 This code finds variable in storage blocks of volatile and non-volatile storage areas.
303 If VariableName is an empty string, then we just return the first
304 qualified variable without comparing VariableName and VendorGuid.
306 @param[in] VariableName Name of the variable to be found.
307 @param[in] VendorGuid Variable vendor GUID to be found.
308 @param[out] Data Pointer to data address.
309 @param[out] DataSize Pointer to data size.
311 @retval EFI_INVALID_PARAMETER If VariableName is not an empty string,
312 while VendorGuid is NULL.
313 @retval EFI_SUCCESS Variable successfully found.
314 @retval EFI_NOT_FOUND Variable not found
318 AuthServiceInternalFindVariable (
319 IN CHAR16
*VariableName
,
320 IN EFI_GUID
*VendorGuid
,
326 Update the variable region with Variable information.
328 @param[in] VariableName Name of variable.
329 @param[in] VendorGuid Guid of variable.
330 @param[in] Data Data pointer.
331 @param[in] DataSize Size of Data.
332 @param[in] Attributes Attribute value of the variable.
334 @retval EFI_SUCCESS The update operation is success.
335 @retval EFI_INVALID_PARAMETER Invalid parameter.
336 @retval EFI_WRITE_PROTECTED Variable is write-protected.
337 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
341 AuthServiceInternalUpdateVariable (
342 IN CHAR16
*VariableName
,
343 IN EFI_GUID
*VendorGuid
,
350 Update the variable region with Variable information.
352 @param[in] VariableName Name of variable.
353 @param[in] VendorGuid Guid of variable.
354 @param[in] Data Data pointer.
355 @param[in] DataSize Size of Data.
356 @param[in] Attributes Attribute value of the variable.
357 @param[in] TimeStamp Value of associated TimeStamp.
359 @retval EFI_SUCCESS The update operation is success.
360 @retval EFI_INVALID_PARAMETER Invalid parameter.
361 @retval EFI_WRITE_PROTECTED Variable is write-protected.
362 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
366 AuthServiceInternalUpdateVariableWithTimeStamp (
367 IN CHAR16
*VariableName
,
368 IN EFI_GUID
*VendorGuid
,
371 IN UINT32 Attributes
,
372 IN EFI_TIME
*TimeStamp