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 @retval EFI_SUCCESS Function successfully executed.
143 @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource.
147 AutenticatedVariableServiceInitialize (
152 Initializes for cryptlib service before use, include register algrithm and allocate scratch.
156 CryptLibraryInitialize (
161 Check input data form to make sure it is a valid EFI_SIGNATURE_LIST for PK/KEK variable.
163 @param[in] VariableName Name of Variable to be check.
164 @param[in] VendorGuid Variable vendor GUID.
165 @param[in] Data Point to the variable data to be checked.
166 @param[in] DataSize Size of Data.
168 @return EFI_INVALID_PARAMETER Invalid signature list format.
169 @return EFI_SUCCESS Passed signature list format check successfully.
173 CheckSignatureListFormat(
174 IN CHAR16
*VariableName
,
175 IN EFI_GUID
*VendorGuid
,
181 Process variable with platform key for verification.
183 Caution: This function may receive untrusted input.
184 This function may be invoked in SMM mode, and datasize and data are external input.
185 This function will do basic validation, before parse the data.
186 This function will parse the authentication carefully to avoid security issues, like
187 buffer overflow, integer overflow.
188 This function will check attribute carefully to avoid authentication bypass.
190 @param[in] VariableName Name of Variable to be found.
191 @param[in] VendorGuid Variable vendor GUID.
192 @param[in] Data Data pointer.
193 @param[in] DataSize Size of Data found. If size is less than the
194 data, this value contains the required size.
195 @param[in] Variable The variable information which is used to keep track of variable usage.
196 @param[in] Attributes Attribute value of the variable.
197 @param[in] IsPk Indicate whether it is to process pk.
199 @return EFI_INVALID_PARAMETER Invalid parameter
200 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation
201 check carried out by the firmware.
202 @return EFI_SUCCESS Variable passed validation successfully.
207 IN CHAR16
*VariableName
,
208 IN EFI_GUID
*VendorGuid
,
211 IN VARIABLE_POINTER_TRACK
*Variable
,
212 IN UINT32 Attributes OPTIONAL
,
217 Process variable with key exchange key for verification.
219 Caution: This function may receive untrusted input.
220 This function may be invoked in SMM mode, and datasize and data are external input.
221 This function will do basic validation, before parse the data.
222 This function will parse the authentication carefully to avoid security issues, like
223 buffer overflow, integer overflow.
224 This function will check attribute carefully to avoid authentication bypass.
226 @param[in] VariableName Name of Variable to be found.
227 @param[in] VendorGuid Variable vendor GUID.
228 @param[in] Data Data pointer.
229 @param[in] DataSize Size of Data found. If size is less than the
230 data, this value contains the required size.
231 @param[in] Variable The variable information that is used to keep track of variable usage.
232 @param[in] Attributes Attribute value of the variable.
234 @return EFI_INVALID_PARAMETER Invalid parameter.
235 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation
236 check carried out by the firmware.
237 @return EFI_SUCCESS Variable passed validation successfully.
242 IN CHAR16
*VariableName
,
243 IN EFI_GUID
*VendorGuid
,
246 IN VARIABLE_POINTER_TRACK
*Variable
,
247 IN UINT32 Attributes OPTIONAL
251 Merge two buffers which formatted as EFI_SIGNATURE_LIST. Only the new EFI_SIGNATURE_DATA
252 will be appended to the original EFI_SIGNATURE_LIST, duplicate EFI_SIGNATURE_DATA
255 @param[in, out] Data Pointer to original EFI_SIGNATURE_LIST.
256 @param[in] DataSize Size of Data buffer.
257 @param[in] FreeBufSize Size of free data buffer
258 @param[in] NewData Pointer to new EFI_SIGNATURE_LIST to be appended.
259 @param[in] NewDataSize Size of NewData buffer.
260 @param[out] MergedBufSize Size of the merged buffer
262 @return EFI_BUFFER_TOO_SMALL if input Data buffer overflowed
266 AppendSignatureList (
269 IN UINTN FreeBufSize
,
271 IN UINTN NewDataSize
,
272 OUT UINTN
*MergedBufSize
276 Compare two EFI_TIME data.
279 @param FirstTime A pointer to the first EFI_TIME data.
280 @param SecondTime A pointer to the second EFI_TIME data.
282 @retval TRUE The FirstTime is not later than the SecondTime.
283 @retval FALSE The FirstTime is later than the SecondTime.
288 IN EFI_TIME
*FirstTime
,
289 IN EFI_TIME
*SecondTime
293 Delete matching signer's certificates when deleting common authenticated
294 variable by corresponding VariableName and VendorGuid from "certdb".
296 @param[in] VariableName Name of authenticated Variable.
297 @param[in] VendorGuid Vendor GUID of authenticated Variable.
299 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
300 @retval EFI_NOT_FOUND Fail to find "certdb" or matching certs.
301 @retval EFI_OUT_OF_RESOURCES The operation is failed due to lack of resources.
302 @retval EFI_SUCCESS The operation is completed successfully.
307 IN CHAR16
*VariableName
,
308 IN EFI_GUID
*VendorGuid
312 Process variable with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set
314 Caution: This function may receive untrusted input.
315 This function may be invoked in SMM mode, and datasize and data are external input.
316 This function will do basic validation, before parse the data.
317 This function will parse the authentication carefully to avoid security issues, like
318 buffer overflow, integer overflow.
320 @param[in] VariableName Name of Variable to be found.
321 @param[in] VendorGuid Variable vendor GUID.
322 @param[in] Data Data pointer.
323 @param[in] DataSize Size of Data found. If size is less than the
324 data, this value contains the required size.
325 @param[in] Variable The variable information which is used to keep track of variable usage.
326 @param[in] Attributes Attribute value of the variable.
327 @param[in] AuthVarType Verify against PK or KEK database or private database.
328 @param[out] VarDel Delete the variable or not.
330 @retval EFI_INVALID_PARAMETER Invalid parameter.
331 @retval EFI_SECURITY_VIOLATION The variable does NOT pass the validation
332 check carried out by the firmware.
333 @retval EFI_OUT_OF_RESOURCES Failed to process variable due to lack
335 @retval EFI_SUCCESS Variable pass validation successfully.
339 VerifyTimeBasedPayload (
340 IN CHAR16
*VariableName
,
341 IN EFI_GUID
*VendorGuid
,
344 IN VARIABLE_POINTER_TRACK
*Variable
,
345 IN UINT32 Attributes
,
346 IN AUTHVAR_TYPE AuthVarType
,
350 extern UINT8
*mPubKeyStore
;
351 extern UINT8
*mCertDbStore
;
352 extern UINT32 mPubKeyNumber
;
353 extern VOID
*mHashCtx
;
354 extern UINT8
*mSerializationRuntimeBuffer
;