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];
121 /// "SecureBootMode" variable stores current secure boot mode.
122 /// The value type is SECURE_BOOT_MODE_TYPE.
124 #define EDKII_SECURE_BOOT_MODE_NAME L"SecureBootMode"
127 SecureBootModeTypeUserMode
,
128 SecureBootModeTypeSetupMode
,
129 SecureBootModeTypeAuditMode
,
130 SecureBootModeTypeDeployedMode
,
131 SecureBootModeTypeMax
132 } SECURE_BOOT_MODE_TYPE
;
135 // Record status info of Customized Secure Boot Mode.
139 /// AuditMode variable value
143 /// AuditMode variable RW
145 BOOLEAN IsAuditModeRO
;
147 /// DeployedMode variable value
151 /// AuditMode variable RW
153 BOOLEAN IsDeployedModeRO
;
155 /// SetupMode variable value
159 /// SetupMode is always RO. Skip IsSetupModeRO;
163 /// SecureBoot variable value
168 extern UINT8
*mPubKeyStore
;
169 extern UINT32 mPubKeyNumber
;
170 extern UINT32 mMaxKeyNumber
;
171 extern UINT32 mMaxKeyDbSize
;
172 extern UINT8
*mCertDbStore
;
173 extern UINT32 mMaxCertDbSize
;
174 extern UINT32 mPlatformMode
;
175 extern UINT8 mVendorKeyState
;
177 extern VOID
*mHashCtx
;
179 extern AUTH_VAR_LIB_CONTEXT_IN
*mAuthVarLibContextIn
;
182 Initialize Secure Boot variables.
184 @retval EFI_SUCCESS The initialization operation is successful.
185 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
189 InitSecureBootVariables (
194 Process variable with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set
196 Caution: This function may receive untrusted input.
197 This function may be invoked in SMM mode, and datasize and data are external input.
198 This function will do basic validation, before parse the data.
199 This function will parse the authentication carefully to avoid security issues, like
200 buffer overflow, integer overflow.
202 @param[in] VariableName Name of Variable to be found.
203 @param[in] VendorGuid Variable vendor GUID.
204 @param[in] Data Data pointer.
205 @param[in] DataSize Size of Data found. If size is less than the
206 data, this value contains the required size.
207 @param[in] Attributes Attribute value of the variable.
208 @param[in] AuthVarType Verify against PK, KEK database, private database or certificate in data payload.
209 @param[out] VarDel Delete the variable or not.
211 @retval EFI_INVALID_PARAMETER Invalid parameter.
212 @retval EFI_SECURITY_VIOLATION The variable does NOT pass the validation
213 check carried out by the firmware.
214 @retval EFI_OUT_OF_RESOURCES Failed to process variable due to lack
216 @retval EFI_SUCCESS Variable pass validation successfully.
220 VerifyTimeBasedPayloadAndUpdate (
221 IN CHAR16
*VariableName
,
222 IN EFI_GUID
*VendorGuid
,
225 IN UINT32 Attributes
,
226 IN AUTHVAR_TYPE AuthVarType
,
231 Delete matching signer's certificates when deleting common authenticated
232 variable by corresponding VariableName and VendorGuid from "certdb".
234 @param[in] VariableName Name of authenticated Variable.
235 @param[in] VendorGuid Vendor GUID of authenticated Variable.
237 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
238 @retval EFI_NOT_FOUND Fail to find "certdb" or matching certs.
239 @retval EFI_OUT_OF_RESOURCES The operation is failed due to lack of resources.
240 @retval EFI_SUCCESS The operation is completed successfully.
245 IN CHAR16
*VariableName
,
246 IN EFI_GUID
*VendorGuid
250 Clean up signer's certificates for common authenticated variable
251 by corresponding VariableName and VendorGuid from "certdb".
252 Sytem may break down during Timebased Variable update & certdb update,
253 make them inconsistent, this function is called in AuthVariable Init to ensure
256 @retval EFI_NOT_FOUND Fail to find matching certs.
257 @retval EFI_SUCCESS Find matching certs and output parameters.
266 Filter out the duplicated EFI_SIGNATURE_DATA from the new data by comparing to the original data.
268 @param[in] Data Pointer to original EFI_SIGNATURE_LIST.
269 @param[in] DataSize Size of Data buffer.
270 @param[in, out] NewData Pointer to new EFI_SIGNATURE_LIST.
271 @param[in, out] NewDataSize Size of NewData buffer.
275 FilterSignatureList (
278 IN OUT VOID
*NewData
,
279 IN OUT UINTN
*NewDataSize
283 Process Secure Boot Mode variable.
285 Caution: This function may receive untrusted input.
286 This function may be invoked in SMM mode, and datasize and data are external input.
287 This function will do basic validation, before parse the data.
288 This function will parse the authentication carefully to avoid security issues, like
289 buffer overflow, integer overflow.
290 This function will check attribute carefully to avoid authentication bypass.
292 @param[in] VariableName Name of Variable to be found.
293 @param[in] VendorGuid Variable vendor GUID.
294 @param[in] Data Data pointer.
295 @param[in] DataSize Size of Data found. If size is less than the
296 data, this value contains the required size.
297 @param[in] Attributes Attribute value of the variable
299 @return EFI_INVALID_PARAMETER Invalid parameter
300 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation
301 check carried out by the firmware.
302 @return EFI_WRITE_PROTECTED Variable is Read-Only.
303 @return EFI_SUCCESS Variable passed validation successfully.
307 ProcessSecureBootModeVar (
308 IN CHAR16
*VariableName
,
309 IN EFI_GUID
*VendorGuid
,
312 IN UINT32 Attributes OPTIONAL
316 Process variable with platform key for verification.
318 Caution: This function may receive untrusted input.
319 This function may be invoked in SMM mode, and datasize and data are external input.
320 This function will do basic validation, before parse the data.
321 This function will parse the authentication carefully to avoid security issues, like
322 buffer overflow, integer overflow.
323 This function will check attribute carefully to avoid authentication bypass.
325 @param[in] VariableName Name of Variable to be found.
326 @param[in] VendorGuid Variable vendor GUID.
327 @param[in] Data Data pointer.
328 @param[in] DataSize Size of Data found. If size is less than the
329 data, this value contains the required size.
330 @param[in] Attributes Attribute value of the variable
331 @param[in] IsPk Indicate whether it is to process pk.
333 @return EFI_INVALID_PARAMETER Invalid parameter.
334 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation.
335 check carried out by the firmware.
336 @return EFI_SUCCESS Variable passed validation successfully.
341 IN CHAR16
*VariableName
,
342 IN EFI_GUID
*VendorGuid
,
345 IN UINT32 Attributes OPTIONAL
,
350 Process variable with key exchange key for verification.
352 Caution: This function may receive untrusted input.
353 This function may be invoked in SMM mode, and datasize and data are external input.
354 This function will do basic validation, before parse the data.
355 This function will parse the authentication carefully to avoid security issues, like
356 buffer overflow, integer overflow.
357 This function will check attribute carefully to avoid authentication bypass.
359 @param[in] VariableName Name of Variable to be found.
360 @param[in] VendorGuid Variable vendor GUID.
361 @param[in] Data Data pointer.
362 @param[in] DataSize Size of Data found. If size is less than the
363 data, this value contains the required size.
364 @param[in] Attributes Attribute value of the variable.
366 @return EFI_INVALID_PARAMETER Invalid parameter.
367 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation
368 check carried out by the firmware.
369 @return EFI_SUCCESS Variable pass validation successfully.
374 IN CHAR16
*VariableName
,
375 IN EFI_GUID
*VendorGuid
,
378 IN UINT32 Attributes OPTIONAL
382 Process variable with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS/EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set
384 Caution: This function may receive untrusted input.
385 This function may be invoked in SMM mode, and datasize and data are external input.
386 This function will do basic validation, before parse the data.
387 This function will parse the authentication carefully to avoid security issues, like
388 buffer overflow, integer overflow.
389 This function will check attribute carefully to avoid authentication bypass.
391 @param[in] VariableName Name of the variable.
392 @param[in] VendorGuid Variable vendor GUID.
393 @param[in] Data Data pointer.
394 @param[in] DataSize Size of Data.
395 @param[in] Attributes Attribute value of the variable.
397 @return EFI_INVALID_PARAMETER Invalid parameter.
398 @return EFI_WRITE_PROTECTED Variable is write-protected and needs authentication with
399 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS set.
400 @return EFI_OUT_OF_RESOURCES The Database to save the public key is full.
401 @return EFI_SECURITY_VIOLATION The variable is with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
402 set, but the AuthInfo does NOT pass the validation
403 check carried out by the firmware.
404 @return EFI_SUCCESS Variable is not write-protected or pass validation successfully.
409 IN CHAR16
*VariableName
,
410 IN EFI_GUID
*VendorGuid
,
413 IN UINT32 Attributes OPTIONAL
417 Finds variable in storage blocks of volatile and non-volatile storage areas.
419 This code finds variable in storage blocks of volatile and non-volatile storage areas.
420 If VariableName is an empty string, then we just return the first
421 qualified variable without comparing VariableName and VendorGuid.
423 @param[in] VariableName Name of the variable to be found.
424 @param[in] VendorGuid Variable vendor GUID to be found.
425 @param[out] Data Pointer to data address.
426 @param[out] DataSize Pointer to data size.
428 @retval EFI_INVALID_PARAMETER If VariableName is not an empty string,
429 while VendorGuid is NULL.
430 @retval EFI_SUCCESS Variable successfully found.
431 @retval EFI_NOT_FOUND Variable not found
435 AuthServiceInternalFindVariable (
436 IN CHAR16
*VariableName
,
437 IN EFI_GUID
*VendorGuid
,
443 Update the variable region with Variable information.
445 @param[in] VariableName Name of variable.
446 @param[in] VendorGuid Guid of variable.
447 @param[in] Data Data pointer.
448 @param[in] DataSize Size of Data.
449 @param[in] Attributes Attribute value of the variable.
451 @retval EFI_SUCCESS The update operation is success.
452 @retval EFI_INVALID_PARAMETER Invalid parameter.
453 @retval EFI_WRITE_PROTECTED Variable is write-protected.
454 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
458 AuthServiceInternalUpdateVariable (
459 IN CHAR16
*VariableName
,
460 IN EFI_GUID
*VendorGuid
,
467 Update the variable region with Variable information.
469 @param[in] VariableName Name of variable.
470 @param[in] VendorGuid Guid of variable.
471 @param[in] Data Data pointer.
472 @param[in] DataSize Size of Data.
473 @param[in] Attributes Attribute value of the variable.
474 @param[in] KeyIndex Index of associated public key.
475 @param[in] MonotonicCount Value of associated monotonic count.
477 @retval EFI_SUCCESS The update operation is success.
478 @retval EFI_INVALID_PARAMETER Invalid parameter.
479 @retval EFI_WRITE_PROTECTED Variable is write-protected.
480 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
484 AuthServiceInternalUpdateVariableWithMonotonicCount (
485 IN CHAR16
*VariableName
,
486 IN EFI_GUID
*VendorGuid
,
489 IN UINT32 Attributes
,
491 IN UINT64 MonotonicCount
495 Update the variable region with Variable information.
497 @param[in] VariableName Name of variable.
498 @param[in] VendorGuid Guid of variable.
499 @param[in] Data Data pointer.
500 @param[in] DataSize Size of Data.
501 @param[in] Attributes Attribute value of the variable.
502 @param[in] TimeStamp Value of associated TimeStamp.
504 @retval EFI_SUCCESS The update operation is success.
505 @retval EFI_INVALID_PARAMETER Invalid parameter.
506 @retval EFI_WRITE_PROTECTED Variable is write-protected.
507 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
511 AuthServiceInternalUpdateVariableWithTimeStamp (
512 IN CHAR16
*VariableName
,
513 IN EFI_GUID
*VendorGuid
,
516 IN UINT32 Attributes
,
517 IN EFI_TIME
*TimeStamp