2 The internal header file includes the common header files, defines
3 internal structure and functions used by AuthService module.
5 Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #ifndef _AUTHSERVICE_H_
17 #define _AUTHSERVICE_H_
19 #define EFI_CERT_TYPE_RSA2048_SHA256_SIZE 256
20 #define EFI_CERT_TYPE_RSA2048_SIZE 256
23 /// Size of AuthInfo prior to the data payload.
25 #define AUTHINFO_SIZE ((OFFSET_OF (EFI_VARIABLE_AUTHENTICATION, AuthInfo)) + \
26 (OFFSET_OF (WIN_CERTIFICATE_UEFI_GUID, CertData)) + \
27 sizeof (EFI_CERT_BLOCK_RSA_2048_SHA256))
29 #define AUTHINFO2_SIZE(VarAuth2) ((OFFSET_OF (EFI_VARIABLE_AUTHENTICATION_2, AuthInfo)) + \
30 (UINTN) ((EFI_VARIABLE_AUTHENTICATION_2 *) (VarAuth2))->AuthInfo.Hdr.dwLength)
32 #define OFFSET_OF_AUTHINFO2_CERT_DATA ((OFFSET_OF (EFI_VARIABLE_AUTHENTICATION_2, AuthInfo)) + \
33 (OFFSET_OF (WIN_CERTIFICATE_UEFI_GUID, CertData)))
36 /// "AuthVarKeyDatabase" variable for the Public Key store.
38 #define AUTHVAR_KEYDB_NAME L"AuthVarKeyDatabase"
41 /// Max size of public key database, restricted by max individal EFI varible size, exclude variable header and name size.
43 #define MAX_KEYDB_SIZE (FixedPcdGet32 (PcdMaxVariableSize) - sizeof (VARIABLE_HEADER) - sizeof (AUTHVAR_KEYDB_NAME))
44 #define MAX_KEY_NUM (MAX_KEYDB_SIZE / EFI_CERT_TYPE_RSA2048_SIZE)
47 /// "certdb" variable stores the signer's certificates for non PK/KEK/DB/DBX
48 /// variables with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set.
51 #define EFI_CERT_DB_NAME L"certdb"
52 #define MAX_CERTDB_SIZE (FixedPcdGet32 (PcdMaxVariableSize) - sizeof (VARIABLE_HEADER) - sizeof (EFI_CERT_DB_NAME))
55 /// Struct to record signature requirement defined by UEFI spec.
56 /// For SigHeaderSize and SigDataSize, ((UINT32) ~0) means NO exact length requirement for this field.
60 // Expected SignatureHeader size in Bytes.
62 // Expected SignatureData size in Bytes.
79 /// CHAR16 VariableName[NameSize];
80 /// UINT8 CertData[CertDataSize];
85 Process variable with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS/EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set.
87 Caution: This function may receive untrusted input.
88 This function may be invoked in SMM mode, and datasize and data are external input.
89 This function will do basic validation, before parse the data.
90 This function will parse the authentication carefully to avoid security issues, like
91 buffer overflow, integer overflow.
92 This function will check attribute carefully to avoid authentication bypass.
94 @param[in] VariableName Name of Variable to be found.
95 @param[in] VendorGuid Variable vendor GUID.
97 @param[in] Data Data pointer.
98 @param[in] DataSize Size of Data found. If size is less than the
99 data, this value contains the required size.
100 @param[in] Variable The variable information which is used to keep track of variable usage.
101 @param[in] Attributes Attribute value of the variable.
103 @return EFI_INVALID_PARAMETER Invalid parameter
104 @return EFI_WRITE_PROTECTED Variable is write-protected and needs authentication with
105 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS set.
106 @return EFI_SECURITY_VIOLATION The variable is with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
107 set, but the AuthInfo does NOT pass the validation
108 check carried out by the firmware.
109 @return EFI_SUCCESS Variable is not write-protected, or passed validation successfully.
114 IN CHAR16
*VariableName
,
115 IN EFI_GUID
*VendorGuid
,
118 IN VARIABLE_POINTER_TRACK
*Variable
,
123 Update platform mode.
125 @param[in] Mode SETUP_MODE or USER_MODE.
127 @return EFI_INVALID_PARAMETER Invalid parameter.
128 @return EFI_SUCCESS Update platform mode successfully.
137 Initializes for authenticated varibale service.
139 @retval EFI_SUCCESS Function successfully executed.
140 @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource.
144 AutenticatedVariableServiceInitialize (
149 Initializes for cryptlib service before use, include register algrithm and allocate scratch.
153 CryptLibraryInitialize (
158 Check input data form to make sure it is a valid EFI_SIGNATURE_LIST for PK/KEK variable.
160 @param[in] VariableName Name of Variable to be check.
161 @param[in] VendorGuid Variable vendor GUID.
162 @param[in] Data Point to the variable data to be checked.
163 @param[in] DataSize Size of Data.
165 @return EFI_INVALID_PARAMETER Invalid signature list format.
166 @return EFI_SUCCESS Passed signature list format check successfully.
170 CheckSignatureListFormat(
171 IN CHAR16
*VariableName
,
172 IN EFI_GUID
*VendorGuid
,
178 Process variable with platform key for verification.
180 Caution: This function may receive untrusted input.
181 This function may be invoked in SMM mode, and datasize and data are external input.
182 This function will do basic validation, before parse the data.
183 This function will parse the authentication carefully to avoid security issues, like
184 buffer overflow, integer overflow.
185 This function will check attribute carefully to avoid authentication bypass.
187 @param[in] VariableName Name of Variable to be found.
188 @param[in] VendorGuid Variable vendor GUID.
189 @param[in] Data Data pointer.
190 @param[in] DataSize Size of Data found. If size is less than the
191 data, this value contains the required size.
192 @param[in] Variable The variable information which is used to keep track of variable usage.
193 @param[in] Attributes Attribute value of the variable.
194 @param[in] IsPk Indicate whether it is to process pk.
196 @return EFI_INVALID_PARAMETER Invalid parameter
197 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation
198 check carried out by the firmware.
199 @return EFI_SUCCESS Variable passed validation successfully.
204 IN CHAR16
*VariableName
,
205 IN EFI_GUID
*VendorGuid
,
208 IN VARIABLE_POINTER_TRACK
*Variable
,
209 IN UINT32 Attributes OPTIONAL
,
214 Process variable with key exchange key for verification.
216 Caution: This function may receive untrusted input.
217 This function may be invoked in SMM mode, and datasize and data are external input.
218 This function will do basic validation, before parse the data.
219 This function will parse the authentication carefully to avoid security issues, like
220 buffer overflow, integer overflow.
221 This function will check attribute carefully to avoid authentication bypass.
223 @param[in] VariableName Name of Variable to be found.
224 @param[in] VendorGuid Variable vendor GUID.
225 @param[in] Data Data pointer.
226 @param[in] DataSize Size of Data found. If size is less than the
227 data, this value contains the required size.
228 @param[in] Variable The variable information that is used to keep track of variable usage.
229 @param[in] Attributes Attribute value of the variable.
231 @return EFI_INVALID_PARAMETER Invalid parameter.
232 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation
233 check carried out by the firmware.
234 @return EFI_SUCCESS Variable passed validation successfully.
239 IN CHAR16
*VariableName
,
240 IN EFI_GUID
*VendorGuid
,
243 IN VARIABLE_POINTER_TRACK
*Variable
,
244 IN UINT32 Attributes OPTIONAL
248 Merge two buffers which formatted as EFI_SIGNATURE_LIST. Only the new EFI_SIGNATURE_DATA
249 will be appended to the original EFI_SIGNATURE_LIST, duplicate EFI_SIGNATURE_DATA
252 @param[in, out] Data Pointer to original EFI_SIGNATURE_LIST.
253 @param[in] DataSize Size of Data buffer.
254 @param[in] FreeBufSize Size of free data buffer
255 @param[in] NewData Pointer to new EFI_SIGNATURE_LIST to be appended.
256 @param[in] NewDataSize Size of NewData buffer.
257 @param[out] MergedBufSize Size of the merged buffer
259 @return EFI_BUFFER_TOO_SMALL if input Data buffer overflowed
263 AppendSignatureList (
266 IN UINTN FreeBufSize
,
268 IN UINTN NewDataSize
,
269 OUT UINTN
*MergedBufSize
273 Compare two EFI_TIME data.
276 @param FirstTime A pointer to the first EFI_TIME data.
277 @param SecondTime A pointer to the second EFI_TIME data.
279 @retval TRUE The FirstTime is not later than the SecondTime.
280 @retval FALSE The FirstTime is later than the SecondTime.
285 IN EFI_TIME
*FirstTime
,
286 IN EFI_TIME
*SecondTime
291 Process variable with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set
293 Caution: This function may receive untrusted input.
294 This function may be invoked in SMM mode, and datasize and data are external input.
295 This function will do basic validation, before parse the data.
296 This function will parse the authentication carefully to avoid security issues, like
297 buffer overflow, integer overflow.
299 @param[in] VariableName Name of Variable to be found.
300 @param[in] VendorGuid Variable vendor GUID.
301 @param[in] Data Data pointer.
302 @param[in] DataSize Size of Data found. If size is less than the
303 data, this value contains the required size.
304 @param[in] Variable The variable information which is used to keep track of variable usage.
305 @param[in] Attributes Attribute value of the variable.
306 @param[in] AuthVarType Verify against PK or KEK database or private database.
307 @param[out] VarDel Delete the variable or not.
309 @retval EFI_INVALID_PARAMETER Invalid parameter.
310 @retval EFI_SECURITY_VIOLATION The variable does NOT pass the validation
311 check carried out by the firmware.
312 @retval EFI_OUT_OF_RESOURCES Failed to process variable due to lack
314 @retval EFI_SUCCESS Variable pass validation successfully.
318 VerifyTimeBasedPayload (
319 IN CHAR16
*VariableName
,
320 IN EFI_GUID
*VendorGuid
,
323 IN VARIABLE_POINTER_TRACK
*Variable
,
324 IN UINT32 Attributes
,
325 IN AUTHVAR_TYPE AuthVarType
,
329 extern UINT8 mPubKeyStore
[MAX_KEYDB_SIZE
];
330 extern UINT32 mPubKeyNumber
;
331 extern VOID
*mHashCtx
;
332 extern VOID
*mStorageArea
;
333 extern UINT8
*mSerializationRuntimeBuffer
;