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 - 2016, 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|EFI_VARIABLE_NON_VOLATILE set.
91 /// "certdbv" variable stores the signer's certificates for non PK/KEK/DB/DBX
92 /// variables with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set
94 /// GUID: gEfiCertDbGuid
96 /// We need maintain atomicity.
99 /// +----------------------------+
100 /// | UINT32 | <-- CertDbListSize, including this UINT32
101 /// +----------------------------+
102 /// | AUTH_CERT_DB_DATA | <-- First CERT
103 /// +----------------------------+
105 /// +----------------------------+
106 /// | AUTH_CERT_DB_DATA | <-- Last CERT
107 /// +----------------------------+
109 #define EFI_CERT_DB_NAME L"certdb"
110 #define EFI_CERT_DB_VOLATILE_NAME L"certdbv"
118 /// CHAR16 VariableName[NameSize];
119 /// UINT8 CertData[CertDataSize];
123 extern UINT8
*mPubKeyStore
;
124 extern UINT32 mPubKeyNumber
;
125 extern UINT32 mMaxKeyNumber
;
126 extern UINT32 mMaxKeyDbSize
;
127 extern UINT8
*mCertDbStore
;
128 extern UINT32 mMaxCertDbSize
;
129 extern UINT32 mPlatformMode
;
130 extern UINT8 mVendorKeyState
;
132 extern VOID
*mHashCtx
;
134 extern AUTH_VAR_LIB_CONTEXT_IN
*mAuthVarLibContextIn
;
138 Process variable with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set
140 Caution: This function may receive untrusted input.
141 This function may be invoked in SMM mode, and datasize and data are external input.
142 This function will do basic validation, before parse the data.
143 This function will parse the authentication carefully to avoid security issues, like
144 buffer overflow, integer overflow.
146 @param[in] VariableName Name of Variable to be found.
147 @param[in] VendorGuid Variable vendor GUID.
148 @param[in] Data Data pointer.
149 @param[in] DataSize Size of Data found. If size is less than the
150 data, this value contains the required size.
151 @param[in] Attributes Attribute value of the variable.
152 @param[in] AuthVarType Verify against PK, KEK database, private database or certificate in data payload.
153 @param[out] VarDel Delete the variable or not.
155 @retval EFI_INVALID_PARAMETER Invalid parameter.
156 @retval EFI_SECURITY_VIOLATION The variable does NOT pass the validation
157 check carried out by the firmware.
158 @retval EFI_OUT_OF_RESOURCES Failed to process variable due to lack
160 @retval EFI_SUCCESS Variable pass validation successfully.
164 VerifyTimeBasedPayloadAndUpdate (
165 IN CHAR16
*VariableName
,
166 IN EFI_GUID
*VendorGuid
,
169 IN UINT32 Attributes
,
170 IN AUTHVAR_TYPE AuthVarType
,
175 Delete matching signer's certificates when deleting common authenticated
176 variable by corresponding VariableName and VendorGuid from "certdb" or
177 "certdbv" according to authenticated variable attributes.
179 @param[in] VariableName Name of authenticated Variable.
180 @param[in] VendorGuid Vendor GUID of authenticated Variable.
181 @param[in] Attributes Attributes of authenticated variable.
183 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
184 @retval EFI_NOT_FOUND Fail to find "certdb"/"certdbv" or matching certs.
185 @retval EFI_OUT_OF_RESOURCES The operation is failed due to lack of resources.
186 @retval EFI_SUCCESS The operation is completed successfully.
191 IN CHAR16
*VariableName
,
192 IN EFI_GUID
*VendorGuid
,
197 Clean up signer's certificates for common authenticated variable
198 by corresponding VariableName and VendorGuid from "certdb".
199 Sytem may break down during Timebased Variable update & certdb update,
200 make them inconsistent, this function is called in AuthVariable Init to ensure
203 @retval EFI_NOT_FOUND Fail to find matching certs.
204 @retval EFI_SUCCESS Find matching certs and output parameters.
213 Filter out the duplicated EFI_SIGNATURE_DATA from the new data by comparing to the original data.
215 @param[in] Data Pointer to original EFI_SIGNATURE_LIST.
216 @param[in] DataSize Size of Data buffer.
217 @param[in, out] NewData Pointer to new EFI_SIGNATURE_LIST.
218 @param[in, out] NewDataSize Size of NewData buffer.
222 FilterSignatureList (
225 IN OUT VOID
*NewData
,
226 IN OUT UINTN
*NewDataSize
230 Process variable with platform key for verification.
232 Caution: This function may receive untrusted input.
233 This function may be invoked in SMM mode, and datasize and data are external input.
234 This function will do basic validation, before parse the data.
235 This function will parse the authentication carefully to avoid security issues, like
236 buffer overflow, integer overflow.
237 This function will check attribute carefully to avoid authentication bypass.
239 @param[in] VariableName Name of Variable to be found.
240 @param[in] VendorGuid Variable vendor GUID.
241 @param[in] Data Data pointer.
242 @param[in] DataSize Size of Data found. If size is less than the
243 data, this value contains the required size.
244 @param[in] Attributes Attribute value of the variable
245 @param[in] IsPk Indicate whether it is to process pk.
247 @return EFI_INVALID_PARAMETER Invalid parameter.
248 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation.
249 check carried out by the firmware.
250 @return EFI_SUCCESS Variable passed validation successfully.
255 IN CHAR16
*VariableName
,
256 IN EFI_GUID
*VendorGuid
,
259 IN UINT32 Attributes OPTIONAL
,
264 Process variable with key exchange key for verification.
266 Caution: This function may receive untrusted input.
267 This function may be invoked in SMM mode, and datasize and data are external input.
268 This function will do basic validation, before parse the data.
269 This function will parse the authentication carefully to avoid security issues, like
270 buffer overflow, integer overflow.
271 This function will check attribute carefully to avoid authentication bypass.
273 @param[in] VariableName Name of Variable to be found.
274 @param[in] VendorGuid Variable vendor GUID.
275 @param[in] Data Data pointer.
276 @param[in] DataSize Size of Data found. If size is less than the
277 data, this value contains the required size.
278 @param[in] Attributes Attribute value of the variable.
280 @return EFI_INVALID_PARAMETER Invalid parameter.
281 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation
282 check carried out by the firmware.
283 @return EFI_SUCCESS Variable pass validation successfully.
288 IN CHAR16
*VariableName
,
289 IN EFI_GUID
*VendorGuid
,
292 IN UINT32 Attributes OPTIONAL
296 Process variable with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS/EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set
298 Caution: This function may receive untrusted input.
299 This function may be invoked in SMM mode, and datasize and data are external input.
300 This function will do basic validation, before parse the data.
301 This function will parse the authentication carefully to avoid security issues, like
302 buffer overflow, integer overflow.
303 This function will check attribute carefully to avoid authentication bypass.
305 @param[in] VariableName Name of the variable.
306 @param[in] VendorGuid Variable vendor GUID.
307 @param[in] Data Data pointer.
308 @param[in] DataSize Size of Data.
309 @param[in] Attributes Attribute value of the variable.
311 @return EFI_INVALID_PARAMETER Invalid parameter.
312 @return EFI_WRITE_PROTECTED Variable is write-protected and needs authentication with
313 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS set.
314 @return EFI_OUT_OF_RESOURCES The Database to save the public key is full.
315 @return EFI_SECURITY_VIOLATION The variable is with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
316 set, but the AuthInfo does NOT pass the validation
317 check carried out by the firmware.
318 @return EFI_SUCCESS Variable is not write-protected or pass validation successfully.
323 IN CHAR16
*VariableName
,
324 IN EFI_GUID
*VendorGuid
,
331 Finds variable in storage blocks of volatile and non-volatile storage areas.
333 This code finds variable in storage blocks of volatile and non-volatile storage areas.
334 If VariableName is an empty string, then we just return the first
335 qualified variable without comparing VariableName and VendorGuid.
337 @param[in] VariableName Name of the variable to be found.
338 @param[in] VendorGuid Variable vendor GUID to be found.
339 @param[out] Data Pointer to data address.
340 @param[out] DataSize Pointer to data size.
342 @retval EFI_INVALID_PARAMETER If VariableName is not an empty string,
343 while VendorGuid is NULL.
344 @retval EFI_SUCCESS Variable successfully found.
345 @retval EFI_NOT_FOUND Variable not found
349 AuthServiceInternalFindVariable (
350 IN CHAR16
*VariableName
,
351 IN EFI_GUID
*VendorGuid
,
357 Update the variable region with Variable information.
359 @param[in] VariableName Name of variable.
360 @param[in] VendorGuid Guid of variable.
361 @param[in] Data Data pointer.
362 @param[in] DataSize Size of Data.
363 @param[in] Attributes Attribute value of the variable.
365 @retval EFI_SUCCESS The update operation is success.
366 @retval EFI_INVALID_PARAMETER Invalid parameter.
367 @retval EFI_WRITE_PROTECTED Variable is write-protected.
368 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
372 AuthServiceInternalUpdateVariable (
373 IN CHAR16
*VariableName
,
374 IN EFI_GUID
*VendorGuid
,
381 Update the variable region with Variable information.
383 @param[in] VariableName Name of variable.
384 @param[in] VendorGuid Guid of variable.
385 @param[in] Data Data pointer.
386 @param[in] DataSize Size of Data.
387 @param[in] Attributes Attribute value of the variable.
388 @param[in] KeyIndex Index of associated public key.
389 @param[in] MonotonicCount Value of associated monotonic count.
391 @retval EFI_SUCCESS The update operation is success.
392 @retval EFI_INVALID_PARAMETER Invalid parameter.
393 @retval EFI_WRITE_PROTECTED Variable is write-protected.
394 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
398 AuthServiceInternalUpdateVariableWithMonotonicCount (
399 IN CHAR16
*VariableName
,
400 IN EFI_GUID
*VendorGuid
,
403 IN UINT32 Attributes
,
405 IN UINT64 MonotonicCount
409 Update the variable region with Variable information.
411 @param[in] VariableName Name of variable.
412 @param[in] VendorGuid Guid of variable.
413 @param[in] Data Data pointer.
414 @param[in] DataSize Size of Data.
415 @param[in] Attributes Attribute value of the variable.
416 @param[in] TimeStamp Value of associated TimeStamp.
418 @retval EFI_SUCCESS The update operation is success.
419 @retval EFI_INVALID_PARAMETER Invalid parameter.
420 @retval EFI_WRITE_PROTECTED Variable is write-protected.
421 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
425 AuthServiceInternalUpdateVariableWithTimeStamp (
426 IN CHAR16
*VariableName
,
427 IN EFI_GUID
*VendorGuid
,
430 IN UINT32 Attributes
,
431 IN EFI_TIME
*TimeStamp