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_H_
27 #define _AUTHSERVICE_H_
29 #define EFI_CERT_TYPE_RSA2048_SHA256_SIZE 256
30 #define EFI_CERT_TYPE_RSA2048_SIZE 256
33 /// Size of AuthInfo prior to the data payload.
35 #define AUTHINFO_SIZE ((OFFSET_OF (EFI_VARIABLE_AUTHENTICATION, AuthInfo)) + \
36 (OFFSET_OF (WIN_CERTIFICATE_UEFI_GUID, CertData)) + \
37 sizeof (EFI_CERT_BLOCK_RSA_2048_SHA256))
39 #define AUTHINFO2_SIZE(VarAuth2) ((OFFSET_OF (EFI_VARIABLE_AUTHENTICATION_2, AuthInfo)) + \
40 (UINTN) ((EFI_VARIABLE_AUTHENTICATION_2 *) (VarAuth2))->AuthInfo.Hdr.dwLength)
42 #define OFFSET_OF_AUTHINFO2_CERT_DATA ((OFFSET_OF (EFI_VARIABLE_AUTHENTICATION_2, AuthInfo)) + \
43 (OFFSET_OF (WIN_CERTIFICATE_UEFI_GUID, CertData)))
46 /// "AuthVarKeyDatabase" variable for the Public Key store.
48 #define AUTHVAR_KEYDB_NAME L"AuthVarKeyDatabase"
51 /// "certdb" variable stores the signer's certificates for non PK/KEK/DB/DBX
52 /// variables with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set.
55 #define EFI_CERT_DB_NAME L"certdb"
58 /// Struct to record signature requirement defined by UEFI spec.
59 /// For SigHeaderSize and SigDataSize, ((UINT32) ~0) means NO exact length requirement for this field.
63 // Expected SignatureHeader size in Bytes.
65 // Expected SignatureData size in Bytes.
82 /// CHAR16 VariableName[NameSize];
83 /// UINT8 CertData[CertDataSize];
88 Process variable with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS/EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set.
90 Caution: This function may receive untrusted input.
91 This function may be invoked in SMM mode, and datasize and data are external input.
92 This function will do basic validation, before parse the data.
93 This function will parse the authentication carefully to avoid security issues, like
94 buffer overflow, integer overflow.
95 This function will check attribute carefully to avoid authentication bypass.
97 @param[in] VariableName Name of Variable to be found.
98 @param[in] VendorGuid Variable vendor GUID.
100 @param[in] Data Data pointer.
101 @param[in] DataSize Size of Data found. If size is less than the
102 data, this value contains the required size.
103 @param[in] Variable The variable information which is used to keep track of variable usage.
104 @param[in] Attributes Attribute value of the variable.
106 @return EFI_INVALID_PARAMETER Invalid parameter
107 @return EFI_WRITE_PROTECTED Variable is write-protected and needs authentication with
108 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS set.
109 @return EFI_SECURITY_VIOLATION The variable is with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
110 set, but the AuthInfo does NOT pass the validation
111 check carried out by the firmware.
112 @return EFI_SUCCESS Variable is not write-protected, or passed validation successfully.
117 IN CHAR16
*VariableName
,
118 IN EFI_GUID
*VendorGuid
,
121 IN VARIABLE_POINTER_TRACK
*Variable
,
126 Update platform mode.
128 @param[in] Mode SETUP_MODE or USER_MODE.
130 @return EFI_INVALID_PARAMETER Invalid parameter.
131 @return EFI_SUCCESS Update platform mode successfully.
140 Initializes for authenticated varibale service.
142 @param[in] MaxAuthVariableSize Reflect the overhead associated with the saving
143 of a single EFI authenticated variable with the exception
144 of the overhead associated with the length
145 of the string name of the EFI variable.
147 @retval EFI_SUCCESS Function successfully executed.
148 @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resources.
152 AutenticatedVariableServiceInitialize (
153 IN UINTN MaxAuthVariableSize
157 Initializes for cryptlib service before use, include register algrithm and allocate scratch.
161 CryptLibraryInitialize (
166 Check input data form to make sure it is a valid EFI_SIGNATURE_LIST for PK/KEK variable.
168 @param[in] VariableName Name of Variable to be check.
169 @param[in] VendorGuid Variable vendor GUID.
170 @param[in] Data Point to the variable data to be checked.
171 @param[in] DataSize Size of Data.
173 @return EFI_INVALID_PARAMETER Invalid signature list format.
174 @return EFI_SUCCESS Passed signature list format check successfully.
178 CheckSignatureListFormat(
179 IN CHAR16
*VariableName
,
180 IN EFI_GUID
*VendorGuid
,
186 Process variable with platform key for verification.
188 Caution: This function may receive untrusted input.
189 This function may be invoked in SMM mode, and datasize and data are external input.
190 This function will do basic validation, before parse the data.
191 This function will parse the authentication carefully to avoid security issues, like
192 buffer overflow, integer overflow.
193 This function will check attribute carefully to avoid authentication bypass.
195 @param[in] VariableName Name of Variable to be found.
196 @param[in] VendorGuid Variable vendor GUID.
197 @param[in] Data Data pointer.
198 @param[in] DataSize Size of Data found. If size is less than the
199 data, this value contains the required size.
200 @param[in] Variable The variable information which is used to keep track of variable usage.
201 @param[in] Attributes Attribute value of the variable.
202 @param[in] IsPk Indicate whether it is to process pk.
204 @return EFI_INVALID_PARAMETER Invalid parameter
205 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation
206 check carried out by the firmware.
207 @return EFI_SUCCESS Variable passed validation successfully.
212 IN CHAR16
*VariableName
,
213 IN EFI_GUID
*VendorGuid
,
216 IN VARIABLE_POINTER_TRACK
*Variable
,
217 IN UINT32 Attributes OPTIONAL
,
222 Process variable with key exchange key for verification.
224 Caution: This function may receive untrusted input.
225 This function may be invoked in SMM mode, and datasize and data are external input.
226 This function will do basic validation, before parse the data.
227 This function will parse the authentication carefully to avoid security issues, like
228 buffer overflow, integer overflow.
229 This function will check attribute carefully to avoid authentication bypass.
231 @param[in] VariableName Name of Variable to be found.
232 @param[in] VendorGuid Variable vendor GUID.
233 @param[in] Data Data pointer.
234 @param[in] DataSize Size of Data found. If size is less than the
235 data, this value contains the required size.
236 @param[in] Variable The variable information that is used to keep track of variable usage.
237 @param[in] Attributes Attribute value of the variable.
239 @return EFI_INVALID_PARAMETER Invalid parameter.
240 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation
241 check carried out by the firmware.
242 @return EFI_SUCCESS Variable passed validation successfully.
247 IN CHAR16
*VariableName
,
248 IN EFI_GUID
*VendorGuid
,
251 IN VARIABLE_POINTER_TRACK
*Variable
,
252 IN UINT32 Attributes OPTIONAL
256 Merge two buffers which formatted as EFI_SIGNATURE_LIST. Only the new EFI_SIGNATURE_DATA
257 will be appended to the original EFI_SIGNATURE_LIST, duplicate EFI_SIGNATURE_DATA
260 @param[in, out] Data Pointer to original EFI_SIGNATURE_LIST.
261 @param[in] DataSize Size of Data buffer.
262 @param[in] FreeBufSize Size of free data buffer
263 @param[in] NewData Pointer to new EFI_SIGNATURE_LIST to be appended.
264 @param[in] NewDataSize Size of NewData buffer.
265 @param[out] MergedBufSize Size of the merged buffer
267 @return EFI_BUFFER_TOO_SMALL if input Data buffer overflowed
271 AppendSignatureList (
274 IN UINTN FreeBufSize
,
276 IN UINTN NewDataSize
,
277 OUT UINTN
*MergedBufSize
281 Compare two EFI_TIME data.
284 @param FirstTime A pointer to the first EFI_TIME data.
285 @param SecondTime A pointer to the second EFI_TIME data.
287 @retval TRUE The FirstTime is not later than the SecondTime.
288 @retval FALSE The FirstTime is later than the SecondTime.
293 IN EFI_TIME
*FirstTime
,
294 IN EFI_TIME
*SecondTime
298 Delete matching signer's certificates when deleting common authenticated
299 variable by corresponding VariableName and VendorGuid from "certdb".
301 @param[in] VariableName Name of authenticated Variable.
302 @param[in] VendorGuid Vendor GUID of authenticated Variable.
304 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
305 @retval EFI_NOT_FOUND Fail to find "certdb" or matching certs.
306 @retval EFI_OUT_OF_RESOURCES The operation is failed due to lack of resources.
307 @retval EFI_SUCCESS The operation is completed successfully.
312 IN CHAR16
*VariableName
,
313 IN EFI_GUID
*VendorGuid
317 Process variable with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set
319 Caution: This function may receive untrusted input.
320 This function may be invoked in SMM mode, and datasize and data are external input.
321 This function will do basic validation, before parse the data.
322 This function will parse the authentication carefully to avoid security issues, like
323 buffer overflow, integer overflow.
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] Variable The variable information which is used to keep track of variable usage.
331 @param[in] Attributes Attribute value of the variable.
332 @param[in] AuthVarType Verify against PK or KEK database or private database.
333 @param[out] VarDel Delete the variable or not.
335 @retval EFI_INVALID_PARAMETER Invalid parameter.
336 @retval EFI_SECURITY_VIOLATION The variable does NOT pass the validation
337 check carried out by the firmware.
338 @retval EFI_OUT_OF_RESOURCES Failed to process variable due to lack
340 @retval EFI_SUCCESS Variable pass validation successfully.
344 VerifyTimeBasedPayload (
345 IN CHAR16
*VariableName
,
346 IN EFI_GUID
*VendorGuid
,
349 IN VARIABLE_POINTER_TRACK
*Variable
,
350 IN UINT32 Attributes
,
351 IN AUTHVAR_TYPE AuthVarType
,
355 extern UINT8
*mPubKeyStore
;
356 extern UINT8
*mCertDbStore
;
357 extern UINT32 mPubKeyNumber
;
358 extern VOID
*mHashCtx
;