]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/VariableAuthenticated/RuntimeDxe/AuthService.h
Update common authenticated variable (non PK/KEK/DB/DBX) support to comply with lates...
[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
39#define AUTHVAR_KEYDB_NAME_SIZE 38\r
40\r
41///\r
42/// Max size of public key database, restricted by max individal EFI varible size, exclude variable header and name size.\r
43///\r
44#define MAX_KEYDB_SIZE (FixedPcdGet32 (PcdMaxVariableSize) - sizeof (VARIABLE_HEADER) - AUTHVAR_KEYDB_NAME_SIZE)\r
45#define MAX_KEY_NUM (MAX_KEYDB_SIZE / EFI_CERT_TYPE_RSA2048_SIZE)\r
46\r
d912bad7 47///\r
48/// Struct to record signature requirement defined by UEFI spec.\r
49/// For SigHeaderSize and SigDataSize, ((UINT32) ~0) means NO exact length requirement for this field.\r
50///\r
51typedef struct {\r
52 EFI_GUID SigType;\r
53 // Expected SignatureHeader size in Bytes.\r
54 UINT32 SigHeaderSize;\r
55 // Expected SignatureData size in Bytes.\r
56 UINT32 SigDataSize;\r
57} EFI_SIGNATURE_ITEM;\r
0c18794e 58\r
ed47ae02 59typedef enum {\r
60 AuthVarTypePk,\r
61 AuthVarTypeKek,\r
62 AuthVarTypePriv\r
63} AUTHVAR_TYPE;\r
64\r
65#pragma pack(1)\r
66typedef struct {\r
67 EFI_GUID VendorGuid;\r
68 UINT32 CertNodeSize;\r
69 UINT32 NameSize;\r
70 UINT32 CertDataSize;\r
71 /// CHAR16 VariableName[NameSize];\r
72 /// UINT8 CertData[CertDataSize];\r
73} AUTH_CERT_DB_DATA;\r
74#pragma pack()\r
75\r
0c18794e 76/**\r
77 Process variable with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS/EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set.\r
78\r
79 @param[in] VariableName Name of Variable to be found.\r
80 @param[in] VendorGuid Variable vendor GUID.\r
81\r
82 @param[in] Data Data pointer.\r
83 @param[in] DataSize Size of Data found. If size is less than the\r
84 data, this value contains the required size.\r
85 @param[in] Variable The variable information which is used to keep track of variable usage.\r
86 @param[in] Attributes Attribute value of the variable.\r
87\r
88 @return EFI_INVALID_PARAMETER Invalid parameter\r
89 @return EFI_WRITE_PROTECTED Variable is write-protected and needs authentication with\r
90 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS set.\r
91 @return EFI_SECURITY_VIOLATION The variable is with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS\r
2d3fb919 92 set, but the AuthInfo does NOT pass the validation\r
93 check carried out by the firmware.\r
0c18794e 94 @return EFI_SUCCESS Variable is not write-protected, or passed validation successfully.\r
95\r
96**/\r
97EFI_STATUS\r
98ProcessVariable (\r
99 IN CHAR16 *VariableName,\r
100 IN EFI_GUID *VendorGuid,\r
101 IN VOID *Data,\r
102 IN UINTN DataSize,\r
103 IN VARIABLE_POINTER_TRACK *Variable,\r
104 IN UINT32 Attributes\r
105 );\r
106\r
2d3fb919 107/**\r
108 Update platform mode.\r
109\r
110 @param[in] Mode SETUP_MODE or USER_MODE.\r
111\r
112 @return EFI_INVALID_PARAMETER Invalid parameter.\r
113 @return EFI_SUCCESS Update platform mode successfully.\r
114\r
115**/\r
116EFI_STATUS\r
117UpdatePlatformMode (\r
118 IN UINT32 Mode\r
119 );\r
120\r
0c18794e 121/**\r
122 Initializes for authenticated varibale service.\r
123\r
124 @retval EFI_SUCCESS Function successfully executed.\r
125 @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource.\r
126\r
127**/\r
128EFI_STATUS\r
129AutenticatedVariableServiceInitialize (\r
130 VOID\r
131 );\r
132\r
133/**\r
134 Initializes for cryptlib service before use, include register algrithm and allocate scratch.\r
135\r
136**/\r
137VOID\r
138CryptLibraryInitialize (\r
139 VOID\r
140 );\r
141\r
d912bad7 142/**\r
143 Check input data form to make sure it is a valid EFI_SIGNATURE_LIST for PK/KEK variable.\r
144\r
145 @param[in] VariableName Name of Variable to be check.\r
146 @param[in] VendorGuid Variable vendor GUID.\r
147 @param[in] Data Point to the variable data to be checked.\r
148 @param[in] DataSize Size of Data.\r
149\r
150 @return EFI_INVALID_PARAMETER Invalid signature list format.\r
151 @return EFI_SUCCESS Passed signature list format check successfully.\r
152 \r
153**/\r
154EFI_STATUS\r
155CheckSignatureListFormat(\r
156 IN CHAR16 *VariableName,\r
157 IN EFI_GUID *VendorGuid,\r
158 IN VOID *Data,\r
159 IN UINTN DataSize\r
160 );\r
161\r
0c18794e 162/**\r
163 Process variable with platform key for verification.\r
164\r
165 @param[in] VariableName Name of Variable to be found.\r
166 @param[in] VendorGuid Variable vendor GUID.\r
167 @param[in] Data Data pointer.\r
168 @param[in] DataSize Size of Data found. If size is less than the\r
169 data, this value contains the required size.\r
170 @param[in] Variable The variable information which is used to keep track of variable usage.\r
171 @param[in] Attributes Attribute value of the variable.\r
172 @param[in] IsPk Indicate whether it is to process pk.\r
173\r
174 @return EFI_INVALID_PARAMETER Invalid parameter\r
2d3fb919 175 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation\r
176 check carried out by the firmware.\r
0c18794e 177 @return EFI_SUCCESS Variable passed validation successfully.\r
178\r
179**/\r
180EFI_STATUS\r
181ProcessVarWithPk (\r
182 IN CHAR16 *VariableName,\r
183 IN EFI_GUID *VendorGuid,\r
184 IN VOID *Data,\r
185 IN UINTN DataSize,\r
186 IN VARIABLE_POINTER_TRACK *Variable,\r
187 IN UINT32 Attributes OPTIONAL,\r
188 IN BOOLEAN IsPk\r
189 );\r
190\r
191/**\r
192 Process variable with key exchange key for verification.\r
193\r
194 @param[in] VariableName Name of Variable to be found.\r
195 @param[in] VendorGuid Variable vendor GUID.\r
196 @param[in] Data Data pointer.\r
197 @param[in] DataSize Size of Data found. If size is less than the\r
198 data, this value contains the required size.\r
199 @param[in] Variable The variable information that is used to keep track of variable usage.\r
200 @param[in] Attributes Attribute value of the variable.\r
201\r
202 @return EFI_INVALID_PARAMETER Invalid parameter.\r
2d3fb919 203 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation\r
204 check carried out by the firmware.\r
0c18794e 205 @return EFI_SUCCESS Variable passed validation successfully.\r
206\r
207**/\r
208EFI_STATUS\r
209ProcessVarWithKek (\r
210 IN CHAR16 *VariableName,\r
211 IN EFI_GUID *VendorGuid,\r
212 IN VOID *Data,\r
213 IN UINTN DataSize,\r
214 IN VARIABLE_POINTER_TRACK *Variable,\r
215 IN UINT32 Attributes OPTIONAL\r
216 );\r
217\r
2d3fb919 218/**\r
219 Merge two buffers which formatted as EFI_SIGNATURE_LIST. Only the new EFI_SIGNATURE_DATA\r
220 will be appended to the original EFI_SIGNATURE_LIST, duplicate EFI_SIGNATURE_DATA\r
221 will be ignored.\r
222\r
223 @param[in, out] Data Pointer to original EFI_SIGNATURE_LIST.\r
224 @param[in] DataSize Size of Data buffer.\r
225 @param[in] NewData Pointer to new EFI_SIGNATURE_LIST to be appended.\r
226 @param[in] NewDataSize Size of NewData buffer.\r
227\r
228 @return Size of the merged buffer.\r
229\r
230**/\r
231UINTN\r
232AppendSignatureList (\r
233 IN OUT VOID *Data,\r
234 IN UINTN DataSize,\r
235 IN VOID *NewData,\r
236 IN UINTN NewDataSize\r
237 );\r
238\r
0c18794e 239/**\r
240 Compare two EFI_TIME data.\r
241\r
242\r
243 @param FirstTime A pointer to the first EFI_TIME data.\r
244 @param SecondTime A pointer to the second EFI_TIME data.\r
245\r
246 @retval TRUE The FirstTime is not later than the SecondTime.\r
247 @retval FALSE The FirstTime is later than the SecondTime.\r
248\r
249**/\r
250BOOLEAN\r
251CompareTimeStamp (\r
252 IN EFI_TIME *FirstTime,\r
253 IN EFI_TIME *SecondTime\r
254 );\r
255\r
256\r
257/**\r
258 Process variable with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set\r
259\r
260 @param[in] VariableName Name of Variable to be found.\r
261 @param[in] VendorGuid Variable vendor GUID.\r
262 @param[in] Data Data pointer.\r
263 @param[in] DataSize Size of Data found. If size is less than the\r
264 data, this value contains the required size.\r
265 @param[in] Variable The variable information which is used to keep track of variable usage.\r
266 @param[in] Attributes Attribute value of the variable.\r
ed47ae02 267 @param[in] AuthVarType Verify against PK or KEK database or private database.\r
0c18794e 268 @param[out] VarDel Delete the variable or not.\r
269\r
270 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
2d3fb919 271 @retval EFI_SECURITY_VIOLATION The variable does NOT pass the validation\r
272 check carried out by the firmware.\r
0c18794e 273 @retval EFI_OUT_OF_RESOURCES Failed to process variable due to lack\r
274 of resources.\r
275 @retval EFI_SUCCESS Variable pass validation successfully.\r
276\r
277**/\r
278EFI_STATUS\r
279VerifyTimeBasedPayload (\r
280 IN CHAR16 *VariableName,\r
281 IN EFI_GUID *VendorGuid,\r
282 IN VOID *Data,\r
283 IN UINTN DataSize,\r
284 IN VARIABLE_POINTER_TRACK *Variable,\r
285 IN UINT32 Attributes,\r
ed47ae02 286 IN AUTHVAR_TYPE AuthVarType,\r
0c18794e 287 OUT BOOLEAN *VarDel\r
288 );\r
289\r
290extern UINT8 mPubKeyStore[MAX_KEYDB_SIZE];\r
291extern UINT32 mPubKeyNumber;\r
292extern VOID *mHashCtx;\r
293extern VOID *mStorageArea;\r
2d3fb919 294extern UINT8 *mSerializationRuntimeBuffer;\r
295\r
0c18794e 296#endif\r