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