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