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 /// "AuthVarKeyDatabase" variable for the Public Key store
63 /// of variables with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS set.
65 /// GUID: gEfiAuthenticatedVariableGuid
67 /// We need maintain atomicity.
70 /// +----------------------------+
71 /// | AUTHVAR_KEY_DB_DATA | <-- First AuthVarKey
72 /// +----------------------------+
74 /// +----------------------------+
75 /// | AUTHVAR_KEY_DB_DATA | <-- Last AuthKey
76 /// +----------------------------+
78 #define AUTHVAR_KEYDB_NAME L"AuthVarKeyDatabase"
80 #define EFI_CERT_TYPE_RSA2048_SHA256_SIZE 256
81 #define EFI_CERT_TYPE_RSA2048_SIZE 256
86 UINT8 KeyData
[EFI_CERT_TYPE_RSA2048_SIZE
];
87 } AUTHVAR_KEY_DB_DATA
;
91 /// "certdb" variable stores the signer's certificates for non PK/KEK/DB/DBX
92 /// variables with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS|EFI_VARIABLE_NON_VOLATILE set.
93 /// "certdbv" variable stores the signer's certificates for non PK/KEK/DB/DBX
94 /// variables with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set
96 /// GUID: gEfiCertDbGuid
98 /// We need maintain atomicity.
101 /// +----------------------------+
102 /// | UINT32 | <-- CertDbListSize, including this UINT32
103 /// +----------------------------+
104 /// | AUTH_CERT_DB_DATA | <-- First CERT
105 /// +----------------------------+
107 /// +----------------------------+
108 /// | AUTH_CERT_DB_DATA | <-- Last CERT
109 /// +----------------------------+
111 #define EFI_CERT_DB_NAME L"certdb"
112 #define EFI_CERT_DB_VOLATILE_NAME L"certdbv"
120 /// CHAR16 VariableName[NameSize];
121 /// UINT8 CertData[CertDataSize];
125 extern UINT8
*mPubKeyStore
;
126 extern UINT32 mPubKeyNumber
;
127 extern UINT32 mMaxKeyNumber
;
128 extern UINT32 mMaxKeyDbSize
;
129 extern UINT8
*mCertDbStore
;
130 extern UINT32 mMaxCertDbSize
;
131 extern UINT32 mPlatformMode
;
132 extern UINT8 mVendorKeyState
;
134 extern VOID
*mHashCtx
;
136 extern AUTH_VAR_LIB_CONTEXT_IN
*mAuthVarLibContextIn
;
140 Process variable with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set
142 Caution: This function may receive untrusted input.
143 This function may be invoked in SMM mode, and datasize and data are external input.
144 This function will do basic validation, before parse the data.
145 This function will parse the authentication carefully to avoid security issues, like
146 buffer overflow, integer overflow.
148 @param[in] VariableName Name of Variable to be found.
149 @param[in] VendorGuid Variable vendor GUID.
150 @param[in] Data Data pointer.
151 @param[in] DataSize Size of Data found. If size is less than the
152 data, this value contains the required size.
153 @param[in] Attributes Attribute value of the variable.
154 @param[in] AuthVarType Verify against PK, KEK database, private database or certificate in data payload.
155 @param[out] VarDel Delete the variable or not.
157 @retval EFI_INVALID_PARAMETER Invalid parameter.
158 @retval EFI_SECURITY_VIOLATION The variable does NOT pass the validation
159 check carried out by the firmware.
160 @retval EFI_OUT_OF_RESOURCES Failed to process variable due to lack
162 @retval EFI_SUCCESS Variable pass validation successfully.
166 VerifyTimeBasedPayloadAndUpdate (
167 IN CHAR16
*VariableName
,
168 IN EFI_GUID
*VendorGuid
,
171 IN UINT32 Attributes
,
172 IN AUTHVAR_TYPE AuthVarType
,
177 Delete matching signer's certificates when deleting common authenticated
178 variable by corresponding VariableName and VendorGuid from "certdb" or
179 "certdbv" according to authenticated variable attributes.
181 @param[in] VariableName Name of authenticated Variable.
182 @param[in] VendorGuid Vendor GUID of authenticated Variable.
183 @param[in] Attributes Attributes of authenticated variable.
185 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
186 @retval EFI_NOT_FOUND Fail to find "certdb"/"certdbv" or matching certs.
187 @retval EFI_OUT_OF_RESOURCES The operation is failed due to lack of resources.
188 @retval EFI_SUCCESS The operation is completed successfully.
193 IN CHAR16
*VariableName
,
194 IN EFI_GUID
*VendorGuid
,
199 Clean up signer's certificates for common authenticated variable
200 by corresponding VariableName and VendorGuid from "certdb".
201 Sytem may break down during Timebased Variable update & certdb update,
202 make them inconsistent, this function is called in AuthVariable Init to ensure
205 @retval EFI_NOT_FOUND Fail to find matching certs.
206 @retval EFI_SUCCESS Find matching certs and output parameters.
215 Filter out the duplicated EFI_SIGNATURE_DATA from the new data by comparing to the original data.
217 @param[in] Data Pointer to original EFI_SIGNATURE_LIST.
218 @param[in] DataSize Size of Data buffer.
219 @param[in, out] NewData Pointer to new EFI_SIGNATURE_LIST.
220 @param[in, out] NewDataSize Size of NewData buffer.
224 FilterSignatureList (
227 IN OUT VOID
*NewData
,
228 IN OUT UINTN
*NewDataSize
232 Process variable with platform key for verification.
234 Caution: This function may receive untrusted input.
235 This function may be invoked in SMM mode, and datasize and data are external input.
236 This function will do basic validation, before parse the data.
237 This function will parse the authentication carefully to avoid security issues, like
238 buffer overflow, integer overflow.
239 This function will check attribute carefully to avoid authentication bypass.
241 @param[in] VariableName Name of Variable to be found.
242 @param[in] VendorGuid Variable vendor GUID.
243 @param[in] Data Data pointer.
244 @param[in] DataSize Size of Data found. If size is less than the
245 data, this value contains the required size.
246 @param[in] Attributes Attribute value of the variable
247 @param[in] IsPk Indicate whether it is to process pk.
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 passed validation successfully.
257 IN CHAR16
*VariableName
,
258 IN EFI_GUID
*VendorGuid
,
261 IN UINT32 Attributes OPTIONAL
,
266 Process variable with key exchange key for verification.
268 Caution: This function may receive untrusted input.
269 This function may be invoked in SMM mode, and datasize and data are external input.
270 This function will do basic validation, before parse the data.
271 This function will parse the authentication carefully to avoid security issues, like
272 buffer overflow, integer overflow.
273 This function will check attribute carefully to avoid authentication bypass.
275 @param[in] VariableName Name of Variable to be found.
276 @param[in] VendorGuid Variable vendor GUID.
277 @param[in] Data Data pointer.
278 @param[in] DataSize Size of Data found. If size is less than the
279 data, this value contains the required size.
280 @param[in] Attributes Attribute value of the variable.
282 @return EFI_INVALID_PARAMETER Invalid parameter.
283 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation
284 check carried out by the firmware.
285 @return EFI_SUCCESS Variable pass validation successfully.
290 IN CHAR16
*VariableName
,
291 IN EFI_GUID
*VendorGuid
,
294 IN UINT32 Attributes OPTIONAL
298 Process variable with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS/EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set
300 Caution: This function may receive untrusted input.
301 This function may be invoked in SMM mode, and datasize and data are external input.
302 This function will do basic validation, before parse the data.
303 This function will parse the authentication carefully to avoid security issues, like
304 buffer overflow, integer overflow.
305 This function will check attribute carefully to avoid authentication bypass.
307 @param[in] VariableName Name of the variable.
308 @param[in] VendorGuid Variable vendor GUID.
309 @param[in] Data Data pointer.
310 @param[in] DataSize Size of Data.
311 @param[in] Attributes Attribute value of the variable.
313 @return EFI_INVALID_PARAMETER Invalid parameter.
314 @return EFI_WRITE_PROTECTED Variable is write-protected and needs authentication with
315 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS set.
316 @return EFI_OUT_OF_RESOURCES The Database to save the public key is full.
317 @return EFI_SECURITY_VIOLATION The variable is with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
318 set, but the AuthInfo does NOT pass the validation
319 check carried out by the firmware.
320 @return EFI_SUCCESS Variable is not write-protected or pass validation successfully.
325 IN CHAR16
*VariableName
,
326 IN EFI_GUID
*VendorGuid
,
333 Finds variable in storage blocks of volatile and non-volatile storage areas.
335 This code finds variable in storage blocks of volatile and non-volatile storage areas.
336 If VariableName is an empty string, then we just return the first
337 qualified variable without comparing VariableName and VendorGuid.
339 @param[in] VariableName Name of the variable to be found.
340 @param[in] VendorGuid Variable vendor GUID to be found.
341 @param[out] Data Pointer to data address.
342 @param[out] DataSize Pointer to data size.
344 @retval EFI_INVALID_PARAMETER If VariableName is not an empty string,
345 while VendorGuid is NULL.
346 @retval EFI_SUCCESS Variable successfully found.
347 @retval EFI_NOT_FOUND Variable not found
351 AuthServiceInternalFindVariable (
352 IN CHAR16
*VariableName
,
353 IN EFI_GUID
*VendorGuid
,
359 Update the variable region with Variable information.
361 @param[in] VariableName Name of variable.
362 @param[in] VendorGuid Guid of variable.
363 @param[in] Data Data pointer.
364 @param[in] DataSize Size of Data.
365 @param[in] Attributes Attribute value of the variable.
367 @retval EFI_SUCCESS The update operation is success.
368 @retval EFI_INVALID_PARAMETER Invalid parameter.
369 @retval EFI_WRITE_PROTECTED Variable is write-protected.
370 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
374 AuthServiceInternalUpdateVariable (
375 IN CHAR16
*VariableName
,
376 IN EFI_GUID
*VendorGuid
,
383 Update the variable region with Variable information.
385 @param[in] VariableName Name of variable.
386 @param[in] VendorGuid Guid of variable.
387 @param[in] Data Data pointer.
388 @param[in] DataSize Size of Data.
389 @param[in] Attributes Attribute value of the variable.
390 @param[in] KeyIndex Index of associated public key.
391 @param[in] MonotonicCount Value of associated monotonic count.
393 @retval EFI_SUCCESS The update operation is success.
394 @retval EFI_INVALID_PARAMETER Invalid parameter.
395 @retval EFI_WRITE_PROTECTED Variable is write-protected.
396 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
400 AuthServiceInternalUpdateVariableWithMonotonicCount (
401 IN CHAR16
*VariableName
,
402 IN EFI_GUID
*VendorGuid
,
405 IN UINT32 Attributes
,
407 IN UINT64 MonotonicCount
411 Update the variable region with Variable information.
413 @param[in] VariableName Name of variable.
414 @param[in] VendorGuid Guid of variable.
415 @param[in] Data Data pointer.
416 @param[in] DataSize Size of Data.
417 @param[in] Attributes Attribute value of the variable.
418 @param[in] TimeStamp Value of associated TimeStamp.
420 @retval EFI_SUCCESS The update operation is success.
421 @retval EFI_INVALID_PARAMETER Invalid parameter.
422 @retval EFI_WRITE_PROTECTED Variable is write-protected.
423 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
427 AuthServiceInternalUpdateVariableWithTimeStamp (
428 IN CHAR16
*VariableName
,
429 IN EFI_GUID
*VendorGuid
,
432 IN UINT32 Attributes
,
433 IN EFI_TIME
*TimeStamp