]>
Commit | Line | Data |
---|---|---|
0c18794e | 1 | /** @file\r |
2 | Usb Credential Provider driver implemenetation.\r | |
3 | \r | |
ae4cb94f | 4 | Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r |
0c18794e | 5 | This program and the accompanying materials \r |
6 | are licensed and made available under the terms and conditions of the BSD License \r | |
7 | which accompanies this distribution. The full text of the license may be found at \r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "UsbCredentialProvider.h"\r | |
16 | \r | |
17 | CREDENTIAL_TABLE *mUsbTable = NULL;\r | |
18 | USB_PROVIDER_CALLBACK_INFO *mCallbackInfo = NULL;\r | |
19 | USB_CREDENTIAL_INFO *mUsbInfoHandle = NULL;\r | |
20 | \r | |
6f0b8648 | 21 | EFI_USER_CREDENTIAL2_PROTOCOL gUsbCredentialProviderDriver = {\r |
0c18794e | 22 | USB_CREDENTIAL_PROVIDER_GUID,\r |
23 | EFI_USER_CREDENTIAL_CLASS_SECURE_CARD,\r | |
24 | CredentialEnroll,\r | |
25 | CredentialForm,\r | |
26 | CredentialTile,\r | |
27 | CredentialTitle,\r | |
28 | CredentialUser,\r | |
29 | CredentialSelect,\r | |
30 | CredentialDeselect,\r | |
31 | CredentialDefault,\r | |
32 | CredentialGetInfo,\r | |
6f0b8648 | 33 | CredentialGetNextInfo,\r |
34 | EFI_CREDENTIAL_CAPABILITIES_ENROLL,\r | |
35 | CredentialDelete\r | |
0c18794e | 36 | };\r |
37 | \r | |
38 | \r | |
39 | /**\r | |
40 | Get string by string id from HII Interface.\r | |
41 | \r | |
42 | \r | |
43 | @param[in] Id String ID to get the string from.\r | |
44 | \r | |
45 | @retval CHAR16 * String from ID.\r | |
46 | @retval NULL If error occurs.\r | |
47 | \r | |
48 | **/\r | |
49 | CHAR16 *\r | |
50 | GetStringById (\r | |
51 | IN EFI_STRING_ID Id\r | |
52 | )\r | |
53 | {\r | |
54 | //\r | |
55 | // Get the current string for the current Language\r | |
56 | //\r | |
57 | return HiiGetString (mCallbackInfo->HiiHandle, Id, NULL);\r | |
58 | }\r | |
59 | \r | |
60 | \r | |
61 | /**\r | |
62 | Expand password table size.\r | |
63 | \r | |
64 | **/\r | |
65 | VOID\r | |
66 | ExpandTableSize (\r | |
67 | VOID\r | |
68 | )\r | |
69 | {\r | |
70 | CREDENTIAL_TABLE *NewTable;\r | |
71 | UINTN Count;\r | |
72 | \r | |
73 | Count = mUsbTable->MaxCount + USB_TABLE_INC;\r | |
74 | //\r | |
75 | // Create new credential table.\r | |
76 | //\r | |
77 | NewTable = AllocateZeroPool (\r | |
78 | sizeof (CREDENTIAL_TABLE) - sizeof (USB_INFO) +\r | |
79 | Count * sizeof (USB_INFO)\r | |
80 | );\r | |
81 | ASSERT (NewTable != NULL); \r | |
82 | \r | |
83 | NewTable->MaxCount = Count;\r | |
84 | NewTable->Count = mUsbTable->Count;\r | |
85 | \r | |
86 | //\r | |
87 | // Copy old entries.\r | |
88 | //\r | |
89 | CopyMem (\r | |
90 | &NewTable->UserInfo, \r | |
91 | &mUsbTable->UserInfo, \r | |
92 | mUsbTable->Count * sizeof (USB_INFO)\r | |
93 | );\r | |
94 | FreePool (mUsbTable);\r | |
95 | mUsbTable = NewTable;\r | |
96 | }\r | |
97 | \r | |
98 | \r | |
99 | /**\r | |
6f0b8648 | 100 | Add, update or delete info in table, and sync with NV variable.\r |
0c18794e | 101 | \r |
6f0b8648 | 102 | @param[in] Index The index of the password in table. If index is found in\r |
103 | table, update the info, else add the into to table. \r | |
104 | @param[in] Info The new credential info to add into table. If Info is NULL, \r | |
105 | delete the info by Index.\r | |
0c18794e | 106 | \r |
107 | @retval EFI_INVALID_PARAMETER Info is NULL when save the info.\r | |
108 | @retval EFI_SUCCESS Modify the table successfully.\r | |
109 | @retval Others Failed to modify the table.\r | |
110 | \r | |
111 | **/\r | |
112 | EFI_STATUS\r | |
113 | ModifyTable (\r | |
114 | IN UINTN Index,\r | |
115 | IN USB_INFO * Info OPTIONAL\r | |
116 | )\r | |
117 | {\r | |
118 | EFI_STATUS Status;\r | |
6f0b8648 | 119 | USB_INFO *NewUsbInfo;\r |
0c18794e | 120 | \r |
6f0b8648 | 121 | NewUsbInfo = NULL;\r |
0c18794e | 122 | if (Index < mUsbTable->Count) {\r |
6f0b8648 | 123 | if (Info == NULL) {\r |
124 | //\r | |
125 | // Delete the specified entry.\r | |
126 | //\r | |
127 | mUsbTable->Count--;\r | |
128 | if (Index != mUsbTable->Count) {\r | |
129 | NewUsbInfo = &mUsbTable->UserInfo[mUsbTable->Count];\r | |
130 | } \r | |
131 | } else {\r | |
132 | //\r | |
133 | // Update the specified entry.\r | |
134 | //\r | |
135 | NewUsbInfo = Info;\r | |
0c18794e | 136 | }\r |
137 | } else {\r | |
138 | //\r | |
139 | // Add a new entry\r | |
140 | //\r | |
141 | if (Info == NULL) {\r | |
142 | return EFI_INVALID_PARAMETER;\r | |
143 | }\r | |
144 | \r | |
145 | if (mUsbTable->Count >= mUsbTable->MaxCount) {\r | |
146 | ExpandTableSize ();\r | |
147 | }\r | |
148 | \r | |
6f0b8648 | 149 | NewUsbInfo = Info;\r |
0c18794e | 150 | mUsbTable->Count++;\r |
151 | }\r | |
152 | \r | |
6f0b8648 | 153 | if (NewUsbInfo != NULL) {\r |
154 | CopyMem (&mUsbTable->UserInfo[Index], NewUsbInfo, sizeof (USB_INFO));\r | |
155 | }\r | |
156 | \r | |
0c18794e | 157 | //\r |
158 | // Save the credential table.\r | |
159 | //\r | |
160 | Status = gRT->SetVariable (\r | |
161 | L"UsbCredential",\r | |
a0c56a82 | 162 | &gUsbCredentialProviderGuid,\r |
0c18794e | 163 | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r |
164 | mUsbTable->Count * sizeof (USB_INFO),\r | |
165 | &mUsbTable->UserInfo\r | |
166 | );\r | |
167 | return Status;\r | |
168 | }\r | |
169 | \r | |
170 | \r | |
171 | /**\r | |
172 | Create a credential table\r | |
173 | \r | |
174 | @retval EFI_SUCCESS Create a credential table successfully.\r | |
175 | @retval Others Failed to create a password.\r | |
176 | \r | |
177 | **/\r | |
178 | EFI_STATUS\r | |
179 | InitCredentialTable (\r | |
180 | VOID\r | |
181 | )\r | |
182 | {\r | |
183 | EFI_STATUS Status;\r | |
184 | UINT8 *Var;\r | |
185 | UINTN VarSize;\r | |
186 | \r | |
187 | //\r | |
188 | // Get Usb credential data from NV variable.\r | |
189 | //\r | |
190 | VarSize = 0;\r | |
191 | Var = NULL;\r | |
192 | Status = gRT->GetVariable (\r | |
193 | L"UsbCredential", \r | |
a0c56a82 | 194 | &gUsbCredentialProviderGuid, \r |
0c18794e | 195 | NULL, \r |
196 | &VarSize,\r | |
197 | Var\r | |
198 | );\r | |
199 | if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
200 | Var = AllocateZeroPool (VarSize);\r | |
201 | if (Var == NULL) {\r | |
202 | return EFI_OUT_OF_RESOURCES;\r | |
203 | }\r | |
204 | Status = gRT->GetVariable (\r | |
205 | L"UsbCredential", \r | |
a0c56a82 | 206 | &gUsbCredentialProviderGuid, \r |
0c18794e | 207 | NULL, \r |
208 | &VarSize,\r | |
209 | Var\r | |
210 | );\r | |
211 | }\r | |
212 | if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {\r | |
213 | return Status;\r | |
214 | }\r | |
215 | \r | |
216 | //\r | |
217 | // Init Usb credential table.\r | |
218 | //\r | |
219 | mUsbTable = AllocateZeroPool (\r | |
220 | sizeof (CREDENTIAL_TABLE) - sizeof (USB_INFO) +\r | |
221 | USB_TABLE_INC * sizeof (USB_INFO) + \r | |
222 | VarSize\r | |
223 | );\r | |
224 | if (mUsbTable == NULL) {\r | |
225 | FreePool (Var);\r | |
226 | return EFI_OUT_OF_RESOURCES;\r | |
227 | }\r | |
228 | \r | |
229 | mUsbTable->Count = VarSize / sizeof (USB_INFO);\r | |
230 | mUsbTable->MaxCount = mUsbTable->Count + USB_TABLE_INC;\r | |
231 | if (Var != NULL) {\r | |
232 | CopyMem (mUsbTable->UserInfo, Var, VarSize);\r | |
233 | FreePool (Var);\r | |
234 | }\r | |
235 | return EFI_SUCCESS;\r | |
236 | }\r | |
237 | \r | |
238 | \r | |
239 | /**\r | |
240 | Read the specified file by FileName in the Usb key and return the file size in BufferSize\r | |
241 | and file content in Buffer.\r | |
242 | Note: the caller is responsible to free the buffer memory.\r | |
243 | \r | |
244 | @param FileName File to read.\r | |
245 | @param Buffer Returned with data read from the file.\r | |
246 | @param BufferSize Size of the data buffer.\r | |
247 | \r | |
248 | @retval EFI_SUCCESS The command completed successfully.\r | |
249 | @retval EFI_OUT_OF_RESOURCES Resource allocation failed.\r | |
250 | @retval EFI_NOT_FOUND File not found.\r | |
251 | @retval EFI_DEVICE_ERROR Device I/O error.\r | |
252 | \r | |
253 | **/\r | |
254 | EFI_STATUS\r | |
255 | GetFileData (\r | |
256 | IN CHAR16 *FileName,\r | |
257 | OUT VOID **Buffer,\r | |
258 | OUT UINTN *BufferSize\r | |
259 | )\r | |
260 | {\r | |
261 | EFI_STATUS Status;\r | |
262 | UINTN Index;\r | |
263 | UINTN HandleCount;\r | |
264 | UINTN ScratchBufferSize;\r | |
265 | EFI_HANDLE *HandleBuffer;\r | |
266 | EFI_FILE *RootFs;\r | |
267 | EFI_FILE *FileHandle;\r | |
268 | EFI_FILE_INFO *FileInfo;\r | |
269 | EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFileSystem;\r | |
270 | EFI_BLOCK_IO_PROTOCOL *BlkIo;\r | |
271 | \r | |
272 | FileInfo = NULL;\r | |
273 | FileHandle = NULL;\r | |
274 | \r | |
275 | Status = gBS->LocateHandleBuffer (\r | |
276 | ByProtocol,\r | |
277 | &gEfiSimpleFileSystemProtocolGuid,\r | |
278 | NULL,\r | |
279 | &HandleCount,\r | |
280 | &HandleBuffer\r | |
281 | );\r | |
282 | if (EFI_ERROR (Status)) {\r | |
283 | DEBUG ((DEBUG_ERROR, "Can not Locate SimpleFileSystemProtocol\n"));\r | |
284 | goto Done;\r | |
285 | }\r | |
286 | \r | |
287 | //\r | |
288 | // Find and open the file in removable media disk.\r | |
289 | //\r | |
290 | for (Index = 0; Index < HandleCount; Index++) {\r | |
291 | Status = gBS->HandleProtocol (\r | |
292 | HandleBuffer[Index],\r | |
293 | &gEfiBlockIoProtocolGuid,\r | |
294 | (VOID **) &BlkIo\r | |
295 | );\r | |
296 | if (EFI_ERROR (Status)) {\r | |
297 | continue;\r | |
298 | }\r | |
299 | \r | |
300 | if (BlkIo->Media->RemovableMedia) {\r | |
301 | Status = gBS->HandleProtocol (\r | |
302 | HandleBuffer[Index],\r | |
303 | &gEfiSimpleFileSystemProtocolGuid,\r | |
304 | (VOID **) &SimpleFileSystem\r | |
305 | );\r | |
306 | if (EFI_ERROR (Status)) {\r | |
307 | continue;\r | |
308 | }\r | |
309 | \r | |
310 | Status = SimpleFileSystem->OpenVolume (\r | |
311 | SimpleFileSystem,\r | |
312 | &RootFs\r | |
313 | );\r | |
314 | if (EFI_ERROR (Status)) {\r | |
315 | continue;\r | |
316 | }\r | |
317 | \r | |
318 | Status = RootFs->Open (\r | |
319 | RootFs,\r | |
320 | &FileHandle,\r | |
321 | FileName,\r | |
322 | EFI_FILE_MODE_READ,\r | |
323 | 0\r | |
324 | );\r | |
325 | if (!EFI_ERROR (Status)) {\r | |
326 | break;\r | |
327 | } \r | |
328 | }\r | |
329 | }\r | |
330 | \r | |
331 | FreePool (HandleBuffer);\r | |
332 | \r | |
333 | if (Index >= HandleCount) {\r | |
334 | DEBUG ((DEBUG_ERROR, "Can not found the token file!\n"));\r | |
335 | Status = EFI_NOT_FOUND;\r | |
336 | goto Done;\r | |
337 | }\r | |
338 | \r | |
339 | //\r | |
340 | // Figure out how big the file is.\r | |
341 | //\r | |
342 | ScratchBufferSize = 0;\r | |
343 | Status = FileHandle->GetInfo (\r | |
344 | FileHandle,\r | |
345 | &gEfiFileInfoGuid,\r | |
346 | &ScratchBufferSize,\r | |
347 | NULL\r | |
348 | );\r | |
349 | if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {\r | |
350 | DEBUG ((DEBUG_ERROR, "Can not obtain file size info!\n"));\r | |
351 | Status = EFI_DEVICE_ERROR;\r | |
352 | goto Done;\r | |
353 | }\r | |
354 | \r | |
355 | FileInfo = AllocateZeroPool (ScratchBufferSize); \r | |
356 | if (FileInfo == NULL) {\r | |
357 | DEBUG ((DEBUG_ERROR, "Can not allocate enough memory for the token file!\n"));\r | |
358 | Status = EFI_OUT_OF_RESOURCES;\r | |
359 | goto Done;\r | |
360 | }\r | |
361 | \r | |
362 | Status = FileHandle->GetInfo (\r | |
363 | FileHandle,\r | |
364 | &gEfiFileInfoGuid,\r | |
365 | &ScratchBufferSize,\r | |
366 | FileInfo\r | |
367 | );\r | |
368 | if (EFI_ERROR (Status)) {\r | |
369 | DEBUG ((DEBUG_ERROR, "Can not obtain file info from the token file!\n"));\r | |
370 | Status = EFI_DEVICE_ERROR;\r | |
371 | goto Done;\r | |
372 | }\r | |
373 | \r | |
374 | //\r | |
375 | // Allocate a buffer for the file.\r | |
376 | //\r | |
377 | *BufferSize = (UINT32) FileInfo->FileSize;\r | |
378 | *Buffer = AllocateZeroPool (*BufferSize); \r | |
379 | if (*Buffer == NULL) {\r | |
380 | DEBUG ((DEBUG_ERROR, "Can not allocate a buffer for the file!\n"));\r | |
381 | Status = EFI_OUT_OF_RESOURCES;\r | |
382 | goto Done;\r | |
383 | }\r | |
384 | \r | |
385 | //\r | |
386 | // Load file into the allocated memory.\r | |
387 | //\r | |
388 | Status = FileHandle->Read (FileHandle, BufferSize, *Buffer);\r | |
389 | if (EFI_ERROR (Status)) {\r | |
390 | FreePool (*Buffer);\r | |
391 | DEBUG ((DEBUG_ERROR, "Can not read the token file!\n"));\r | |
392 | Status = EFI_DEVICE_ERROR;\r | |
393 | goto Done;\r | |
394 | }\r | |
395 | \r | |
396 | //\r | |
397 | // Close file.\r | |
398 | //\r | |
399 | Status = FileHandle->Close (FileHandle);\r | |
400 | if (EFI_ERROR (Status)) {\r | |
401 | FreePool (*Buffer);\r | |
402 | DEBUG ((DEBUG_ERROR, "Can not close the token file !\n"));\r | |
403 | Status = EFI_DEVICE_ERROR;\r | |
404 | }\r | |
405 | \r | |
406 | Done:\r | |
407 | \r | |
408 | if (FileInfo != NULL) {\r | |
409 | FreePool (FileInfo);\r | |
410 | }\r | |
411 | \r | |
412 | return Status;\r | |
413 | }\r | |
414 | \r | |
415 | \r | |
416 | /**\r | |
417 | Hash the data to get credential.\r | |
418 | \r | |
419 | @param[in] Buffer Points to the data buffer \r | |
420 | @param[in] BufferSize The size of data in buffer, in bytes.\r | |
421 | @param[out] Credential Points to the hashed result\r | |
422 | \r | |
423 | @retval TRUE Hash the data successfully.\r | |
424 | @retval FALSE Failed to hash the data.\r | |
425 | \r | |
426 | **/\r | |
427 | BOOLEAN\r | |
428 | GenerateCredential (\r | |
429 | IN UINT8 *Buffer,\r | |
430 | IN UINTN BufferSize,\r | |
431 | OUT UINT8 *Credential\r | |
432 | )\r | |
433 | {\r | |
434 | BOOLEAN Status;\r | |
435 | UINTN HashSize;\r | |
436 | VOID *Hash;\r | |
437 | \r | |
438 | HashSize = Sha1GetContextSize ();\r | |
439 | Hash = AllocatePool (HashSize);\r | |
440 | ASSERT (Hash != NULL);\r | |
441 | \r | |
442 | Status = Sha1Init (Hash);\r | |
443 | if (!Status) {\r | |
444 | goto Done;\r | |
445 | }\r | |
446 | \r | |
447 | Status = Sha1Update (Hash, Buffer, BufferSize);\r | |
448 | if (!Status) {\r | |
449 | goto Done;\r | |
450 | }\r | |
451 | \r | |
452 | Status = Sha1Final (Hash, Credential);\r | |
453 | \r | |
454 | Done:\r | |
455 | FreePool (Hash);\r | |
456 | return Status;\r | |
457 | }\r | |
458 | \r | |
459 | \r | |
460 | /**\r | |
461 | Read the token file, and default the Token is saved at the begining of the file.\r | |
462 | \r | |
463 | @param[out] Token Token read from a Token file.\r | |
464 | \r | |
465 | @retval EFI_SUCCESS Read a Token successfully.\r | |
466 | @retval Others Fails to read a Token.\r | |
467 | \r | |
468 | **/\r | |
469 | EFI_STATUS\r | |
470 | GetToken (\r | |
471 | OUT UINT8 *Token\r | |
472 | )\r | |
473 | {\r | |
474 | EFI_STATUS Status;\r | |
475 | UINT8 *Buffer;\r | |
476 | UINTN BufSize;\r | |
477 | CHAR16 *TokenFile;\r | |
478 | \r | |
479 | BufSize = 0;\r | |
480 | Buffer = NULL;\r | |
481 | TokenFile = FixedPcdGetPtr (PcdFixedUsbCredentialProviderTokenFileName);\r | |
482 | Status = GetFileData (TokenFile, (VOID *)&Buffer, &BufSize);\r | |
483 | if (EFI_ERROR (Status)) {\r | |
484 | DEBUG ((DEBUG_ERROR, "Read file %s from USB error! Status=(%r)\n", TokenFile, Status));\r | |
485 | return Status;\r | |
486 | }\r | |
487 | \r | |
488 | if (!GenerateCredential (Buffer, BufSize, Token)) {\r | |
489 | DEBUG ((DEBUG_ERROR, "Generate credential from read data failed!\n"));\r | |
490 | FreePool (Buffer);\r | |
491 | return EFI_SECURITY_VIOLATION;\r | |
492 | }\r | |
493 | \r | |
494 | FreePool (Buffer); \r | |
495 | return EFI_SUCCESS;\r | |
496 | }\r | |
497 | \r | |
498 | \r | |
499 | /**\r | |
500 | Find a user infomation record by the information record type.\r | |
501 | \r | |
502 | This function searches all user information records of User from beginning \r | |
503 | until either the information is found or there are no more user infomation\r | |
504 | record. A match occurs when a Info.InfoType field matches the user information\r | |
505 | record type.\r | |
506 | \r | |
507 | @param[in] User Points to the user profile record to search. \r | |
508 | @param[in] InfoType The infomation type to be searched.\r | |
509 | @param[out] Info Points to the user info found, the caller is responsible\r | |
510 | to free.\r | |
511 | \r | |
512 | @retval EFI_SUCCESS Find the user information successfully.\r | |
513 | @retval Others Fail to find the user information.\r | |
514 | \r | |
515 | **/\r | |
516 | EFI_STATUS\r | |
517 | FindUserInfoByType (\r | |
518 | IN EFI_USER_PROFILE_HANDLE User,\r | |
519 | IN UINT8 InfoType,\r | |
520 | OUT EFI_USER_INFO **Info\r | |
521 | )\r | |
522 | {\r | |
523 | EFI_STATUS Status;\r | |
524 | EFI_USER_INFO *UserInfo;\r | |
525 | UINTN UserInfoSize;\r | |
526 | EFI_USER_INFO_HANDLE UserInfoHandle;\r | |
527 | EFI_USER_MANAGER_PROTOCOL *UserManager;\r | |
528 | \r | |
529 | //\r | |
530 | // Find user information by information type.\r | |
531 | //\r | |
532 | if (Info == NULL) {\r | |
533 | return EFI_INVALID_PARAMETER;\r | |
534 | }\r | |
535 | \r | |
536 | Status = gBS->LocateProtocol (\r | |
537 | &gEfiUserManagerProtocolGuid,\r | |
538 | NULL,\r | |
539 | (VOID **) &UserManager\r | |
540 | );\r | |
541 | if (EFI_ERROR (Status)) {\r | |
542 | return EFI_NOT_FOUND;\r | |
543 | }\r | |
544 | \r | |
545 | //\r | |
546 | // Get each user information.\r | |
547 | //\r | |
548 | \r | |
549 | UserInfoHandle = NULL;\r | |
550 | UserInfo = NULL;\r | |
551 | UserInfoSize = 0;\r | |
552 | while (TRUE) {\r | |
553 | Status = UserManager->GetNextInfo (UserManager, User, &UserInfoHandle);\r | |
554 | if (EFI_ERROR (Status)) {\r | |
555 | break;\r | |
556 | }\r | |
557 | //\r | |
558 | // Get information.\r | |
559 | //\r | |
560 | Status = UserManager->GetInfo (\r | |
561 | UserManager,\r | |
562 | User,\r | |
563 | UserInfoHandle,\r | |
564 | UserInfo,\r | |
565 | &UserInfoSize\r | |
566 | );\r | |
567 | if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
568 | if (UserInfo != NULL) {\r | |
569 | FreePool (UserInfo);\r | |
570 | }\r | |
571 | UserInfo = AllocateZeroPool (UserInfoSize);\r | |
572 | if (UserInfo == NULL) {\r | |
573 | return EFI_OUT_OF_RESOURCES;\r | |
574 | }\r | |
575 | Status = UserManager->GetInfo (\r | |
576 | UserManager,\r | |
577 | User,\r | |
578 | UserInfoHandle,\r | |
579 | UserInfo,\r | |
580 | &UserInfoSize\r | |
581 | );\r | |
582 | }\r | |
583 | if (EFI_ERROR (Status)) {\r | |
584 | break;\r | |
585 | }\r | |
586 | \r | |
587 | ASSERT (UserInfo != NULL);\r | |
588 | if (UserInfo->InfoType == InfoType) {\r | |
589 | *Info = UserInfo;\r | |
590 | return EFI_SUCCESS;\r | |
591 | } \r | |
592 | }\r | |
593 | \r | |
594 | if (UserInfo != NULL) {\r | |
595 | FreePool (UserInfo);\r | |
596 | }\r | |
597 | return Status;\r | |
598 | }\r | |
599 | \r | |
600 | \r | |
601 | /**\r | |
602 | This function initialize the data mainly used in form browser.\r | |
603 | \r | |
604 | @retval EFI_SUCCESS Initialize form data successfully.\r | |
605 | @retval Others Fail to Initialize form data.\r | |
606 | \r | |
607 | **/\r | |
608 | EFI_STATUS\r | |
609 | InitFormBrowser (\r | |
610 | VOID\r | |
611 | )\r | |
612 | {\r | |
613 | USB_PROVIDER_CALLBACK_INFO *CallbackInfo;\r | |
614 | \r | |
615 | //\r | |
616 | // Initialize driver private data.\r | |
617 | //\r | |
618 | CallbackInfo = AllocateZeroPool (sizeof (USB_PROVIDER_CALLBACK_INFO));\r | |
619 | if (CallbackInfo == NULL) {\r | |
620 | return EFI_OUT_OF_RESOURCES;\r | |
621 | }\r | |
622 | \r | |
623 | CallbackInfo->DriverHandle = NULL;\r | |
624 | \r | |
625 | //\r | |
626 | // Publish HII data.\r | |
627 | //\r | |
628 | CallbackInfo->HiiHandle = HiiAddPackages (\r | |
a0c56a82 | 629 | &gUsbCredentialProviderGuid,\r |
0c18794e | 630 | CallbackInfo->DriverHandle,\r |
631 | UsbCredentialProviderStrings,\r | |
632 | NULL\r | |
633 | );\r | |
634 | if (CallbackInfo->HiiHandle == NULL) {\r | |
635 | return EFI_OUT_OF_RESOURCES;\r | |
636 | }\r | |
637 | mCallbackInfo = CallbackInfo;\r | |
638 | \r | |
639 | return EFI_SUCCESS;\r | |
640 | }\r | |
641 | \r | |
642 | \r | |
643 | /**\r | |
644 | Enroll a user on a credential provider.\r | |
645 | \r | |
6f0b8648 | 646 | This function enrolls a user on this credential provider. If the user exists on \r |
647 | this credential provider, update the user information on this credential provider; \r | |
648 | otherwise add the user information on credential provider.\r | |
0c18794e | 649 | \r |
6f0b8648 | 650 | @param[in] This Points to this instance of EFI_USER_CREDENTIAL2_PROTOCOL.\r |
0c18794e | 651 | @param[in] User The user profile to enroll.\r |
652 | \r | |
653 | @retval EFI_SUCCESS User profile was successfully enrolled.\r | |
654 | @retval EFI_ACCESS_DENIED Current user profile does not permit enrollment on the\r | |
655 | user profile handle. Either the user profile cannot enroll\r | |
656 | on any user profile or cannot enroll on a user profile \r | |
657 | other than the current user profile.\r | |
658 | @retval EFI_UNSUPPORTED This credential provider does not support enrollment in\r | |
659 | the pre-OS.\r | |
660 | @retval EFI_DEVICE_ERROR The new credential could not be created because of a device\r | |
661 | error.\r | |
662 | @retval EFI_INVALID_PARAMETER User does not refer to a valid user profile handle.\r | |
663 | \r | |
664 | **/\r | |
665 | EFI_STATUS\r | |
666 | EFIAPI\r | |
667 | CredentialEnroll (\r | |
6f0b8648 | 668 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r |
0c18794e | 669 | IN EFI_USER_PROFILE_HANDLE User\r |
670 | )\r | |
671 | {\r | |
672 | EFI_STATUS Status;\r | |
673 | UINTN Index;\r | |
674 | USB_INFO UsbInfo;\r | |
675 | EFI_USER_INFO *UserInfo;\r | |
676 | EFI_INPUT_KEY Key;\r | |
677 | EFI_USER_MANAGER_PROTOCOL *UserManager;\r | |
678 | UINT8 *UserId;\r | |
0c18794e | 679 | CHAR16 *QuestionStr;\r |
680 | CHAR16 *PromptStr;\r | |
681 | \r | |
682 | if ((This == NULL) || (User == NULL)) {\r | |
683 | return EFI_INVALID_PARAMETER;\r | |
684 | }\r | |
685 | \r | |
686 | Status = gBS->LocateProtocol (\r | |
687 | &gEfiUserManagerProtocolGuid,\r | |
688 | NULL,\r | |
689 | (VOID **) &UserManager\r | |
690 | );\r | |
691 | if (EFI_ERROR (Status)) {\r | |
692 | return EFI_UNSUPPORTED;\r | |
693 | }\r | |
694 | \r | |
695 | //\r | |
696 | // Get User Identifier\r | |
697 | //\r | |
698 | UserInfo = NULL;\r | |
699 | Status = FindUserInfoByType (\r | |
700 | User,\r | |
701 | EFI_USER_INFO_IDENTIFIER_RECORD,\r | |
702 | &UserInfo\r | |
703 | );\r | |
704 | if (EFI_ERROR (Status)) {\r | |
705 | return EFI_INVALID_PARAMETER;\r | |
706 | }\r | |
0c18794e | 707 | \r |
6f0b8648 | 708 | CopyMem (UsbInfo.UserId, (UINT8 *) (UserInfo + 1), sizeof (EFI_USER_INFO_IDENTIFIER)); \r |
709 | FreePool (UserInfo);\r | |
710 | \r | |
0c18794e | 711 | //\r |
712 | // Get Token and User ID to UsbInfo.\r | |
713 | //\r | |
714 | Status = GetToken (UsbInfo.Token);\r | |
715 | if (EFI_ERROR (Status)) {\r | |
716 | QuestionStr = GetStringById (STRING_TOKEN (STR_READ_USB_TOKEN_ERROR));\r | |
717 | PromptStr = GetStringById (STRING_TOKEN (STR_INSERT_USB_TOKEN)); \r | |
0c18794e | 718 | CreatePopUp (\r |
719 | EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r | |
720 | &Key,\r | |
721 | QuestionStr,\r | |
722 | L"",\r | |
723 | PromptStr,\r | |
724 | NULL\r | |
725 | );\r | |
0c18794e | 726 | FreePool (QuestionStr);\r |
727 | FreePool (PromptStr);\r | |
0c18794e | 728 | return Status;\r |
729 | } \r | |
0c18794e | 730 | \r |
731 | //\r | |
6f0b8648 | 732 | // Check whether User is ever enrolled in the provider.\r |
733 | // \r | |
734 | for (Index = 0; Index < mUsbTable->Count; Index++) {\r | |
735 | UserId = (UINT8 *) &mUsbTable->UserInfo[Index].UserId;\r | |
736 | if (CompareMem (UserId, (UINT8 *) &UsbInfo.UserId, sizeof (EFI_USER_INFO_IDENTIFIER)) == 0) {\r | |
737 | //\r | |
738 | // User already exists, update the password.\r | |
739 | // \r | |
740 | break;\r | |
741 | }\r | |
742 | }\r | |
743 | \r | |
744 | //\r | |
745 | // Enroll the User to the provider.\r | |
0c18794e | 746 | //\r |
6f0b8648 | 747 | Status = ModifyTable (Index, &UsbInfo);\r |
0c18794e | 748 | if (EFI_ERROR (Status)) {\r |
749 | return Status;\r | |
750 | }\r | |
751 | \r | |
752 | //\r | |
753 | // Notify the user manager driver that credential information has changed.\r | |
754 | //\r | |
755 | UserManager->Notify (UserManager, mCallbackInfo->DriverHandle); \r | |
756 | \r | |
757 | return EFI_SUCCESS;\r | |
758 | }\r | |
759 | \r | |
760 | \r | |
761 | /**\r | |
762 | Returns the user interface information used during user identification.\r | |
763 | \r | |
764 | This function returns information about the form used when interacting with the\r | |
765 | user during user identification. The form is the first enabled form in the form-set\r | |
766 | class EFI_HII_USER_CREDENTIAL_FORMSET_GUID installed on the HII handle HiiHandle. If \r | |
767 | the user credential provider does not require a form to identify the user, then this\r | |
768 | function should return EFI_NOT_FOUND.\r | |
769 | \r | |
6f0b8648 | 770 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r |
0c18794e | 771 | @param[out] Hii On return, holds the HII database handle.\r |
772 | @param[out] FormSetId On return, holds the identifier of the form set which contains\r | |
773 | the form used during user identification.\r | |
774 | @param[out] FormId On return, holds the identifier of the form used during user \r | |
775 | identification.\r | |
776 | \r | |
777 | @retval EFI_SUCCESS Form returned successfully.\r | |
778 | @retval EFI_NOT_FOUND Form not returned.\r | |
779 | @retval EFI_INVALID_PARAMETER Hii is NULL or FormSetId is NULL or FormId is NULL.\r | |
780 | \r | |
781 | **/\r | |
782 | EFI_STATUS\r | |
783 | EFIAPI\r | |
784 | CredentialForm (\r | |
6f0b8648 | 785 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r |
0c18794e | 786 | OUT EFI_HII_HANDLE *Hii,\r |
787 | OUT EFI_GUID *FormSetId,\r | |
788 | OUT EFI_FORM_ID *FormId\r | |
789 | )\r | |
790 | {\r | |
791 | if ((This == NULL) || (Hii == NULL) || \r | |
792 | (FormSetId == NULL) || (FormId == NULL)) {\r | |
793 | return EFI_INVALID_PARAMETER;\r | |
794 | }\r | |
795 | return EFI_NOT_FOUND;\r | |
796 | }\r | |
797 | \r | |
798 | \r | |
799 | /**\r | |
800 | Returns bitmap used to describe the credential provider type.\r | |
801 | \r | |
802 | This optional function returns a bitmap which is less than or equal to the number\r | |
803 | of pixels specified by Width and Height. If no such bitmap exists, then EFI_NOT_FOUND\r | |
804 | is returned. \r | |
805 | \r | |
6f0b8648 | 806 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r |
0c18794e | 807 | @param[in, out] Width On entry, points to the desired bitmap width. If NULL then no \r |
808 | bitmap information will be returned. On exit, points to the \r | |
809 | width of the bitmap returned.\r | |
810 | @param[in, out] Height On entry, points to the desired bitmap height. If NULL then no\r | |
811 | bitmap information will be returned. On exit, points to the \r | |
812 | height of the bitmap returned.\r | |
813 | @param[out] Hii On return, holds the HII database handle. \r | |
814 | @param[out] Image On return, holds the HII image identifier. \r | |
815 | \r | |
816 | @retval EFI_SUCCESS Image identifier returned successfully.\r | |
817 | @retval EFI_NOT_FOUND Image identifier not returned.\r | |
818 | @retval EFI_INVALID_PARAMETER Hii is NULL or Image is NULL.\r | |
819 | \r | |
820 | **/\r | |
821 | EFI_STATUS\r | |
822 | EFIAPI\r | |
823 | CredentialTile (\r | |
6f0b8648 | 824 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r |
0c18794e | 825 | IN OUT UINTN *Width,\r |
826 | IN OUT UINTN *Height,\r | |
827 | OUT EFI_HII_HANDLE *Hii,\r | |
828 | OUT EFI_IMAGE_ID *Image\r | |
829 | )\r | |
830 | {\r | |
831 | if ((This == NULL) || (Hii == NULL) || (Image == NULL)) {\r | |
832 | return EFI_INVALID_PARAMETER;\r | |
833 | }\r | |
834 | return EFI_NOT_FOUND;\r | |
835 | }\r | |
836 | \r | |
837 | \r | |
838 | /**\r | |
839 | Returns string used to describe the credential provider type.\r | |
840 | \r | |
841 | This function returns a string which describes the credential provider. If no\r | |
842 | such string exists, then EFI_NOT_FOUND is returned. \r | |
843 | \r | |
6f0b8648 | 844 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r |
0c18794e | 845 | @param[out] Hii On return, holds the HII database handle.\r |
846 | @param[out] String On return, holds the HII string identifier.\r | |
847 | \r | |
848 | @retval EFI_SUCCESS String identifier returned successfully.\r | |
849 | @retval EFI_NOT_FOUND String identifier not returned.\r | |
850 | @retval EFI_INVALID_PARAMETER Hii is NULL or String is NULL.\r | |
851 | \r | |
852 | **/\r | |
853 | EFI_STATUS\r | |
854 | EFIAPI\r | |
855 | CredentialTitle (\r | |
6f0b8648 | 856 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r |
0c18794e | 857 | OUT EFI_HII_HANDLE *Hii,\r |
858 | OUT EFI_STRING_ID *String\r | |
859 | )\r | |
860 | {\r | |
861 | if ((This == NULL) || (Hii == NULL) || (String == NULL)) {\r | |
862 | return EFI_INVALID_PARAMETER;\r | |
863 | }\r | |
864 | //\r | |
865 | // Set Hii handle and String ID.\r | |
866 | //\r | |
867 | *Hii = mCallbackInfo->HiiHandle;\r | |
868 | *String = STRING_TOKEN (STR_CREDENTIAL_TITLE);\r | |
869 | \r | |
870 | return EFI_SUCCESS;\r | |
871 | }\r | |
872 | \r | |
873 | \r | |
874 | /**\r | |
875 | Return the user identifier associated with the currently authenticated user.\r | |
876 | \r | |
877 | This function returns the user identifier of the user authenticated by this credential\r | |
878 | provider. This function is called after the credential-related information has been \r | |
879 | submitted on a form OR after a call to Default() has returned that this credential is\r | |
880 | ready to log on.\r | |
881 | \r | |
6f0b8648 | 882 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r |
0c18794e | 883 | @param[in] User The user profile handle of the user profile currently being \r |
884 | considered by the user identity manager. If NULL, then no user\r | |
885 | profile is currently under consideration.\r | |
886 | @param[out] Identifier On return, points to the user identifier. \r | |
887 | \r | |
888 | @retval EFI_SUCCESS User identifier returned successfully.\r | |
889 | @retval EFI_NOT_READY No user identifier can be returned.\r | |
890 | @retval EFI_ACCESS_DENIED The user has been locked out of this user credential.\r | |
891 | @retval EFI_INVALID_PARAMETER This is NULL, or Identifier is NULL.\r | |
892 | @retval EFI_NOT_FOUND User is not NULL, and the specified user handle can't be\r | |
893 | found in user profile database.\r | |
894 | \r | |
895 | **/\r | |
896 | EFI_STATUS\r | |
897 | EFIAPI\r | |
898 | CredentialUser (\r | |
6f0b8648 | 899 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r |
0c18794e | 900 | IN EFI_USER_PROFILE_HANDLE User,\r |
901 | OUT EFI_USER_INFO_IDENTIFIER *Identifier\r | |
902 | )\r | |
903 | {\r | |
904 | EFI_STATUS Status;\r | |
905 | UINTN Index;\r | |
906 | EFI_USER_INFO *UserInfo;\r | |
907 | UINT8 *UserId;\r | |
908 | UINT8 *NewUserId;\r | |
909 | UINT8 *UserToken; \r | |
910 | UINT8 ReadToken[HASHED_CREDENTIAL_LEN];\r | |
911 | EFI_INPUT_KEY Key;\r | |
912 | EFI_TPL OldTpl;\r | |
913 | CHAR16 *QuestionStr;\r | |
914 | CHAR16 *PromptStr;\r | |
915 | \r | |
916 | if ((This == NULL) || (Identifier == NULL)) {\r | |
917 | return EFI_INVALID_PARAMETER;\r | |
918 | }\r | |
919 | \r | |
920 | if (User == NULL) {\r | |
921 | //\r | |
922 | // Verify the auto logon user, get user id by matched token.\r | |
923 | //\r | |
924 | if (mUsbTable->Count == 0) {\r | |
925 | return EFI_NOT_READY;\r | |
926 | }\r | |
927 | \r | |
928 | //\r | |
929 | // No user selected, get token first and verify the user existed in user database.\r | |
930 | //\r | |
931 | Status = GetToken (ReadToken);\r | |
932 | if (EFI_ERROR (Status)) {\r | |
933 | return EFI_NOT_READY;\r | |
934 | }\r | |
935 | \r | |
936 | for (Index = 0; Index < mUsbTable->Count; Index++) {\r | |
937 | //\r | |
938 | // find the specified credential in the Usb credential database.\r | |
939 | //\r | |
940 | UserToken = mUsbTable->UserInfo[Index].Token;\r | |
941 | if (CompareMem (UserToken, ReadToken, HASHED_CREDENTIAL_LEN) == 0) {\r | |
942 | UserId = (UINT8 *) &mUsbTable->UserInfo[Index].UserId;\r | |
943 | CopyMem (Identifier, UserId, sizeof (EFI_USER_INFO_IDENTIFIER));\r | |
944 | return EFI_SUCCESS;\r | |
945 | }\r | |
946 | }\r | |
947 | \r | |
948 | return EFI_NOT_READY; \r | |
949 | }\r | |
950 | \r | |
951 | // \r | |
952 | // User is not NULL here. Read a token, and check whether the token matches with \r | |
953 | // the selected user's Token. If not, try to find a token in token DB to matches \r | |
954 | // with read token.\r | |
955 | // \r | |
956 | \r | |
957 | Status = GetToken (ReadToken);\r | |
958 | if (EFI_ERROR (Status)) {\r | |
959 | QuestionStr = GetStringById (STRING_TOKEN (STR_READ_USB_TOKEN_ERROR));\r | |
960 | PromptStr = GetStringById (STRING_TOKEN (STR_INSERT_USB_TOKEN));\r | |
961 | OldTpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r | |
962 | gBS->RestoreTPL (TPL_APPLICATION);\r | |
963 | CreatePopUp (\r | |
964 | EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r | |
965 | &Key,\r | |
966 | QuestionStr,\r | |
967 | L"",\r | |
968 | PromptStr,\r | |
969 | NULL\r | |
970 | );\r | |
971 | gBS->RaiseTPL (OldTpl);\r | |
972 | FreePool (QuestionStr);\r | |
973 | FreePool (PromptStr);\r | |
974 | return EFI_NOT_FOUND;\r | |
975 | }\r | |
976 | \r | |
977 | //\r | |
978 | // Get the selected user's identifier.\r | |
979 | //\r | |
980 | Status = FindUserInfoByType (User, EFI_USER_INFO_IDENTIFIER_RECORD, &UserInfo);\r | |
981 | if (EFI_ERROR (Status)) {\r | |
982 | return EFI_NOT_FOUND;\r | |
983 | } \r | |
984 | \r | |
985 | //\r | |
986 | // Check the selected user's Token with the read token.\r | |
987 | //\r | |
988 | for (Index = 0; Index < mUsbTable->Count; Index++) {\r | |
989 | UserId = (UINT8 *) &mUsbTable->UserInfo[Index].UserId;\r | |
990 | NewUserId = (UINT8 *) (UserInfo + 1);\r | |
991 | if (CompareMem (UserId, NewUserId, sizeof (EFI_USER_INFO_IDENTIFIER)) == 0) {\r | |
992 | //\r | |
993 | // The user's ID is found in the UsbTable.\r | |
994 | //\r | |
995 | UserToken = mUsbTable->UserInfo[Index].Token;\r | |
996 | if (CompareMem (UserToken, ReadToken, HASHED_CREDENTIAL_LEN) == 0) {\r | |
997 | //\r | |
998 | // The read token matches with the one in UsbTable.\r | |
999 | //\r | |
1000 | CopyMem (Identifier, UserId, sizeof (EFI_USER_INFO_IDENTIFIER));\r | |
1001 | FreePool (UserInfo);\r | |
1002 | return EFI_SUCCESS;\r | |
1003 | } \r | |
1004 | }\r | |
1005 | }\r | |
ae4cb94f | 1006 | \r |
1007 | FreePool (UserInfo); \r | |
1008 | \r | |
1009 | return EFI_NOT_READY;\r | |
0c18794e | 1010 | }\r |
1011 | \r | |
1012 | \r | |
1013 | /**\r | |
1014 | Indicate that user interface interaction has begun for the specified credential.\r | |
1015 | \r | |
1016 | This function is called when a credential provider is selected by the user. If \r | |
1017 | AutoLogon returns FALSE, then the user interface will be constructed by the User\r | |
1018 | Identity Manager. \r | |
1019 | \r | |
6f0b8648 | 1020 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r |
0c18794e | 1021 | @param[out] AutoLogon On return, points to the credential provider's capabilities \r |
1022 | after the credential provider has been selected by the user. \r | |
1023 | \r | |
1024 | @retval EFI_SUCCESS Credential provider successfully selected.\r | |
1025 | @retval EFI_INVALID_PARAMETER AutoLogon is NULL.\r | |
1026 | \r | |
1027 | **/\r | |
1028 | EFI_STATUS\r | |
1029 | EFIAPI\r | |
1030 | CredentialSelect (\r | |
6f0b8648 | 1031 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r |
0c18794e | 1032 | OUT EFI_CREDENTIAL_LOGON_FLAGS *AutoLogon\r |
1033 | )\r | |
1034 | {\r | |
1035 | if ((This == NULL) || (AutoLogon == NULL)) {\r | |
1036 | return EFI_INVALID_PARAMETER;\r | |
1037 | }\r | |
1038 | \r | |
1039 | *AutoLogon = EFI_CREDENTIAL_LOGON_FLAG_DEFAULT | EFI_CREDENTIAL_LOGON_FLAG_AUTO;\r | |
1040 | \r | |
1041 | return EFI_SUCCESS;\r | |
1042 | }\r | |
1043 | \r | |
1044 | \r | |
1045 | /**\r | |
1046 | Indicate that user interface interaction has ended for the specified credential.\r | |
1047 | \r | |
1048 | This function is called when a credential provider is deselected by the user.\r | |
1049 | \r | |
6f0b8648 | 1050 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r |
0c18794e | 1051 | \r |
1052 | @retval EFI_SUCCESS Credential provider successfully deselected.\r | |
1053 | \r | |
1054 | **/\r | |
1055 | EFI_STATUS\r | |
1056 | EFIAPI\r | |
1057 | CredentialDeselect (\r | |
6f0b8648 | 1058 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This\r |
0c18794e | 1059 | )\r |
1060 | {\r | |
1061 | if (This == NULL) {\r | |
1062 | return EFI_INVALID_PARAMETER;\r | |
1063 | }\r | |
1064 | return EFI_SUCCESS;\r | |
1065 | }\r | |
1066 | \r | |
1067 | \r | |
1068 | /**\r | |
1069 | Return the default logon behavior for this user credential.\r | |
1070 | \r | |
1071 | This function reports the default login behavior regarding this credential provider. \r | |
1072 | \r | |
6f0b8648 | 1073 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r |
0c18794e | 1074 | @param[out] AutoLogon On return, holds whether the credential provider should be used\r |
1075 | by default to automatically log on the user. \r | |
1076 | \r | |
1077 | @retval EFI_SUCCESS Default information successfully returned.\r | |
1078 | @retval EFI_INVALID_PARAMETER AutoLogon is NULL.\r | |
1079 | \r | |
1080 | **/\r | |
1081 | EFI_STATUS\r | |
1082 | EFIAPI\r | |
1083 | CredentialDefault (\r | |
6f0b8648 | 1084 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r |
0c18794e | 1085 | OUT EFI_CREDENTIAL_LOGON_FLAGS *AutoLogon\r |
1086 | )\r | |
1087 | {\r | |
1088 | if ((This == NULL) || (AutoLogon == NULL)) {\r | |
1089 | return EFI_INVALID_PARAMETER;\r | |
1090 | }\r | |
1091 | \r | |
1092 | *AutoLogon = EFI_CREDENTIAL_LOGON_FLAG_DEFAULT | EFI_CREDENTIAL_LOGON_FLAG_AUTO;\r | |
1093 | return EFI_SUCCESS;\r | |
1094 | }\r | |
1095 | \r | |
1096 | \r | |
1097 | /**\r | |
1098 | Return information attached to the credential provider.\r | |
1099 | \r | |
1100 | This function returns user information. \r | |
1101 | \r | |
6f0b8648 | 1102 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r |
0c18794e | 1103 | @param[in] UserInfo Handle of the user information data record. \r |
1104 | @param[out] Info On entry, points to a buffer of at least *InfoSize bytes. On\r | |
1105 | exit, holds the user information. If the buffer is too small\r | |
1106 | to hold the information, then EFI_BUFFER_TOO_SMALL is returned\r | |
1107 | and InfoSize is updated to contain the number of bytes actually\r | |
1108 | required.\r | |
1109 | @param[in, out] InfoSize On entry, points to the size of Info. On return, points to the \r | |
1110 | size of the user information. \r | |
1111 | \r | |
1112 | @retval EFI_SUCCESS Information returned successfully.\r | |
1113 | @retval EFI_BUFFER_TOO_SMALL The size specified by InfoSize is too small to hold all of the\r | |
1114 | user information. The size required is returned in *InfoSize.\r | |
1115 | @retval EFI_INVALID_PARAMETER Info is NULL or InfoSize is NULL.\r | |
1116 | @retval EFI_NOT_FOUND The specified UserInfo does not refer to a valid user info handle. \r | |
1117 | \r | |
1118 | **/\r | |
1119 | EFI_STATUS\r | |
1120 | EFIAPI\r | |
1121 | CredentialGetInfo (\r | |
6f0b8648 | 1122 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r |
0c18794e | 1123 | IN EFI_USER_INFO_HANDLE UserInfo,\r |
1124 | OUT EFI_USER_INFO *Info,\r | |
1125 | IN OUT UINTN *InfoSize\r | |
1126 | )\r | |
1127 | {\r | |
1128 | EFI_USER_INFO *CredentialInfo;\r | |
1129 | UINTN Index;\r | |
1130 | \r | |
1131 | if ((This == NULL) || (InfoSize == NULL) || (Info == NULL)) {\r | |
1132 | return EFI_INVALID_PARAMETER;\r | |
1133 | }\r | |
1134 | \r | |
1135 | if ((UserInfo == NULL) || (mUsbInfoHandle == NULL)) {\r | |
1136 | return EFI_NOT_FOUND;\r | |
1137 | }\r | |
1138 | \r | |
1139 | //\r | |
1140 | // Find information handle in credential info table.\r | |
1141 | //\r | |
1142 | for (Index = 0; Index < mUsbInfoHandle->Count; Index++) {\r | |
1143 | CredentialInfo = mUsbInfoHandle->Info[Index];\r | |
1144 | if (UserInfo == (EFI_USER_INFO_HANDLE)CredentialInfo) {\r | |
1145 | //\r | |
1146 | // The handle is found, copy the user info.\r | |
1147 | //\r | |
1148 | if (CredentialInfo->InfoSize > *InfoSize) {\r | |
1149 | *InfoSize = CredentialInfo->InfoSize;\r | |
1150 | return EFI_BUFFER_TOO_SMALL;\r | |
1151 | }\r | |
1152 | \r | |
1153 | CopyMem (Info, CredentialInfo, CredentialInfo->InfoSize); \r | |
1154 | return EFI_SUCCESS; \r | |
1155 | }\r | |
1156 | }\r | |
1157 | \r | |
1158 | return EFI_NOT_FOUND;\r | |
1159 | }\r | |
1160 | \r | |
1161 | \r | |
1162 | /**\r | |
1163 | Enumerate all of the user informations on the credential provider.\r | |
1164 | \r | |
1165 | This function returns the next user information record. To retrieve the first user\r | |
1166 | information record handle, point UserInfo at a NULL. Each subsequent call will retrieve\r | |
1167 | another user information record handle until there are no more, at which point UserInfo\r | |
1168 | will point to NULL. \r | |
1169 | \r | |
6f0b8648 | 1170 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r |
0c18794e | 1171 | @param[in, out] UserInfo On entry, points to the previous user information handle or NULL\r |
1172 | to start enumeration. On exit, points to the next user information\r | |
1173 | handle or NULL if there is no more user information.\r | |
1174 | \r | |
1175 | @retval EFI_SUCCESS User information returned.\r | |
1176 | @retval EFI_NOT_FOUND No more user information found.\r | |
1177 | @retval EFI_INVALID_PARAMETER UserInfo is NULL.\r | |
1178 | \r | |
1179 | **/\r | |
1180 | EFI_STATUS\r | |
1181 | EFIAPI\r | |
1182 | CredentialGetNextInfo (\r | |
6f0b8648 | 1183 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r |
0c18794e | 1184 | IN OUT EFI_USER_INFO_HANDLE *UserInfo\r |
1185 | )\r | |
1186 | {\r | |
1187 | EFI_USER_INFO *Info;\r | |
1188 | CHAR16 *ProvNameStr;\r | |
1189 | UINTN InfoLen;\r | |
1190 | UINTN Index;\r | |
1191 | UINTN ProvStrLen;\r | |
1192 | \r | |
1193 | if ((This == NULL) || (UserInfo == NULL)) {\r | |
1194 | return EFI_INVALID_PARAMETER;\r | |
1195 | }\r | |
1196 | \r | |
1197 | if (mUsbInfoHandle == NULL) {\r | |
1198 | //\r | |
1199 | // Initilized user info table. There are 4 user info records in the table.\r | |
1200 | //\r | |
1201 | InfoLen = sizeof (USB_CREDENTIAL_INFO) + (4 - 1) * sizeof (EFI_USER_INFO *);\r | |
1202 | mUsbInfoHandle = AllocateZeroPool (InfoLen);\r | |
1203 | if (mUsbInfoHandle == NULL) {\r | |
1204 | *UserInfo = NULL;\r | |
1205 | return EFI_NOT_FOUND;\r | |
1206 | }\r | |
1207 | \r | |
1208 | //\r | |
1209 | // The first information, Credential Provider info.\r | |
1210 | //\r | |
1211 | InfoLen = sizeof (EFI_USER_INFO) + sizeof (EFI_GUID);\r | |
1212 | Info = AllocateZeroPool (InfoLen);\r | |
1213 | ASSERT (Info != NULL);\r | |
1214 | \r | |
1215 | Info->InfoType = EFI_USER_INFO_CREDENTIAL_PROVIDER_RECORD;\r | |
1216 | Info->InfoSize = (UINT32) InfoLen;\r | |
1217 | Info->InfoAttribs = EFI_USER_INFO_PROTECTED;\r | |
a0c56a82 LG |
1218 | CopyGuid (&Info->Credential, &gUsbCredentialProviderGuid);\r |
1219 | CopyGuid ((EFI_GUID *)(Info + 1), &gUsbCredentialProviderGuid);\r | |
0c18794e | 1220 | \r |
1221 | mUsbInfoHandle->Info[0] = Info;\r | |
1222 | mUsbInfoHandle->Count++;\r | |
1223 | \r | |
1224 | //\r | |
1225 | // The second information, Credential Provider name info.\r | |
1226 | //\r | |
1227 | ProvNameStr = GetStringById (STRING_TOKEN (STR_PROVIDER_NAME));\r | |
1228 | ProvStrLen = StrSize (ProvNameStr);\r | |
1229 | InfoLen = sizeof (EFI_USER_INFO) + ProvStrLen;\r | |
1230 | Info = AllocateZeroPool (InfoLen);\r | |
1231 | ASSERT (Info != NULL);\r | |
1232 | \r | |
1233 | Info->InfoType = EFI_USER_INFO_CREDENTIAL_PROVIDER_NAME_RECORD;\r | |
1234 | Info->InfoSize = (UINT32) InfoLen;\r | |
1235 | Info->InfoAttribs = EFI_USER_INFO_PROTECTED;\r | |
a0c56a82 | 1236 | CopyGuid (&Info->Credential, &gUsbCredentialProviderGuid);\r |
0c18794e | 1237 | CopyMem ((UINT8*)(Info + 1), ProvNameStr, ProvStrLen);\r |
1238 | FreePool (ProvNameStr);\r | |
1239 | \r | |
1240 | mUsbInfoHandle->Info[1] = Info;\r | |
1241 | mUsbInfoHandle->Count++;\r | |
1242 | \r | |
1243 | //\r | |
1244 | // The third information, Credential Provider type info.\r | |
1245 | //\r | |
1246 | InfoLen = sizeof (EFI_USER_INFO) + sizeof (EFI_GUID);\r | |
1247 | Info = AllocateZeroPool (InfoLen);\r | |
1248 | ASSERT (Info != NULL);\r | |
1249 | \r | |
1250 | Info->InfoType = EFI_USER_INFO_CREDENTIAL_TYPE_RECORD;\r | |
1251 | Info->InfoSize = (UINT32) InfoLen;\r | |
1252 | Info->InfoAttribs = EFI_USER_INFO_PROTECTED;\r | |
a0c56a82 | 1253 | CopyGuid (&Info->Credential, &gUsbCredentialProviderGuid);\r |
0c18794e | 1254 | CopyGuid ((EFI_GUID *)(Info + 1), &gEfiUserCredentialClassSecureCardGuid);\r |
1255 | \r | |
1256 | mUsbInfoHandle->Info[2] = Info;\r | |
1257 | mUsbInfoHandle->Count++;\r | |
1258 | \r | |
1259 | //\r | |
1260 | // The fourth information, Credential Provider type name info.\r | |
1261 | //\r | |
1262 | ProvNameStr = GetStringById (STRING_TOKEN (STR_PROVIDER_TYPE_NAME));\r | |
1263 | ProvStrLen = StrSize (ProvNameStr);\r | |
1264 | InfoLen = sizeof (EFI_USER_INFO) + ProvStrLen;\r | |
1265 | Info = AllocateZeroPool (InfoLen);\r | |
1266 | ASSERT (Info != NULL);\r | |
1267 | \r | |
1268 | Info->InfoType = EFI_USER_INFO_CREDENTIAL_PROVIDER_NAME_RECORD;\r | |
1269 | Info->InfoSize = (UINT32) InfoLen;\r | |
1270 | Info->InfoAttribs = EFI_USER_INFO_PROTECTED;\r | |
a0c56a82 | 1271 | CopyGuid (&Info->Credential, &gUsbCredentialProviderGuid);\r |
0c18794e | 1272 | CopyMem ((UINT8*)(Info + 1), ProvNameStr, ProvStrLen);\r |
1273 | FreePool (ProvNameStr);\r | |
1274 | \r | |
1275 | mUsbInfoHandle->Info[3] = Info;\r | |
1276 | mUsbInfoHandle->Count++;\r | |
1277 | }\r | |
1278 | \r | |
1279 | if (*UserInfo == NULL) {\r | |
1280 | //\r | |
1281 | // Return the first info handle.\r | |
1282 | //\r | |
1283 | *UserInfo = (EFI_USER_INFO_HANDLE) mUsbInfoHandle->Info[0];\r | |
1284 | return EFI_SUCCESS;\r | |
1285 | }\r | |
1286 | \r | |
1287 | //\r | |
1288 | // Find information handle in credential info table.\r | |
1289 | //\r | |
1290 | for (Index = 0; Index < mUsbInfoHandle->Count; Index++) {\r | |
1291 | Info = mUsbInfoHandle->Info[Index];\r | |
1292 | if (*UserInfo == (EFI_USER_INFO_HANDLE)Info) {\r | |
1293 | //\r | |
1294 | // The handle is found, get the next one.\r | |
1295 | //\r | |
1296 | if (Index == mUsbInfoHandle->Count - 1) {\r | |
1297 | //\r | |
1298 | // Already last one.\r | |
1299 | //\r | |
1300 | *UserInfo = NULL;\r | |
1301 | return EFI_NOT_FOUND;\r | |
1302 | }\r | |
1303 | Index++;\r | |
1304 | *UserInfo = (EFI_USER_INFO_HANDLE)mUsbInfoHandle->Info[Index];\r | |
1305 | return EFI_SUCCESS; \r | |
1306 | }\r | |
1307 | }\r | |
1308 | \r | |
1309 | *UserInfo = NULL;\r | |
1310 | return EFI_NOT_FOUND;\r | |
1311 | }\r | |
1312 | \r | |
1313 | \r | |
6f0b8648 | 1314 | /**\r |
1315 | Delete a user on this credential provider.\r | |
1316 | \r | |
1317 | This function deletes a user on this credential provider. \r | |
1318 | \r | |
1319 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r | |
1320 | @param[in] User The user profile handle to delete.\r | |
1321 | \r | |
1322 | @retval EFI_SUCCESS User profile was successfully deleted.\r | |
1323 | @retval EFI_ACCESS_DENIED Current user profile does not permit deletion on the user profile handle. \r | |
1324 | Either the user profile cannot delete on any user profile or cannot delete \r | |
1325 | on a user profile other than the current user profile. \r | |
1326 | @retval EFI_UNSUPPORTED This credential provider does not support deletion in the pre-OS.\r | |
1327 | @retval EFI_DEVICE_ERROR The new credential could not be deleted because of a device error.\r | |
1328 | @retval EFI_INVALID_PARAMETER User does not refer to a valid user profile handle.\r | |
1329 | **/\r | |
1330 | EFI_STATUS\r | |
1331 | EFIAPI\r | |
1332 | CredentialDelete (\r | |
1333 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r | |
1334 | IN EFI_USER_PROFILE_HANDLE User\r | |
1335 | )\r | |
1336 | {\r | |
1337 | EFI_STATUS Status;\r | |
1338 | EFI_USER_INFO *UserInfo;\r | |
1339 | UINT8 *UserId;\r | |
1340 | UINT8 *NewUserId;\r | |
1341 | UINTN Index;\r | |
1342 | \r | |
1343 | if ((This == NULL) || (User == NULL)) {\r | |
1344 | return EFI_INVALID_PARAMETER;\r | |
1345 | }\r | |
1346 | \r | |
1347 | //\r | |
1348 | // Get User Identifier.\r | |
1349 | //\r | |
1350 | UserInfo = NULL;\r | |
1351 | Status = FindUserInfoByType (\r | |
1352 | User,\r | |
1353 | EFI_USER_INFO_IDENTIFIER_RECORD,\r | |
1354 | &UserInfo\r | |
1355 | );\r | |
1356 | if (EFI_ERROR (Status)) {\r | |
1357 | return EFI_INVALID_PARAMETER;\r | |
1358 | }\r | |
1359 | \r | |
1360 | //\r | |
1361 | // Find the user by user identifier in mPwdTable.\r | |
1362 | // \r | |
1363 | for (Index = 0; Index < mUsbTable->Count; Index++) {\r | |
1364 | UserId = (UINT8 *) &mUsbTable->UserInfo[Index].UserId;\r | |
1365 | NewUserId = (UINT8 *) (UserInfo + 1);\r | |
1366 | if (CompareMem (UserId, NewUserId, sizeof (EFI_USER_INFO_IDENTIFIER)) == 0) {\r | |
1367 | //\r | |
1368 | // Found the user, delete it.\r | |
1369 | //\r | |
1370 | ModifyTable (Index, NULL);\r | |
1371 | break;\r | |
1372 | }\r | |
1373 | }\r | |
1374 | \r | |
1375 | FreePool (UserInfo);\r | |
1376 | return EFI_SUCCESS;\r | |
1377 | }\r | |
1378 | \r | |
1379 | \r | |
0c18794e | 1380 | /**\r |
1381 | Main entry for this driver.\r | |
1382 | \r | |
1383 | @param ImageHandle Image handle this driver.\r | |
1384 | @param SystemTable Pointer to SystemTable.\r | |
1385 | \r | |
1386 | @retval EFI_SUCESS This function always complete successfully.\r | |
1387 | \r | |
1388 | **/\r | |
1389 | EFI_STATUS\r | |
1390 | EFIAPI\r | |
1391 | UsbProviderInit (\r | |
1392 | IN EFI_HANDLE ImageHandle,\r | |
1393 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
1394 | )\r | |
1395 | {\r | |
1396 | EFI_STATUS Status;\r | |
1397 | \r | |
1398 | //\r | |
1399 | // Init credential table.\r | |
1400 | //\r | |
1401 | Status = InitCredentialTable ();\r | |
1402 | if (EFI_ERROR (Status)) {\r | |
1403 | return Status;\r | |
1404 | }\r | |
1405 | \r | |
1406 | //\r | |
1407 | // Init Form Browser\r | |
1408 | //\r | |
1409 | Status = InitFormBrowser ();\r | |
1410 | if (EFI_ERROR (Status)) {\r | |
1411 | return Status;\r | |
1412 | }\r | |
1413 | \r | |
1414 | //\r | |
1415 | // Install protocol interfaces for the Usb Credential Provider.\r | |
1416 | //\r | |
1417 | Status = gBS->InstallProtocolInterface (\r | |
1418 | &mCallbackInfo->DriverHandle,\r | |
6f0b8648 | 1419 | &gEfiUserCredential2ProtocolGuid,\r |
0c18794e | 1420 | EFI_NATIVE_INTERFACE,\r |
1421 | &gUsbCredentialProviderDriver\r | |
1422 | );\r | |
1423 | return Status;\r | |
1424 | }\r |