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 Filter out the duplicated EFI_SIGNATURE_DATA from the new data by comparing to the original data.
192 @param[in] Data Pointer to original EFI_SIGNATURE_LIST.
193 @param[in] DataSize Size of Data buffer.
194 @param[in, out] NewData Pointer to new EFI_SIGNATURE_LIST.
195 @param[in, out] NewDataSize Size of NewData buffer.
199 FilterSignatureList (
202 IN OUT VOID
*NewData
,
203 IN OUT UINTN
*NewDataSize
207 Process variable with platform key for verification.
209 Caution: This function may receive untrusted input.
210 This function may be invoked in SMM mode, and datasize and data are external input.
211 This function will do basic validation, before parse the data.
212 This function will parse the authentication carefully to avoid security issues, like
213 buffer overflow, integer overflow.
214 This function will check attribute carefully to avoid authentication bypass.
216 @param[in] VariableName Name of Variable to be found.
217 @param[in] VendorGuid Variable vendor GUID.
218 @param[in] Data Data pointer.
219 @param[in] DataSize Size of Data found. If size is less than the
220 data, this value contains the required size.
221 @param[in] Attributes Attribute value of the variable
222 @param[in] IsPk Indicate whether it is to process pk.
224 @return EFI_INVALID_PARAMETER Invalid parameter.
225 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation.
226 check carried out by the firmware.
227 @return EFI_SUCCESS Variable passed validation successfully.
232 IN CHAR16
*VariableName
,
233 IN EFI_GUID
*VendorGuid
,
236 IN UINT32 Attributes OPTIONAL
,
241 Process variable with key exchange key for verification.
243 Caution: This function may receive untrusted input.
244 This function may be invoked in SMM mode, and datasize and data are external input.
245 This function will do basic validation, before parse the data.
246 This function will parse the authentication carefully to avoid security issues, like
247 buffer overflow, integer overflow.
248 This function will check attribute carefully to avoid authentication bypass.
250 @param[in] VariableName Name of Variable to be found.
251 @param[in] VendorGuid Variable vendor GUID.
252 @param[in] Data Data pointer.
253 @param[in] DataSize Size of Data found. If size is less than the
254 data, this value contains the required size.
255 @param[in] Attributes Attribute value of the variable.
257 @return EFI_INVALID_PARAMETER Invalid parameter.
258 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation
259 check carried out by the firmware.
260 @return EFI_SUCCESS Variable pass validation successfully.
265 IN CHAR16
*VariableName
,
266 IN EFI_GUID
*VendorGuid
,
269 IN UINT32 Attributes OPTIONAL
273 Process variable with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS/EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set
275 Caution: This function may receive untrusted input.
276 This function may be invoked in SMM mode, and datasize and data are external input.
277 This function will do basic validation, before parse the data.
278 This function will parse the authentication carefully to avoid security issues, like
279 buffer overflow, integer overflow.
280 This function will check attribute carefully to avoid authentication bypass.
282 @param[in] VariableName Name of the variable.
283 @param[in] VendorGuid Variable vendor GUID.
284 @param[in] Data Data pointer.
285 @param[in] DataSize Size of Data.
286 @param[in] Attributes Attribute value of the variable.
288 @return EFI_INVALID_PARAMETER Invalid parameter.
289 @return EFI_WRITE_PROTECTED Variable is write-protected and needs authentication with
290 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS set.
291 @return EFI_OUT_OF_RESOURCES The Database to save the public key is full.
292 @return EFI_SECURITY_VIOLATION The variable is with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
293 set, but the AuthInfo does NOT pass the validation
294 check carried out by the firmware.
295 @return EFI_SUCCESS Variable is not write-protected or pass validation successfully.
300 IN CHAR16
*VariableName
,
301 IN EFI_GUID
*VendorGuid
,
304 IN UINT32 Attributes OPTIONAL
308 Finds variable in storage blocks of volatile and non-volatile storage areas.
310 This code finds variable in storage blocks of volatile and non-volatile storage areas.
311 If VariableName is an empty string, then we just return the first
312 qualified variable without comparing VariableName and VendorGuid.
314 @param[in] VariableName Name of the variable to be found.
315 @param[in] VendorGuid Variable vendor GUID to be found.
316 @param[out] Data Pointer to data address.
317 @param[out] DataSize Pointer to data size.
319 @retval EFI_INVALID_PARAMETER If VariableName is not an empty string,
320 while VendorGuid is NULL.
321 @retval EFI_SUCCESS Variable successfully found.
322 @retval EFI_NOT_FOUND Variable not found
326 AuthServiceInternalFindVariable (
327 IN CHAR16
*VariableName
,
328 IN EFI_GUID
*VendorGuid
,
334 Update the variable region with Variable information.
336 @param[in] VariableName Name of variable.
337 @param[in] VendorGuid Guid of variable.
338 @param[in] Data Data pointer.
339 @param[in] DataSize Size of Data.
340 @param[in] Attributes Attribute value of the variable.
342 @retval EFI_SUCCESS The update operation is success.
343 @retval EFI_INVALID_PARAMETER Invalid parameter.
344 @retval EFI_WRITE_PROTECTED Variable is write-protected.
345 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
349 AuthServiceInternalUpdateVariable (
350 IN CHAR16
*VariableName
,
351 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.
365 @param[in] KeyIndex Index of associated public key.
366 @param[in] MonotonicCount Value of associated monotonic count.
368 @retval EFI_SUCCESS The update operation is success.
369 @retval EFI_INVALID_PARAMETER Invalid parameter.
370 @retval EFI_WRITE_PROTECTED Variable is write-protected.
371 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
375 AuthServiceInternalUpdateVariableWithMonotonicCount (
376 IN CHAR16
*VariableName
,
377 IN EFI_GUID
*VendorGuid
,
380 IN UINT32 Attributes
,
382 IN UINT64 MonotonicCount
386 Update the variable region with Variable information.
388 @param[in] VariableName Name of variable.
389 @param[in] VendorGuid Guid of variable.
390 @param[in] Data Data pointer.
391 @param[in] DataSize Size of Data.
392 @param[in] Attributes Attribute value of the variable.
393 @param[in] TimeStamp Value of associated TimeStamp.
395 @retval EFI_SUCCESS The update operation is success.
396 @retval EFI_INVALID_PARAMETER Invalid parameter.
397 @retval EFI_WRITE_PROTECTED Variable is write-protected.
398 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
402 AuthServiceInternalUpdateVariableWithTimeStamp (
403 IN CHAR16
*VariableName
,
404 IN EFI_GUID
*VendorGuid
,
407 IN UINT32 Attributes
,
408 IN EFI_TIME
*TimeStamp