2 Usb Credential Provider driver implemenetation.
4 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "UsbCredentialProvider.h"
17 CREDENTIAL_TABLE
*mUsbTable
= NULL
;
18 USB_PROVIDER_CALLBACK_INFO
*mCallbackInfo
= NULL
;
19 USB_CREDENTIAL_INFO
*mUsbInfoHandle
= NULL
;
21 EFI_USER_CREDENTIAL2_PROTOCOL gUsbCredentialProviderDriver
= {
22 USB_CREDENTIAL_PROVIDER_GUID
,
23 EFI_USER_CREDENTIAL_CLASS_SECURE_CARD
,
33 CredentialGetNextInfo
,
34 EFI_CREDENTIAL_CAPABILITIES_ENROLL
,
40 Get string by string id from HII Interface.
43 @param[in] Id String ID to get the string from.
45 @retval CHAR16 * String from ID.
46 @retval NULL If error occurs.
55 // Get the current string for the current Language
57 return HiiGetString (mCallbackInfo
->HiiHandle
, Id
, NULL
);
62 Expand password table size.
70 CREDENTIAL_TABLE
*NewTable
;
73 Count
= mUsbTable
->MaxCount
+ USB_TABLE_INC
;
75 // Create new credential table.
77 NewTable
= AllocateZeroPool (
78 sizeof (CREDENTIAL_TABLE
) - sizeof (USB_INFO
) +
79 Count
* sizeof (USB_INFO
)
81 ASSERT (NewTable
!= NULL
);
83 NewTable
->MaxCount
= Count
;
84 NewTable
->Count
= mUsbTable
->Count
;
92 mUsbTable
->Count
* sizeof (USB_INFO
)
100 Add, update or delete info in table, and sync with NV variable.
102 @param[in] Index The index of the password in table. If index is found in
103 table, update the info, else add the into to table.
104 @param[in] Info The new credential info to add into table. If Info is NULL,
105 delete the info by Index.
107 @retval EFI_INVALID_PARAMETER Info is NULL when save the info.
108 @retval EFI_SUCCESS Modify the table successfully.
109 @retval Others Failed to modify the table.
115 IN USB_INFO
* Info OPTIONAL
119 USB_INFO
*NewUsbInfo
;
122 if (Index
< mUsbTable
->Count
) {
125 // Delete the specified entry.
128 if (Index
!= mUsbTable
->Count
) {
129 NewUsbInfo
= &mUsbTable
->UserInfo
[mUsbTable
->Count
];
133 // Update the specified entry.
142 return EFI_INVALID_PARAMETER
;
145 if (mUsbTable
->Count
>= mUsbTable
->MaxCount
) {
153 if (NewUsbInfo
!= NULL
) {
154 CopyMem (&mUsbTable
->UserInfo
[Index
], NewUsbInfo
, sizeof (USB_INFO
));
158 // Save the credential table.
160 Status
= gRT
->SetVariable (
162 &gUsbCredentialProviderGuid
,
163 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
164 mUsbTable
->Count
* sizeof (USB_INFO
),
172 Create a credential table
174 @retval EFI_SUCCESS Create a credential table successfully.
175 @retval Others Failed to create a password.
179 InitCredentialTable (
188 // Get Usb credential data from NV variable.
192 Status
= gRT
->GetVariable (
194 &gUsbCredentialProviderGuid
,
199 if (Status
== EFI_BUFFER_TOO_SMALL
) {
200 Var
= AllocateZeroPool (VarSize
);
202 return EFI_OUT_OF_RESOURCES
;
204 Status
= gRT
->GetVariable (
206 &gUsbCredentialProviderGuid
,
212 if (EFI_ERROR (Status
) && (Status
!= EFI_NOT_FOUND
)) {
217 // Init Usb credential table.
219 mUsbTable
= AllocateZeroPool (
220 sizeof (CREDENTIAL_TABLE
) - sizeof (USB_INFO
) +
221 USB_TABLE_INC
* sizeof (USB_INFO
) +
224 if (mUsbTable
== NULL
) {
226 return EFI_OUT_OF_RESOURCES
;
229 mUsbTable
->Count
= VarSize
/ sizeof (USB_INFO
);
230 mUsbTable
->MaxCount
= mUsbTable
->Count
+ USB_TABLE_INC
;
232 CopyMem (mUsbTable
->UserInfo
, Var
, VarSize
);
240 Read the specified file by FileName in the Usb key and return the file size in BufferSize
241 and file content in Buffer.
242 Note: the caller is responsible to free the buffer memory.
244 @param FileName File to read.
245 @param Buffer Returned with data read from the file.
246 @param BufferSize Size of the data buffer.
248 @retval EFI_SUCCESS The command completed successfully.
249 @retval EFI_OUT_OF_RESOURCES Resource allocation failed.
250 @retval EFI_NOT_FOUND File not found.
251 @retval EFI_DEVICE_ERROR Device I/O error.
258 OUT UINTN
*BufferSize
264 UINTN ScratchBufferSize
;
265 EFI_HANDLE
*HandleBuffer
;
267 EFI_FILE
*FileHandle
;
268 EFI_FILE_INFO
*FileInfo
;
269 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*SimpleFileSystem
;
270 EFI_BLOCK_IO_PROTOCOL
*BlkIo
;
275 Status
= gBS
->LocateHandleBuffer (
277 &gEfiSimpleFileSystemProtocolGuid
,
282 if (EFI_ERROR (Status
)) {
283 DEBUG ((DEBUG_ERROR
, "Can not Locate SimpleFileSystemProtocol\n"));
288 // Find and open the file in removable media disk.
290 for (Index
= 0; Index
< HandleCount
; Index
++) {
291 Status
= gBS
->HandleProtocol (
293 &gEfiBlockIoProtocolGuid
,
296 if (EFI_ERROR (Status
)) {
300 if (BlkIo
->Media
->RemovableMedia
) {
301 Status
= gBS
->HandleProtocol (
303 &gEfiSimpleFileSystemProtocolGuid
,
304 (VOID
**) &SimpleFileSystem
306 if (EFI_ERROR (Status
)) {
310 Status
= SimpleFileSystem
->OpenVolume (
314 if (EFI_ERROR (Status
)) {
318 Status
= RootFs
->Open (
325 if (!EFI_ERROR (Status
)) {
331 FreePool (HandleBuffer
);
333 if (Index
>= HandleCount
) {
334 DEBUG ((DEBUG_ERROR
, "Can not found the token file!\n"));
335 Status
= EFI_NOT_FOUND
;
340 // Figure out how big the file is.
342 ScratchBufferSize
= 0;
343 Status
= FileHandle
->GetInfo (
349 if (EFI_ERROR (Status
) && (Status
!= EFI_BUFFER_TOO_SMALL
)) {
350 DEBUG ((DEBUG_ERROR
, "Can not obtain file size info!\n"));
351 Status
= EFI_DEVICE_ERROR
;
355 FileInfo
= AllocateZeroPool (ScratchBufferSize
);
356 if (FileInfo
== NULL
) {
357 DEBUG ((DEBUG_ERROR
, "Can not allocate enough memory for the token file!\n"));
358 Status
= EFI_OUT_OF_RESOURCES
;
362 Status
= FileHandle
->GetInfo (
368 if (EFI_ERROR (Status
)) {
369 DEBUG ((DEBUG_ERROR
, "Can not obtain file info from the token file!\n"));
370 Status
= EFI_DEVICE_ERROR
;
375 // Allocate a buffer for the file.
377 *BufferSize
= (UINT32
) FileInfo
->FileSize
;
378 *Buffer
= AllocateZeroPool (*BufferSize
);
379 if (*Buffer
== NULL
) {
380 DEBUG ((DEBUG_ERROR
, "Can not allocate a buffer for the file!\n"));
381 Status
= EFI_OUT_OF_RESOURCES
;
386 // Load file into the allocated memory.
388 Status
= FileHandle
->Read (FileHandle
, BufferSize
, *Buffer
);
389 if (EFI_ERROR (Status
)) {
391 DEBUG ((DEBUG_ERROR
, "Can not read the token file!\n"));
392 Status
= EFI_DEVICE_ERROR
;
399 Status
= FileHandle
->Close (FileHandle
);
400 if (EFI_ERROR (Status
)) {
402 DEBUG ((DEBUG_ERROR
, "Can not close the token file !\n"));
403 Status
= EFI_DEVICE_ERROR
;
408 if (FileInfo
!= NULL
) {
417 Hash the data to get credential.
419 @param[in] Buffer Points to the data buffer
420 @param[in] BufferSize The size of data in buffer, in bytes.
421 @param[out] Credential Points to the hashed result
423 @retval TRUE Hash the data successfully.
424 @retval FALSE Failed to hash the data.
431 OUT UINT8
*Credential
438 HashSize
= Sha1GetContextSize ();
439 Hash
= AllocatePool (HashSize
);
440 ASSERT (Hash
!= NULL
);
442 Status
= Sha1Init (Hash
);
447 Status
= Sha1Update (Hash
, Buffer
, BufferSize
);
452 Status
= Sha1Final (Hash
, Credential
);
461 Read the token file, and default the Token is saved at the begining of the file.
463 @param[out] Token Token read from a Token file.
465 @retval EFI_SUCCESS Read a Token successfully.
466 @retval Others Fails to read a Token.
481 TokenFile
= FixedPcdGetPtr (PcdFixedUsbCredentialProviderTokenFileName
);
482 Status
= GetFileData (TokenFile
, (VOID
*)&Buffer
, &BufSize
);
483 if (EFI_ERROR (Status
)) {
484 DEBUG ((DEBUG_ERROR
, "Read file %s from USB error! Status=(%r)\n", TokenFile
, Status
));
488 if (!GenerateCredential (Buffer
, BufSize
, Token
)) {
489 DEBUG ((DEBUG_ERROR
, "Generate credential from read data failed!\n"));
491 return EFI_SECURITY_VIOLATION
;
500 Find a user infomation record by the information record type.
502 This function searches all user information records of User from beginning
503 until either the information is found or there are no more user infomation
504 record. A match occurs when a Info.InfoType field matches the user information
507 @param[in] User Points to the user profile record to search.
508 @param[in] InfoType The infomation type to be searched.
509 @param[out] Info Points to the user info found, the caller is responsible
512 @retval EFI_SUCCESS Find the user information successfully.
513 @retval Others Fail to find the user information.
518 IN EFI_USER_PROFILE_HANDLE User
,
520 OUT EFI_USER_INFO
**Info
524 EFI_USER_INFO
*UserInfo
;
526 EFI_USER_INFO_HANDLE UserInfoHandle
;
527 EFI_USER_MANAGER_PROTOCOL
*UserManager
;
530 // Find user information by information type.
533 return EFI_INVALID_PARAMETER
;
536 Status
= gBS
->LocateProtocol (
537 &gEfiUserManagerProtocolGuid
,
539 (VOID
**) &UserManager
541 if (EFI_ERROR (Status
)) {
542 return EFI_NOT_FOUND
;
546 // Get each user information.
549 UserInfoHandle
= NULL
;
553 Status
= UserManager
->GetNextInfo (UserManager
, User
, &UserInfoHandle
);
554 if (EFI_ERROR (Status
)) {
560 Status
= UserManager
->GetInfo (
567 if (Status
== EFI_BUFFER_TOO_SMALL
) {
568 if (UserInfo
!= NULL
) {
571 UserInfo
= AllocateZeroPool (UserInfoSize
);
572 if (UserInfo
== NULL
) {
573 return EFI_OUT_OF_RESOURCES
;
575 Status
= UserManager
->GetInfo (
583 if (EFI_ERROR (Status
)) {
587 ASSERT (UserInfo
!= NULL
);
588 if (UserInfo
->InfoType
== InfoType
) {
594 if (UserInfo
!= NULL
) {
602 This function initialize the data mainly used in form browser.
604 @retval EFI_SUCCESS Initialize form data successfully.
605 @retval Others Fail to Initialize form data.
613 USB_PROVIDER_CALLBACK_INFO
*CallbackInfo
;
616 // Initialize driver private data.
618 CallbackInfo
= AllocateZeroPool (sizeof (USB_PROVIDER_CALLBACK_INFO
));
619 if (CallbackInfo
== NULL
) {
620 return EFI_OUT_OF_RESOURCES
;
623 CallbackInfo
->DriverHandle
= NULL
;
628 CallbackInfo
->HiiHandle
= HiiAddPackages (
629 &gUsbCredentialProviderGuid
,
630 CallbackInfo
->DriverHandle
,
631 UsbCredentialProviderStrings
,
634 if (CallbackInfo
->HiiHandle
== NULL
) {
635 return EFI_OUT_OF_RESOURCES
;
637 mCallbackInfo
= CallbackInfo
;
644 Enroll a user on a credential provider.
646 This function enrolls a user on this credential provider. If the user exists on
647 this credential provider, update the user information on this credential provider;
648 otherwise add the user information on credential provider.
650 @param[in] This Points to this instance of EFI_USER_CREDENTIAL2_PROTOCOL.
651 @param[in] User The user profile to enroll.
653 @retval EFI_SUCCESS User profile was successfully enrolled.
654 @retval EFI_ACCESS_DENIED Current user profile does not permit enrollment on the
655 user profile handle. Either the user profile cannot enroll
656 on any user profile or cannot enroll on a user profile
657 other than the current user profile.
658 @retval EFI_UNSUPPORTED This credential provider does not support enrollment in
660 @retval EFI_DEVICE_ERROR The new credential could not be created because of a device
662 @retval EFI_INVALID_PARAMETER User does not refer to a valid user profile handle.
668 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL
*This
,
669 IN EFI_USER_PROFILE_HANDLE User
675 EFI_USER_INFO
*UserInfo
;
677 EFI_USER_MANAGER_PROTOCOL
*UserManager
;
682 if ((This
== NULL
) || (User
== NULL
)) {
683 return EFI_INVALID_PARAMETER
;
686 Status
= gBS
->LocateProtocol (
687 &gEfiUserManagerProtocolGuid
,
689 (VOID
**) &UserManager
691 if (EFI_ERROR (Status
)) {
692 return EFI_UNSUPPORTED
;
696 // Get User Identifier
699 Status
= FindUserInfoByType (
701 EFI_USER_INFO_IDENTIFIER_RECORD
,
704 if (EFI_ERROR (Status
)) {
705 return EFI_INVALID_PARAMETER
;
708 CopyMem (UsbInfo
.UserId
, (UINT8
*) (UserInfo
+ 1), sizeof (EFI_USER_INFO_IDENTIFIER
));
712 // Get Token and User ID to UsbInfo.
714 Status
= GetToken (UsbInfo
.Token
);
715 if (EFI_ERROR (Status
)) {
716 QuestionStr
= GetStringById (STRING_TOKEN (STR_READ_USB_TOKEN_ERROR
));
717 PromptStr
= GetStringById (STRING_TOKEN (STR_INSERT_USB_TOKEN
));
719 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
726 FreePool (QuestionStr
);
727 FreePool (PromptStr
);
732 // Check whether User is ever enrolled in the provider.
734 for (Index
= 0; Index
< mUsbTable
->Count
; Index
++) {
735 UserId
= (UINT8
*) &mUsbTable
->UserInfo
[Index
].UserId
;
736 if (CompareMem (UserId
, (UINT8
*) &UsbInfo
.UserId
, sizeof (EFI_USER_INFO_IDENTIFIER
)) == 0) {
738 // User already exists, update the password.
745 // Enroll the User to the provider.
747 Status
= ModifyTable (Index
, &UsbInfo
);
748 if (EFI_ERROR (Status
)) {
753 // Notify the user manager driver that credential information has changed.
755 UserManager
->Notify (UserManager
, mCallbackInfo
->DriverHandle
);
762 Returns the user interface information used during user identification.
764 This function returns information about the form used when interacting with the
765 user during user identification. The form is the first enabled form in the form-set
766 class EFI_HII_USER_CREDENTIAL_FORMSET_GUID installed on the HII handle HiiHandle. If
767 the user credential provider does not require a form to identify the user, then this
768 function should return EFI_NOT_FOUND.
770 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
771 @param[out] Hii On return, holds the HII database handle.
772 @param[out] FormSetId On return, holds the identifier of the form set which contains
773 the form used during user identification.
774 @param[out] FormId On return, holds the identifier of the form used during user
777 @retval EFI_SUCCESS Form returned successfully.
778 @retval EFI_NOT_FOUND Form not returned.
779 @retval EFI_INVALID_PARAMETER Hii is NULL or FormSetId is NULL or FormId is NULL.
785 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL
*This
,
786 OUT EFI_HII_HANDLE
*Hii
,
787 OUT EFI_GUID
*FormSetId
,
788 OUT EFI_FORM_ID
*FormId
791 if ((This
== NULL
) || (Hii
== NULL
) ||
792 (FormSetId
== NULL
) || (FormId
== NULL
)) {
793 return EFI_INVALID_PARAMETER
;
795 return EFI_NOT_FOUND
;
800 Returns bitmap used to describe the credential provider type.
802 This optional function returns a bitmap which is less than or equal to the number
803 of pixels specified by Width and Height. If no such bitmap exists, then EFI_NOT_FOUND
806 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
807 @param[in, out] Width On entry, points to the desired bitmap width. If NULL then no
808 bitmap information will be returned. On exit, points to the
809 width of the bitmap returned.
810 @param[in, out] Height On entry, points to the desired bitmap height. If NULL then no
811 bitmap information will be returned. On exit, points to the
812 height of the bitmap returned.
813 @param[out] Hii On return, holds the HII database handle.
814 @param[out] Image On return, holds the HII image identifier.
816 @retval EFI_SUCCESS Image identifier returned successfully.
817 @retval EFI_NOT_FOUND Image identifier not returned.
818 @retval EFI_INVALID_PARAMETER Hii is NULL or Image is NULL.
824 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL
*This
,
826 IN OUT UINTN
*Height
,
827 OUT EFI_HII_HANDLE
*Hii
,
828 OUT EFI_IMAGE_ID
*Image
831 if ((This
== NULL
) || (Hii
== NULL
) || (Image
== NULL
)) {
832 return EFI_INVALID_PARAMETER
;
834 return EFI_NOT_FOUND
;
839 Returns string used to describe the credential provider type.
841 This function returns a string which describes the credential provider. If no
842 such string exists, then EFI_NOT_FOUND is returned.
844 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
845 @param[out] Hii On return, holds the HII database handle.
846 @param[out] String On return, holds the HII string identifier.
848 @retval EFI_SUCCESS String identifier returned successfully.
849 @retval EFI_NOT_FOUND String identifier not returned.
850 @retval EFI_INVALID_PARAMETER Hii is NULL or String is NULL.
856 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL
*This
,
857 OUT EFI_HII_HANDLE
*Hii
,
858 OUT EFI_STRING_ID
*String
861 if ((This
== NULL
) || (Hii
== NULL
) || (String
== NULL
)) {
862 return EFI_INVALID_PARAMETER
;
865 // Set Hii handle and String ID.
867 *Hii
= mCallbackInfo
->HiiHandle
;
868 *String
= STRING_TOKEN (STR_CREDENTIAL_TITLE
);
875 Return the user identifier associated with the currently authenticated user.
877 This function returns the user identifier of the user authenticated by this credential
878 provider. This function is called after the credential-related information has been
879 submitted on a form OR after a call to Default() has returned that this credential is
882 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
883 @param[in] User The user profile handle of the user profile currently being
884 considered by the user identity manager. If NULL, then no user
885 profile is currently under consideration.
886 @param[out] Identifier On return, points to the user identifier.
888 @retval EFI_SUCCESS User identifier returned successfully.
889 @retval EFI_NOT_READY No user identifier can be returned.
890 @retval EFI_ACCESS_DENIED The user has been locked out of this user credential.
891 @retval EFI_INVALID_PARAMETER This is NULL, or Identifier is NULL.
892 @retval EFI_NOT_FOUND User is not NULL, and the specified user handle can't be
893 found in user profile database.
899 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL
*This
,
900 IN EFI_USER_PROFILE_HANDLE User
,
901 OUT EFI_USER_INFO_IDENTIFIER
*Identifier
906 EFI_USER_INFO
*UserInfo
;
910 UINT8 ReadToken
[HASHED_CREDENTIAL_LEN
];
916 if ((This
== NULL
) || (Identifier
== NULL
)) {
917 return EFI_INVALID_PARAMETER
;
922 // Verify the auto logon user, get user id by matched token.
924 if (mUsbTable
->Count
== 0) {
925 return EFI_NOT_READY
;
929 // No user selected, get token first and verify the user existed in user database.
931 Status
= GetToken (ReadToken
);
932 if (EFI_ERROR (Status
)) {
933 return EFI_NOT_READY
;
936 for (Index
= 0; Index
< mUsbTable
->Count
; Index
++) {
938 // find the specified credential in the Usb credential database.
940 UserToken
= mUsbTable
->UserInfo
[Index
].Token
;
941 if (CompareMem (UserToken
, ReadToken
, HASHED_CREDENTIAL_LEN
) == 0) {
942 UserId
= (UINT8
*) &mUsbTable
->UserInfo
[Index
].UserId
;
943 CopyMem (Identifier
, UserId
, sizeof (EFI_USER_INFO_IDENTIFIER
));
948 return EFI_NOT_READY
;
952 // User is not NULL here. Read a token, and check whether the token matches with
953 // the selected user's Token. If not, try to find a token in token DB to matches
957 Status
= GetToken (ReadToken
);
958 if (EFI_ERROR (Status
)) {
959 QuestionStr
= GetStringById (STRING_TOKEN (STR_READ_USB_TOKEN_ERROR
));
960 PromptStr
= GetStringById (STRING_TOKEN (STR_INSERT_USB_TOKEN
));
961 OldTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
962 gBS
->RestoreTPL (TPL_APPLICATION
);
964 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
971 gBS
->RaiseTPL (OldTpl
);
972 FreePool (QuestionStr
);
973 FreePool (PromptStr
);
974 return EFI_NOT_FOUND
;
978 // Get the selected user's identifier.
980 Status
= FindUserInfoByType (User
, EFI_USER_INFO_IDENTIFIER_RECORD
, &UserInfo
);
981 if (EFI_ERROR (Status
)) {
982 return EFI_NOT_FOUND
;
986 // Check the selected user's Token with the read token.
988 for (Index
= 0; Index
< mUsbTable
->Count
; Index
++) {
989 UserId
= (UINT8
*) &mUsbTable
->UserInfo
[Index
].UserId
;
990 NewUserId
= (UINT8
*) (UserInfo
+ 1);
991 if (CompareMem (UserId
, NewUserId
, sizeof (EFI_USER_INFO_IDENTIFIER
)) == 0) {
993 // The user's ID is found in the UsbTable.
995 UserToken
= mUsbTable
->UserInfo
[Index
].Token
;
996 if (CompareMem (UserToken
, ReadToken
, HASHED_CREDENTIAL_LEN
) == 0) {
998 // The read token matches with the one in UsbTable.
1000 CopyMem (Identifier
, UserId
, sizeof (EFI_USER_INFO_IDENTIFIER
));
1001 FreePool (UserInfo
);
1007 FreePool (UserInfo
);
1009 return EFI_NOT_READY
;
1014 Indicate that user interface interaction has begun for the specified credential.
1016 This function is called when a credential provider is selected by the user. If
1017 AutoLogon returns FALSE, then the user interface will be constructed by the User
1020 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
1021 @param[out] AutoLogon On return, points to the credential provider's capabilities
1022 after the credential provider has been selected by the user.
1024 @retval EFI_SUCCESS Credential provider successfully selected.
1025 @retval EFI_INVALID_PARAMETER AutoLogon is NULL.
1031 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL
*This
,
1032 OUT EFI_CREDENTIAL_LOGON_FLAGS
*AutoLogon
1035 if ((This
== NULL
) || (AutoLogon
== NULL
)) {
1036 return EFI_INVALID_PARAMETER
;
1039 *AutoLogon
= EFI_CREDENTIAL_LOGON_FLAG_DEFAULT
| EFI_CREDENTIAL_LOGON_FLAG_AUTO
;
1046 Indicate that user interface interaction has ended for the specified credential.
1048 This function is called when a credential provider is deselected by the user.
1050 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
1052 @retval EFI_SUCCESS Credential provider successfully deselected.
1057 CredentialDeselect (
1058 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL
*This
1062 return EFI_INVALID_PARAMETER
;
1069 Return the default logon behavior for this user credential.
1071 This function reports the default login behavior regarding this credential provider.
1073 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
1074 @param[out] AutoLogon On return, holds whether the credential provider should be used
1075 by default to automatically log on the user.
1077 @retval EFI_SUCCESS Default information successfully returned.
1078 @retval EFI_INVALID_PARAMETER AutoLogon is NULL.
1084 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL
*This
,
1085 OUT EFI_CREDENTIAL_LOGON_FLAGS
*AutoLogon
1088 if ((This
== NULL
) || (AutoLogon
== NULL
)) {
1089 return EFI_INVALID_PARAMETER
;
1092 *AutoLogon
= EFI_CREDENTIAL_LOGON_FLAG_DEFAULT
| EFI_CREDENTIAL_LOGON_FLAG_AUTO
;
1098 Return information attached to the credential provider.
1100 This function returns user information.
1102 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
1103 @param[in] UserInfo Handle of the user information data record.
1104 @param[out] Info On entry, points to a buffer of at least *InfoSize bytes. On
1105 exit, holds the user information. If the buffer is too small
1106 to hold the information, then EFI_BUFFER_TOO_SMALL is returned
1107 and InfoSize is updated to contain the number of bytes actually
1109 @param[in, out] InfoSize On entry, points to the size of Info. On return, points to the
1110 size of the user information.
1112 @retval EFI_SUCCESS Information returned successfully.
1113 @retval EFI_BUFFER_TOO_SMALL The size specified by InfoSize is too small to hold all of the
1114 user information. The size required is returned in *InfoSize.
1115 @retval EFI_INVALID_PARAMETER Info is NULL or InfoSize is NULL.
1116 @retval EFI_NOT_FOUND The specified UserInfo does not refer to a valid user info handle.
1122 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL
*This
,
1123 IN EFI_USER_INFO_HANDLE UserInfo
,
1124 OUT EFI_USER_INFO
*Info
,
1125 IN OUT UINTN
*InfoSize
1128 EFI_USER_INFO
*CredentialInfo
;
1131 if ((This
== NULL
) || (InfoSize
== NULL
) || (Info
== NULL
)) {
1132 return EFI_INVALID_PARAMETER
;
1135 if ((UserInfo
== NULL
) || (mUsbInfoHandle
== NULL
)) {
1136 return EFI_NOT_FOUND
;
1140 // Find information handle in credential info table.
1142 for (Index
= 0; Index
< mUsbInfoHandle
->Count
; Index
++) {
1143 CredentialInfo
= mUsbInfoHandle
->Info
[Index
];
1144 if (UserInfo
== (EFI_USER_INFO_HANDLE
)CredentialInfo
) {
1146 // The handle is found, copy the user info.
1148 if (CredentialInfo
->InfoSize
> *InfoSize
) {
1149 *InfoSize
= CredentialInfo
->InfoSize
;
1150 return EFI_BUFFER_TOO_SMALL
;
1153 CopyMem (Info
, CredentialInfo
, CredentialInfo
->InfoSize
);
1158 return EFI_NOT_FOUND
;
1163 Enumerate all of the user informations on the credential provider.
1165 This function returns the next user information record. To retrieve the first user
1166 information record handle, point UserInfo at a NULL. Each subsequent call will retrieve
1167 another user information record handle until there are no more, at which point UserInfo
1170 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
1171 @param[in, out] UserInfo On entry, points to the previous user information handle or NULL
1172 to start enumeration. On exit, points to the next user information
1173 handle or NULL if there is no more user information.
1175 @retval EFI_SUCCESS User information returned.
1176 @retval EFI_NOT_FOUND No more user information found.
1177 @retval EFI_INVALID_PARAMETER UserInfo is NULL.
1182 CredentialGetNextInfo (
1183 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL
*This
,
1184 IN OUT EFI_USER_INFO_HANDLE
*UserInfo
1187 EFI_USER_INFO
*Info
;
1188 CHAR16
*ProvNameStr
;
1193 if ((This
== NULL
) || (UserInfo
== NULL
)) {
1194 return EFI_INVALID_PARAMETER
;
1197 if (mUsbInfoHandle
== NULL
) {
1199 // Initilized user info table. There are 4 user info records in the table.
1201 InfoLen
= sizeof (USB_CREDENTIAL_INFO
) + (4 - 1) * sizeof (EFI_USER_INFO
*);
1202 mUsbInfoHandle
= AllocateZeroPool (InfoLen
);
1203 if (mUsbInfoHandle
== NULL
) {
1205 return EFI_NOT_FOUND
;
1209 // The first information, Credential Provider info.
1211 InfoLen
= sizeof (EFI_USER_INFO
) + sizeof (EFI_GUID
);
1212 Info
= AllocateZeroPool (InfoLen
);
1213 ASSERT (Info
!= NULL
);
1215 Info
->InfoType
= EFI_USER_INFO_CREDENTIAL_PROVIDER_RECORD
;
1216 Info
->InfoSize
= (UINT32
) InfoLen
;
1217 Info
->InfoAttribs
= EFI_USER_INFO_PROTECTED
;
1218 CopyGuid (&Info
->Credential
, &gUsbCredentialProviderGuid
);
1219 CopyGuid ((EFI_GUID
*)(Info
+ 1), &gUsbCredentialProviderGuid
);
1221 mUsbInfoHandle
->Info
[0] = Info
;
1222 mUsbInfoHandle
->Count
++;
1225 // The second information, Credential Provider name info.
1227 ProvNameStr
= GetStringById (STRING_TOKEN (STR_PROVIDER_NAME
));
1228 ProvStrLen
= StrSize (ProvNameStr
);
1229 InfoLen
= sizeof (EFI_USER_INFO
) + ProvStrLen
;
1230 Info
= AllocateZeroPool (InfoLen
);
1231 ASSERT (Info
!= NULL
);
1233 Info
->InfoType
= EFI_USER_INFO_CREDENTIAL_PROVIDER_NAME_RECORD
;
1234 Info
->InfoSize
= (UINT32
) InfoLen
;
1235 Info
->InfoAttribs
= EFI_USER_INFO_PROTECTED
;
1236 CopyGuid (&Info
->Credential
, &gUsbCredentialProviderGuid
);
1237 CopyMem ((UINT8
*)(Info
+ 1), ProvNameStr
, ProvStrLen
);
1238 FreePool (ProvNameStr
);
1240 mUsbInfoHandle
->Info
[1] = Info
;
1241 mUsbInfoHandle
->Count
++;
1244 // The third information, Credential Provider type info.
1246 InfoLen
= sizeof (EFI_USER_INFO
) + sizeof (EFI_GUID
);
1247 Info
= AllocateZeroPool (InfoLen
);
1248 ASSERT (Info
!= NULL
);
1250 Info
->InfoType
= EFI_USER_INFO_CREDENTIAL_TYPE_RECORD
;
1251 Info
->InfoSize
= (UINT32
) InfoLen
;
1252 Info
->InfoAttribs
= EFI_USER_INFO_PROTECTED
;
1253 CopyGuid (&Info
->Credential
, &gUsbCredentialProviderGuid
);
1254 CopyGuid ((EFI_GUID
*)(Info
+ 1), &gEfiUserCredentialClassSecureCardGuid
);
1256 mUsbInfoHandle
->Info
[2] = Info
;
1257 mUsbInfoHandle
->Count
++;
1260 // The fourth information, Credential Provider type name info.
1262 ProvNameStr
= GetStringById (STRING_TOKEN (STR_PROVIDER_TYPE_NAME
));
1263 ProvStrLen
= StrSize (ProvNameStr
);
1264 InfoLen
= sizeof (EFI_USER_INFO
) + ProvStrLen
;
1265 Info
= AllocateZeroPool (InfoLen
);
1266 ASSERT (Info
!= NULL
);
1268 Info
->InfoType
= EFI_USER_INFO_CREDENTIAL_PROVIDER_NAME_RECORD
;
1269 Info
->InfoSize
= (UINT32
) InfoLen
;
1270 Info
->InfoAttribs
= EFI_USER_INFO_PROTECTED
;
1271 CopyGuid (&Info
->Credential
, &gUsbCredentialProviderGuid
);
1272 CopyMem ((UINT8
*)(Info
+ 1), ProvNameStr
, ProvStrLen
);
1273 FreePool (ProvNameStr
);
1275 mUsbInfoHandle
->Info
[3] = Info
;
1276 mUsbInfoHandle
->Count
++;
1279 if (*UserInfo
== NULL
) {
1281 // Return the first info handle.
1283 *UserInfo
= (EFI_USER_INFO_HANDLE
) mUsbInfoHandle
->Info
[0];
1288 // Find information handle in credential info table.
1290 for (Index
= 0; Index
< mUsbInfoHandle
->Count
; Index
++) {
1291 Info
= mUsbInfoHandle
->Info
[Index
];
1292 if (*UserInfo
== (EFI_USER_INFO_HANDLE
)Info
) {
1294 // The handle is found, get the next one.
1296 if (Index
== mUsbInfoHandle
->Count
- 1) {
1298 // Already last one.
1301 return EFI_NOT_FOUND
;
1304 *UserInfo
= (EFI_USER_INFO_HANDLE
)mUsbInfoHandle
->Info
[Index
];
1310 return EFI_NOT_FOUND
;
1315 Delete a user on this credential provider.
1317 This function deletes a user on this credential provider.
1319 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
1320 @param[in] User The user profile handle to delete.
1322 @retval EFI_SUCCESS User profile was successfully deleted.
1323 @retval EFI_ACCESS_DENIED Current user profile does not permit deletion on the user profile handle.
1324 Either the user profile cannot delete on any user profile or cannot delete
1325 on a user profile other than the current user profile.
1326 @retval EFI_UNSUPPORTED This credential provider does not support deletion in the pre-OS.
1327 @retval EFI_DEVICE_ERROR The new credential could not be deleted because of a device error.
1328 @retval EFI_INVALID_PARAMETER User does not refer to a valid user profile handle.
1333 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL
*This
,
1334 IN EFI_USER_PROFILE_HANDLE User
1338 EFI_USER_INFO
*UserInfo
;
1343 if ((This
== NULL
) || (User
== NULL
)) {
1344 return EFI_INVALID_PARAMETER
;
1348 // Get User Identifier.
1351 Status
= FindUserInfoByType (
1353 EFI_USER_INFO_IDENTIFIER_RECORD
,
1356 if (EFI_ERROR (Status
)) {
1357 return EFI_INVALID_PARAMETER
;
1361 // Find the user by user identifier in mPwdTable.
1363 for (Index
= 0; Index
< mUsbTable
->Count
; Index
++) {
1364 UserId
= (UINT8
*) &mUsbTable
->UserInfo
[Index
].UserId
;
1365 NewUserId
= (UINT8
*) (UserInfo
+ 1);
1366 if (CompareMem (UserId
, NewUserId
, sizeof (EFI_USER_INFO_IDENTIFIER
)) == 0) {
1368 // Found the user, delete it.
1370 ModifyTable (Index
, NULL
);
1375 FreePool (UserInfo
);
1381 Main entry for this driver.
1383 @param ImageHandle Image handle this driver.
1384 @param SystemTable Pointer to SystemTable.
1386 @retval EFI_SUCESS This function always complete successfully.
1392 IN EFI_HANDLE ImageHandle
,
1393 IN EFI_SYSTEM_TABLE
*SystemTable
1399 // Init credential table.
1401 Status
= InitCredentialTable ();
1402 if (EFI_ERROR (Status
)) {
1407 // Init Form Browser
1409 Status
= InitFormBrowser ();
1410 if (EFI_ERROR (Status
)) {
1415 // Install protocol interfaces for the Usb Credential Provider.
1417 Status
= gBS
->InstallProtocolInterface (
1418 &mCallbackInfo
->DriverHandle
,
1419 &gEfiUserCredential2ProtocolGuid
,
1420 EFI_NATIVE_INTERFACE
,
1421 &gUsbCredentialProviderDriver