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