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
;
131 extern BOOLEAN mUserPhysicalPresent
;
133 extern VOID
*mHashCtx
;
135 extern AUTH_VAR_LIB_CONTEXT_IN
*mAuthVarLibContextIn
;
139 Process variable with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set
141 Caution: This function may receive untrusted input.
142 This function may be invoked in SMM mode, and datasize and data are external input.
143 This function will do basic validation, before parse the data.
144 This function will parse the authentication carefully to avoid security issues, like
145 buffer overflow, integer overflow.
147 @param[in] VariableName Name of Variable to be found.
148 @param[in] VendorGuid Variable vendor GUID.
149 @param[in] Data Data pointer.
150 @param[in] DataSize Size of Data found. If size is less than the
151 data, this value contains the required size.
152 @param[in] Attributes Attribute value of the variable.
153 @param[in] AuthVarType Verify against PK, KEK database, private database or certificate in data payload.
154 @param[out] VarDel Delete the variable or not.
156 @retval EFI_INVALID_PARAMETER Invalid parameter.
157 @retval EFI_SECURITY_VIOLATION The variable does NOT pass the validation
158 check carried out by the firmware.
159 @retval EFI_OUT_OF_RESOURCES Failed to process variable due to lack
161 @retval EFI_SUCCESS Variable pass validation successfully.
165 VerifyTimeBasedPayloadAndUpdate (
166 IN CHAR16
*VariableName
,
167 IN EFI_GUID
*VendorGuid
,
170 IN UINT32 Attributes
,
171 IN AUTHVAR_TYPE AuthVarType
,
176 Delete matching signer's certificates when deleting common authenticated
177 variable by corresponding VariableName and VendorGuid from "certdb" or
178 "certdbv" according to authenticated variable attributes.
180 @param[in] VariableName Name of authenticated Variable.
181 @param[in] VendorGuid Vendor GUID of authenticated Variable.
182 @param[in] Attributes Attributes of authenticated variable.
184 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
185 @retval EFI_NOT_FOUND Fail to find "certdb"/"certdbv" or matching certs.
186 @retval EFI_OUT_OF_RESOURCES The operation is failed due to lack of resources.
187 @retval EFI_SUCCESS The operation is completed successfully.
192 IN CHAR16
*VariableName
,
193 IN EFI_GUID
*VendorGuid
,
198 Clean up signer's certificates for common authenticated variable
199 by corresponding VariableName and VendorGuid from "certdb".
200 Sytem may break down during Timebased Variable update & certdb update,
201 make them inconsistent, this function is called in AuthVariable Init to ensure
204 @retval EFI_NOT_FOUND Fail to find matching certs.
205 @retval EFI_SUCCESS Find matching certs and output parameters.
214 Filter out the duplicated EFI_SIGNATURE_DATA from the new data by comparing to the original data.
216 @param[in] Data Pointer to original EFI_SIGNATURE_LIST.
217 @param[in] DataSize Size of Data buffer.
218 @param[in, out] NewData Pointer to new EFI_SIGNATURE_LIST.
219 @param[in, out] NewDataSize Size of NewData buffer.
223 FilterSignatureList (
226 IN OUT VOID
*NewData
,
227 IN OUT UINTN
*NewDataSize
231 Process variable with platform key for verification.
233 Caution: This function may receive untrusted input.
234 This function may be invoked in SMM mode, and datasize and data are external input.
235 This function will do basic validation, before parse the data.
236 This function will parse the authentication carefully to avoid security issues, like
237 buffer overflow, integer overflow.
238 This function will check attribute carefully to avoid authentication bypass.
240 @param[in] VariableName Name of Variable to be found.
241 @param[in] VendorGuid Variable vendor GUID.
242 @param[in] Data Data pointer.
243 @param[in] DataSize Size of Data found. If size is less than the
244 data, this value contains the required size.
245 @param[in] Attributes Attribute value of the variable
246 @param[in] IsPk Indicate whether it is to process pk.
248 @return EFI_INVALID_PARAMETER Invalid parameter.
249 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation.
250 check carried out by the firmware.
251 @return EFI_SUCCESS Variable passed validation successfully.
256 IN CHAR16
*VariableName
,
257 IN EFI_GUID
*VendorGuid
,
260 IN UINT32 Attributes OPTIONAL
,
265 Process variable with key exchange key for verification.
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 Variable to be found.
275 @param[in] VendorGuid Variable vendor GUID.
276 @param[in] Data Data pointer.
277 @param[in] DataSize Size of Data found. If size is less than the
278 data, this value contains the required size.
279 @param[in] Attributes Attribute value of the variable.
281 @return EFI_INVALID_PARAMETER Invalid parameter.
282 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation
283 check carried out by the firmware.
284 @return EFI_SUCCESS Variable pass validation successfully.
289 IN CHAR16
*VariableName
,
290 IN EFI_GUID
*VendorGuid
,
293 IN UINT32 Attributes OPTIONAL
297 Process variable with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS/EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set
299 Caution: This function may receive untrusted input.
300 This function may be invoked in SMM mode, and datasize and data are external input.
301 This function will do basic validation, before parse the data.
302 This function will parse the authentication carefully to avoid security issues, like
303 buffer overflow, integer overflow.
304 This function will check attribute carefully to avoid authentication bypass.
306 @param[in] VariableName Name of the variable.
307 @param[in] VendorGuid Variable vendor GUID.
308 @param[in] Data Data pointer.
309 @param[in] DataSize Size of Data.
310 @param[in] Attributes Attribute value of the variable.
312 @return EFI_INVALID_PARAMETER Invalid parameter.
313 @return EFI_WRITE_PROTECTED Variable is write-protected and needs authentication with
314 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS set.
315 @return EFI_OUT_OF_RESOURCES The Database to save the public key is full.
316 @return EFI_SECURITY_VIOLATION The variable is with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
317 set, but the AuthInfo does NOT pass the validation
318 check carried out by the firmware.
319 @return EFI_SUCCESS Variable is not write-protected or pass validation successfully.
324 IN CHAR16
*VariableName
,
325 IN EFI_GUID
*VendorGuid
,
332 Finds variable in storage blocks of volatile and non-volatile storage areas.
334 This code finds variable in storage blocks of volatile and non-volatile storage areas.
335 If VariableName is an empty string, then we just return the first
336 qualified variable without comparing VariableName and VendorGuid.
338 @param[in] VariableName Name of the variable to be found.
339 @param[in] VendorGuid Variable vendor GUID to be found.
340 @param[out] Data Pointer to data address.
341 @param[out] DataSize Pointer to data size.
343 @retval EFI_INVALID_PARAMETER If VariableName is not an empty string,
344 while VendorGuid is NULL.
345 @retval EFI_SUCCESS Variable successfully found.
346 @retval EFI_NOT_FOUND Variable not found
350 AuthServiceInternalFindVariable (
351 IN CHAR16
*VariableName
,
352 IN EFI_GUID
*VendorGuid
,
358 Update the variable region with Variable information.
360 @param[in] VariableName Name of variable.
361 @param[in] VendorGuid Guid of variable.
362 @param[in] Data Data pointer.
363 @param[in] DataSize Size of Data.
364 @param[in] Attributes Attribute value of the variable.
366 @retval EFI_SUCCESS The update operation is success.
367 @retval EFI_INVALID_PARAMETER Invalid parameter.
368 @retval EFI_WRITE_PROTECTED Variable is write-protected.
369 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
373 AuthServiceInternalUpdateVariable (
374 IN CHAR16
*VariableName
,
375 IN EFI_GUID
*VendorGuid
,
382 Update the variable region with Variable information.
384 @param[in] VariableName Name of variable.
385 @param[in] VendorGuid Guid of variable.
386 @param[in] Data Data pointer.
387 @param[in] DataSize Size of Data.
388 @param[in] Attributes Attribute value of the variable.
389 @param[in] KeyIndex Index of associated public key.
390 @param[in] MonotonicCount Value of associated monotonic count.
392 @retval EFI_SUCCESS The update operation is success.
393 @retval EFI_INVALID_PARAMETER Invalid parameter.
394 @retval EFI_WRITE_PROTECTED Variable is write-protected.
395 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
399 AuthServiceInternalUpdateVariableWithMonotonicCount (
400 IN CHAR16
*VariableName
,
401 IN EFI_GUID
*VendorGuid
,
404 IN UINT32 Attributes
,
406 IN UINT64 MonotonicCount
410 Update the variable region with Variable information.
412 @param[in] VariableName Name of variable.
413 @param[in] VendorGuid Guid of variable.
414 @param[in] Data Data pointer.
415 @param[in] DataSize Size of Data.
416 @param[in] Attributes Attribute value of the variable.
417 @param[in] TimeStamp Value of associated TimeStamp.
419 @retval EFI_SUCCESS The update operation is success.
420 @retval EFI_INVALID_PARAMETER Invalid parameter.
421 @retval EFI_WRITE_PROTECTED Variable is write-protected.
422 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
426 AuthServiceInternalUpdateVariableWithTimeStamp (
427 IN CHAR16
*VariableName
,
428 IN EFI_GUID
*VendorGuid
,
431 IN UINT32 Attributes
,
432 IN EFI_TIME
*TimeStamp