]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/VariableAuthenticated/RuntimeDxe/AuthService.h
1. Initialize certdb variable with correct value of list size.
[mirror_edk2.git] / SecurityPkg / VariableAuthenticated / RuntimeDxe / AuthService.h
CommitLineData
0c18794e 1/** @file\r
2 The internal header file includes the common header files, defines\r
3 internal structure and functions used by AuthService module.\r
4\r
ed47ae02 5Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
2d3fb919 6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
0c18794e 9http://opensource.org/licenses/bsd-license.php\r
10\r
2d3fb919 11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
0c18794e 12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#ifndef _AUTHSERVICE_H_\r
17#define _AUTHSERVICE_H_\r
18\r
19#define EFI_CERT_TYPE_RSA2048_SHA256_SIZE 256\r
20#define EFI_CERT_TYPE_RSA2048_SIZE 256\r
21\r
22///\r
2d3fb919 23/// Size of AuthInfo prior to the data payload.\r
0c18794e 24///\r
2d3fb919 25#define AUTHINFO_SIZE ((OFFSET_OF (EFI_VARIABLE_AUTHENTICATION, AuthInfo)) + \\r
26 (OFFSET_OF (WIN_CERTIFICATE_UEFI_GUID, CertData)) + \\r
27 sizeof (EFI_CERT_BLOCK_RSA_2048_SHA256))\r
28\r
29#define AUTHINFO2_SIZE(VarAuth2) ((OFFSET_OF (EFI_VARIABLE_AUTHENTICATION_2, AuthInfo)) + \\r
30 (UINTN) ((EFI_VARIABLE_AUTHENTICATION_2 *) (VarAuth2))->AuthInfo.Hdr.dwLength)\r
31\r
32#define OFFSET_OF_AUTHINFO2_CERT_DATA ((OFFSET_OF (EFI_VARIABLE_AUTHENTICATION_2, AuthInfo)) + \\r
33 (OFFSET_OF (WIN_CERTIFICATE_UEFI_GUID, CertData)))\r
0c18794e 34\r
35///\r
36/// "AuthVarKeyDatabase" variable for the Public Key store.\r
37///\r
38#define AUTHVAR_KEYDB_NAME L"AuthVarKeyDatabase"\r
0c18794e 39\r
40///\r
41/// Max size of public key database, restricted by max individal EFI varible size, exclude variable header and name size.\r
42///\r
f6e23353 43#define MAX_KEYDB_SIZE (FixedPcdGet32 (PcdMaxVariableSize) - sizeof (VARIABLE_HEADER) - sizeof (AUTHVAR_KEYDB_NAME))\r
0c18794e 44#define MAX_KEY_NUM (MAX_KEYDB_SIZE / EFI_CERT_TYPE_RSA2048_SIZE)\r
45\r
f6e23353 46///\r
47/// "certdb" variable stores the signer's certificates for non PK/KEK/DB/DBX\r
48/// variables with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set.\r
49/// \r
50///\r
51#define EFI_CERT_DB_NAME L"certdb"\r
52#define MAX_CERTDB_SIZE (FixedPcdGet32 (PcdMaxVariableSize) - sizeof (VARIABLE_HEADER) - sizeof (EFI_CERT_DB_NAME))\r
53\r
54extern EFI_GUID gEfiCertDbGuid;\r
55\r
d912bad7 56///\r
57/// Struct to record signature requirement defined by UEFI spec.\r
58/// For SigHeaderSize and SigDataSize, ((UINT32) ~0) means NO exact length requirement for this field.\r
59///\r
60typedef struct {\r
61 EFI_GUID SigType;\r
62 // Expected SignatureHeader size in Bytes.\r
63 UINT32 SigHeaderSize;\r
64 // Expected SignatureData size in Bytes.\r
65 UINT32 SigDataSize;\r
66} EFI_SIGNATURE_ITEM;\r
0c18794e 67\r
ed47ae02 68typedef enum {\r
69 AuthVarTypePk,\r
70 AuthVarTypeKek,\r
785d84ea 71 AuthVarTypePriv,\r
72 AuthVarTypePayload\r
ed47ae02 73} AUTHVAR_TYPE;\r
74\r
75#pragma pack(1)\r
76typedef struct {\r
77 EFI_GUID VendorGuid;\r
78 UINT32 CertNodeSize;\r
79 UINT32 NameSize;\r
80 UINT32 CertDataSize;\r
81 /// CHAR16 VariableName[NameSize];\r
82 /// UINT8 CertData[CertDataSize];\r
83} AUTH_CERT_DB_DATA;\r
84#pragma pack()\r
85\r
0c18794e 86/**\r
87 Process variable with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS/EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set.\r
88\r
dc204d5a
JY
89 Caution: This function may receive untrusted input.\r
90 This function may be invoked in SMM mode, and datasize and data are external input.\r
91 This function will do basic validation, before parse the data.\r
92 This function will parse the authentication carefully to avoid security issues, like\r
93 buffer overflow, integer overflow.\r
94 This function will check attribute carefully to avoid authentication bypass.\r
95\r
0c18794e 96 @param[in] VariableName Name of Variable to be found.\r
97 @param[in] VendorGuid Variable vendor GUID.\r
98\r
99 @param[in] Data Data pointer.\r
100 @param[in] DataSize Size of Data found. If size is less than the\r
101 data, this value contains the required size.\r
102 @param[in] Variable The variable information which is used to keep track of variable usage.\r
103 @param[in] Attributes Attribute value of the variable.\r
104\r
105 @return EFI_INVALID_PARAMETER Invalid parameter\r
106 @return EFI_WRITE_PROTECTED Variable is write-protected and needs authentication with\r
107 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS set.\r
108 @return EFI_SECURITY_VIOLATION The variable is with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS\r
2d3fb919 109 set, but the AuthInfo does NOT pass the validation\r
110 check carried out by the firmware.\r
0c18794e 111 @return EFI_SUCCESS Variable is not write-protected, or passed validation successfully.\r
112\r
113**/\r
114EFI_STATUS\r
115ProcessVariable (\r
116 IN CHAR16 *VariableName,\r
117 IN EFI_GUID *VendorGuid,\r
118 IN VOID *Data,\r
119 IN UINTN DataSize,\r
120 IN VARIABLE_POINTER_TRACK *Variable,\r
121 IN UINT32 Attributes\r
122 );\r
123\r
2d3fb919 124/**\r
125 Update platform mode.\r
126\r
127 @param[in] Mode SETUP_MODE or USER_MODE.\r
128\r
129 @return EFI_INVALID_PARAMETER Invalid parameter.\r
130 @return EFI_SUCCESS Update platform mode successfully.\r
131\r
132**/\r
133EFI_STATUS\r
134UpdatePlatformMode (\r
135 IN UINT32 Mode\r
136 );\r
137\r
0c18794e 138/**\r
139 Initializes for authenticated varibale service.\r
140\r
141 @retval EFI_SUCCESS Function successfully executed.\r
142 @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource.\r
143\r
144**/\r
145EFI_STATUS\r
146AutenticatedVariableServiceInitialize (\r
147 VOID\r
148 );\r
149\r
150/**\r
151 Initializes for cryptlib service before use, include register algrithm and allocate scratch.\r
152\r
153**/\r
154VOID\r
155CryptLibraryInitialize (\r
156 VOID\r
157 );\r
158\r
d912bad7 159/**\r
160 Check input data form to make sure it is a valid EFI_SIGNATURE_LIST for PK/KEK variable.\r
161\r
162 @param[in] VariableName Name of Variable to be check.\r
163 @param[in] VendorGuid Variable vendor GUID.\r
164 @param[in] Data Point to the variable data to be checked.\r
165 @param[in] DataSize Size of Data.\r
166\r
167 @return EFI_INVALID_PARAMETER Invalid signature list format.\r
168 @return EFI_SUCCESS Passed signature list format check successfully.\r
169 \r
170**/\r
171EFI_STATUS\r
172CheckSignatureListFormat(\r
173 IN CHAR16 *VariableName,\r
174 IN EFI_GUID *VendorGuid,\r
175 IN VOID *Data,\r
176 IN UINTN DataSize\r
177 );\r
178\r
0c18794e 179/**\r
180 Process variable with platform key for verification.\r
181\r
dc204d5a
JY
182 Caution: This function may receive untrusted input.\r
183 This function may be invoked in SMM mode, and datasize and data are external input.\r
184 This function will do basic validation, before parse the data.\r
185 This function will parse the authentication carefully to avoid security issues, like\r
186 buffer overflow, integer overflow.\r
187 This function will check attribute carefully to avoid authentication bypass.\r
188\r
0c18794e 189 @param[in] VariableName Name of Variable to be found.\r
190 @param[in] VendorGuid Variable vendor GUID.\r
191 @param[in] Data Data pointer.\r
192 @param[in] DataSize Size of Data found. If size is less than the\r
193 data, this value contains the required size.\r
194 @param[in] Variable The variable information which is used to keep track of variable usage.\r
195 @param[in] Attributes Attribute value of the variable.\r
196 @param[in] IsPk Indicate whether it is to process pk.\r
197\r
198 @return EFI_INVALID_PARAMETER Invalid parameter\r
2d3fb919 199 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation\r
200 check carried out by the firmware.\r
0c18794e 201 @return EFI_SUCCESS Variable passed validation successfully.\r
202\r
203**/\r
204EFI_STATUS\r
205ProcessVarWithPk (\r
206 IN CHAR16 *VariableName,\r
207 IN EFI_GUID *VendorGuid,\r
208 IN VOID *Data,\r
209 IN UINTN DataSize,\r
210 IN VARIABLE_POINTER_TRACK *Variable,\r
211 IN UINT32 Attributes OPTIONAL,\r
212 IN BOOLEAN IsPk\r
213 );\r
214\r
215/**\r
216 Process variable with key exchange key for verification.\r
217\r
dc204d5a
JY
218 Caution: This function may receive untrusted input.\r
219 This function may be invoked in SMM mode, and datasize and data are external input.\r
220 This function will do basic validation, before parse the data.\r
221 This function will parse the authentication carefully to avoid security issues, like\r
222 buffer overflow, integer overflow.\r
223 This function will check attribute carefully to avoid authentication bypass.\r
224\r
0c18794e 225 @param[in] VariableName Name of Variable to be found.\r
226 @param[in] VendorGuid Variable vendor GUID.\r
227 @param[in] Data Data pointer.\r
228 @param[in] DataSize Size of Data found. If size is less than the\r
229 data, this value contains the required size.\r
230 @param[in] Variable The variable information that is used to keep track of variable usage.\r
231 @param[in] Attributes Attribute value of the variable.\r
232\r
233 @return EFI_INVALID_PARAMETER Invalid parameter.\r
2d3fb919 234 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation\r
235 check carried out by the firmware.\r
0c18794e 236 @return EFI_SUCCESS Variable passed validation successfully.\r
237\r
238**/\r
239EFI_STATUS\r
240ProcessVarWithKek (\r
241 IN CHAR16 *VariableName,\r
242 IN EFI_GUID *VendorGuid,\r
243 IN VOID *Data,\r
244 IN UINTN DataSize,\r
245 IN VARIABLE_POINTER_TRACK *Variable,\r
246 IN UINT32 Attributes OPTIONAL\r
247 );\r
248\r
2d3fb919 249/**\r
250 Merge two buffers which formatted as EFI_SIGNATURE_LIST. Only the new EFI_SIGNATURE_DATA\r
251 will be appended to the original EFI_SIGNATURE_LIST, duplicate EFI_SIGNATURE_DATA\r
252 will be ignored.\r
253\r
254 @param[in, out] Data Pointer to original EFI_SIGNATURE_LIST.\r
255 @param[in] DataSize Size of Data buffer.\r
256 @param[in] NewData Pointer to new EFI_SIGNATURE_LIST to be appended.\r
257 @param[in] NewDataSize Size of NewData buffer.\r
258\r
259 @return Size of the merged buffer.\r
260\r
261**/\r
262UINTN\r
263AppendSignatureList (\r
264 IN OUT VOID *Data,\r
265 IN UINTN DataSize,\r
266 IN VOID *NewData,\r
267 IN UINTN NewDataSize\r
268 );\r
269\r
0c18794e 270/**\r
271 Compare two EFI_TIME data.\r
272\r
273\r
274 @param FirstTime A pointer to the first EFI_TIME data.\r
275 @param SecondTime A pointer to the second EFI_TIME data.\r
276\r
277 @retval TRUE The FirstTime is not later than the SecondTime.\r
278 @retval FALSE The FirstTime is later than the SecondTime.\r
279\r
280**/\r
281BOOLEAN\r
282CompareTimeStamp (\r
283 IN EFI_TIME *FirstTime,\r
284 IN EFI_TIME *SecondTime\r
285 );\r
286\r
287\r
288/**\r
289 Process variable with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set\r
290\r
dc204d5a
JY
291 Caution: This function may receive untrusted input.\r
292 This function may be invoked in SMM mode, and datasize and data are external input.\r
293 This function will do basic validation, before parse the data.\r
294 This function will parse the authentication carefully to avoid security issues, like\r
295 buffer overflow, integer overflow.\r
296\r
0c18794e 297 @param[in] VariableName Name of Variable to be found.\r
298 @param[in] VendorGuid Variable vendor GUID.\r
299 @param[in] Data Data pointer.\r
300 @param[in] DataSize Size of Data found. If size is less than the\r
301 data, this value contains the required size.\r
302 @param[in] Variable The variable information which is used to keep track of variable usage.\r
303 @param[in] Attributes Attribute value of the variable.\r
ed47ae02 304 @param[in] AuthVarType Verify against PK or KEK database or private database.\r
0c18794e 305 @param[out] VarDel Delete the variable or not.\r
306\r
307 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
2d3fb919 308 @retval EFI_SECURITY_VIOLATION The variable does NOT pass the validation\r
309 check carried out by the firmware.\r
0c18794e 310 @retval EFI_OUT_OF_RESOURCES Failed to process variable due to lack\r
311 of resources.\r
312 @retval EFI_SUCCESS Variable pass validation successfully.\r
313\r
314**/\r
315EFI_STATUS\r
316VerifyTimeBasedPayload (\r
317 IN CHAR16 *VariableName,\r
318 IN EFI_GUID *VendorGuid,\r
319 IN VOID *Data,\r
320 IN UINTN DataSize,\r
321 IN VARIABLE_POINTER_TRACK *Variable,\r
322 IN UINT32 Attributes,\r
ed47ae02 323 IN AUTHVAR_TYPE AuthVarType,\r
0c18794e 324 OUT BOOLEAN *VarDel\r
325 );\r
326\r
327extern UINT8 mPubKeyStore[MAX_KEYDB_SIZE];\r
328extern UINT32 mPubKeyNumber;\r
329extern VOID *mHashCtx;\r
330extern VOID *mStorageArea;\r
2d3fb919 331extern UINT8 *mSerializationRuntimeBuffer;\r
332\r
0c18794e 333#endif\r