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