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 - 2015, 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>
41 /// Struct to record signature requirement defined by UEFI spec.
42 /// For SigHeaderSize and SigDataSize, ((UINT32) ~0) means NO exact length requirement for this field.
46 // Expected SignatureHeader size in Bytes.
48 // Expected SignatureData size in Bytes.
60 /// "AuthVarKeyDatabase" variable for the Public Key store
61 /// of variables with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS set.
63 /// GUID: gEfiAuthenticatedVariableGuid
65 /// We need maintain atomicity.
68 /// +----------------------------+
69 /// | AUTHVAR_KEY_DB_DATA | <-- First AuthVarKey
70 /// +----------------------------+
72 /// +----------------------------+
73 /// | AUTHVAR_KEY_DB_DATA | <-- Last AuthKey
74 /// +----------------------------+
76 #define AUTHVAR_KEYDB_NAME L"AuthVarKeyDatabase"
78 #define EFI_CERT_TYPE_RSA2048_SHA256_SIZE 256
79 #define EFI_CERT_TYPE_RSA2048_SIZE 256
84 UINT8 KeyData
[EFI_CERT_TYPE_RSA2048_SIZE
];
85 } AUTHVAR_KEY_DB_DATA
;
89 /// "certdb" variable stores the signer's certificates for non PK/KEK/DB/DBX
90 /// variables with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set.
92 /// GUID: gEfiCertDbGuid
94 /// We need maintain atomicity.
97 /// +----------------------------+
98 /// | UINT32 | <-- CertDbListSize, including this UINT32
99 /// +----------------------------+
100 /// | AUTH_CERT_DB_DATA | <-- First CERT
101 /// +----------------------------+
103 /// +----------------------------+
104 /// | AUTH_CERT_DB_DATA | <-- Last CERT
105 /// +----------------------------+
107 #define EFI_CERT_DB_NAME L"certdb"
115 /// CHAR16 VariableName[NameSize];
116 /// UINT8 CertData[CertDataSize];
120 extern UINT8
*mPubKeyStore
;
121 extern UINT32 mPubKeyNumber
;
122 extern UINT32 mMaxKeyNumber
;
123 extern UINT32 mMaxKeyDbSize
;
124 extern UINT8
*mCertDbStore
;
125 extern UINT32 mMaxCertDbSize
;
126 extern UINT32 mPlatformMode
;
127 extern UINT8 mVendorKeyState
;
129 extern VOID
*mHashCtx
;
131 extern AUTH_VAR_LIB_CONTEXT_IN
*mAuthVarLibContextIn
;
134 Process variable with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set
136 Caution: This function may receive untrusted input.
137 This function may be invoked in SMM mode, and datasize and data are external input.
138 This function will do basic validation, before parse the data.
139 This function will parse the authentication carefully to avoid security issues, like
140 buffer overflow, integer overflow.
142 @param[in] VariableName Name of Variable to be found.
143 @param[in] VendorGuid Variable vendor GUID.
144 @param[in] Data Data pointer.
145 @param[in] DataSize Size of Data found. If size is less than the
146 data, this value contains the required size.
147 @param[in] Attributes Attribute value of the variable.
148 @param[in] AuthVarType Verify against PK, KEK database, private database or certificate in data payload.
149 @param[out] VarDel Delete the variable or not.
151 @retval EFI_INVALID_PARAMETER Invalid parameter.
152 @retval EFI_SECURITY_VIOLATION The variable does NOT pass the validation
153 check carried out by the firmware.
154 @retval EFI_OUT_OF_RESOURCES Failed to process variable due to lack
156 @retval EFI_SUCCESS Variable pass validation successfully.
160 VerifyTimeBasedPayloadAndUpdate (
161 IN CHAR16
*VariableName
,
162 IN EFI_GUID
*VendorGuid
,
165 IN UINT32 Attributes
,
166 IN AUTHVAR_TYPE AuthVarType
,
171 Delete matching signer's certificates when deleting common authenticated
172 variable by corresponding VariableName and VendorGuid from "certdb".
174 @param[in] VariableName Name of authenticated Variable.
175 @param[in] VendorGuid Vendor GUID of authenticated Variable.
177 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
178 @retval EFI_NOT_FOUND Fail to find "certdb" or matching certs.
179 @retval EFI_OUT_OF_RESOURCES The operation is failed due to lack of resources.
180 @retval EFI_SUCCESS The operation is completed successfully.
185 IN CHAR16
*VariableName
,
186 IN EFI_GUID
*VendorGuid
190 Clean up signer's certificates for common authenticated variable
191 by corresponding VariableName and VendorGuid from "certdb".
192 Sytem may break down during Timebased Variable update & certdb update,
193 make them inconsistent, this function is called in AuthVariable Init to ensure
196 @retval EFI_NOT_FOUND Fail to find matching certs.
197 @retval EFI_SUCCESS Find matching certs and output parameters.
206 Filter out the duplicated EFI_SIGNATURE_DATA from the new data by comparing to the original data.
208 @param[in] Data Pointer to original EFI_SIGNATURE_LIST.
209 @param[in] DataSize Size of Data buffer.
210 @param[in, out] NewData Pointer to new EFI_SIGNATURE_LIST.
211 @param[in, out] NewDataSize Size of NewData buffer.
215 FilterSignatureList (
218 IN OUT VOID
*NewData
,
219 IN OUT UINTN
*NewDataSize
223 Process variable with platform key for verification.
225 Caution: This function may receive untrusted input.
226 This function may be invoked in SMM mode, and datasize and data are external input.
227 This function will do basic validation, before parse the data.
228 This function will parse the authentication carefully to avoid security issues, like
229 buffer overflow, integer overflow.
230 This function will check attribute carefully to avoid authentication bypass.
232 @param[in] VariableName Name of Variable to be found.
233 @param[in] VendorGuid Variable vendor GUID.
234 @param[in] Data Data pointer.
235 @param[in] DataSize Size of Data found. If size is less than the
236 data, this value contains the required size.
237 @param[in] Attributes Attribute value of the variable
238 @param[in] IsPk Indicate whether it is to process pk.
240 @return EFI_INVALID_PARAMETER Invalid parameter.
241 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation.
242 check carried out by the firmware.
243 @return EFI_SUCCESS Variable passed validation successfully.
248 IN CHAR16
*VariableName
,
249 IN EFI_GUID
*VendorGuid
,
252 IN UINT32 Attributes OPTIONAL
,
257 Process variable with key exchange key for verification.
259 Caution: This function may receive untrusted input.
260 This function may be invoked in SMM mode, and datasize and data are external input.
261 This function will do basic validation, before parse the data.
262 This function will parse the authentication carefully to avoid security issues, like
263 buffer overflow, integer overflow.
264 This function will check attribute carefully to avoid authentication bypass.
266 @param[in] VariableName Name of Variable to be found.
267 @param[in] VendorGuid Variable vendor GUID.
268 @param[in] Data Data pointer.
269 @param[in] DataSize Size of Data found. If size is less than the
270 data, this value contains the required size.
271 @param[in] Attributes Attribute value of the variable.
273 @return EFI_INVALID_PARAMETER Invalid parameter.
274 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation
275 check carried out by the firmware.
276 @return EFI_SUCCESS Variable pass validation successfully.
281 IN CHAR16
*VariableName
,
282 IN EFI_GUID
*VendorGuid
,
285 IN UINT32 Attributes OPTIONAL
289 Process variable with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS/EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set
291 Caution: This function may receive untrusted input.
292 This function may be invoked in SMM mode, and datasize and data are external input.
293 This function will do basic validation, before parse the data.
294 This function will parse the authentication carefully to avoid security issues, like
295 buffer overflow, integer overflow.
296 This function will check attribute carefully to avoid authentication bypass.
298 @param[in] VariableName Name of the variable.
299 @param[in] VendorGuid Variable vendor GUID.
300 @param[in] Data Data pointer.
301 @param[in] DataSize Size of Data.
302 @param[in] Attributes Attribute value of the variable.
304 @return EFI_INVALID_PARAMETER Invalid parameter.
305 @return EFI_WRITE_PROTECTED Variable is write-protected and needs authentication with
306 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS set.
307 @return EFI_OUT_OF_RESOURCES The Database to save the public key is full.
308 @return EFI_SECURITY_VIOLATION The variable is with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
309 set, but the AuthInfo does NOT pass the validation
310 check carried out by the firmware.
311 @return EFI_SUCCESS Variable is not write-protected or pass validation successfully.
316 IN CHAR16
*VariableName
,
317 IN EFI_GUID
*VendorGuid
,
320 IN UINT32 Attributes OPTIONAL
324 Finds variable in storage blocks of volatile and non-volatile storage areas.
326 This code finds variable in storage blocks of volatile and non-volatile storage areas.
327 If VariableName is an empty string, then we just return the first
328 qualified variable without comparing VariableName and VendorGuid.
330 @param[in] VariableName Name of the variable to be found.
331 @param[in] VendorGuid Variable vendor GUID to be found.
332 @param[out] Data Pointer to data address.
333 @param[out] DataSize Pointer to data size.
335 @retval EFI_INVALID_PARAMETER If VariableName is not an empty string,
336 while VendorGuid is NULL.
337 @retval EFI_SUCCESS Variable successfully found.
338 @retval EFI_NOT_FOUND Variable not found
342 AuthServiceInternalFindVariable (
343 IN CHAR16
*VariableName
,
344 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.
358 @retval EFI_SUCCESS The update operation is success.
359 @retval EFI_INVALID_PARAMETER Invalid parameter.
360 @retval EFI_WRITE_PROTECTED Variable is write-protected.
361 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
365 AuthServiceInternalUpdateVariable (
366 IN CHAR16
*VariableName
,
367 IN EFI_GUID
*VendorGuid
,
374 Update the variable region with Variable information.
376 @param[in] VariableName Name of variable.
377 @param[in] VendorGuid Guid of variable.
378 @param[in] Data Data pointer.
379 @param[in] DataSize Size of Data.
380 @param[in] Attributes Attribute value of the variable.
381 @param[in] KeyIndex Index of associated public key.
382 @param[in] MonotonicCount Value of associated monotonic count.
384 @retval EFI_SUCCESS The update operation is success.
385 @retval EFI_INVALID_PARAMETER Invalid parameter.
386 @retval EFI_WRITE_PROTECTED Variable is write-protected.
387 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
391 AuthServiceInternalUpdateVariableWithMonotonicCount (
392 IN CHAR16
*VariableName
,
393 IN EFI_GUID
*VendorGuid
,
396 IN UINT32 Attributes
,
398 IN UINT64 MonotonicCount
402 Update the variable region with Variable information.
404 @param[in] VariableName Name of variable.
405 @param[in] VendorGuid Guid of variable.
406 @param[in] Data Data pointer.
407 @param[in] DataSize Size of Data.
408 @param[in] Attributes Attribute value of the variable.
409 @param[in] TimeStamp Value of associated TimeStamp.
411 @retval EFI_SUCCESS The update operation is success.
412 @retval EFI_INVALID_PARAMETER Invalid parameter.
413 @retval EFI_WRITE_PROTECTED Variable is write-protected.
414 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
418 AuthServiceInternalUpdateVariableWithTimeStamp (
419 IN CHAR16
*VariableName
,
420 IN EFI_GUID
*VendorGuid
,
423 IN UINT32 Attributes
,
424 IN EFI_TIME
*TimeStamp