2 Usb Credential Provider driver implemenetation.
4 Copyright (c) 2009 - 2014, 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
= PcdGetPtr (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
;
681 if ((This
== NULL
) || (User
== NULL
)) {
682 return EFI_INVALID_PARAMETER
;
686 // Get User Identifier
689 Status
= FindUserInfoByType (
691 EFI_USER_INFO_IDENTIFIER_RECORD
,
694 if (EFI_ERROR (Status
)) {
695 return EFI_INVALID_PARAMETER
;
698 CopyMem (UsbInfo
.UserId
, (UINT8
*) (UserInfo
+ 1), sizeof (EFI_USER_INFO_IDENTIFIER
));
702 // Get Token and User ID to UsbInfo.
704 Status
= GetToken (UsbInfo
.Token
);
705 if (EFI_ERROR (Status
)) {
706 QuestionStr
= GetStringById (STRING_TOKEN (STR_READ_USB_TOKEN_ERROR
));
707 PromptStr
= GetStringById (STRING_TOKEN (STR_INSERT_USB_TOKEN
));
709 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
716 FreePool (QuestionStr
);
717 FreePool (PromptStr
);
722 // Check whether User is ever enrolled in the provider.
724 for (Index
= 0; Index
< mUsbTable
->Count
; Index
++) {
725 UserId
= (UINT8
*) &mUsbTable
->UserInfo
[Index
].UserId
;
726 if (CompareMem (UserId
, (UINT8
*) &UsbInfo
.UserId
, sizeof (EFI_USER_INFO_IDENTIFIER
)) == 0) {
728 // User already exists, update the password.
735 // Enroll the User to the provider.
737 Status
= ModifyTable (Index
, &UsbInfo
);
738 if (EFI_ERROR (Status
)) {
747 Returns the user interface information used during user identification.
749 This function returns information about the form used when interacting with the
750 user during user identification. The form is the first enabled form in the form-set
751 class EFI_HII_USER_CREDENTIAL_FORMSET_GUID installed on the HII handle HiiHandle. If
752 the user credential provider does not require a form to identify the user, then this
753 function should return EFI_NOT_FOUND.
755 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
756 @param[out] Hii On return, holds the HII database handle.
757 @param[out] FormSetId On return, holds the identifier of the form set which contains
758 the form used during user identification.
759 @param[out] FormId On return, holds the identifier of the form used during user
762 @retval EFI_SUCCESS Form returned successfully.
763 @retval EFI_NOT_FOUND Form not returned.
764 @retval EFI_INVALID_PARAMETER Hii is NULL or FormSetId is NULL or FormId is NULL.
770 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL
*This
,
771 OUT EFI_HII_HANDLE
*Hii
,
772 OUT EFI_GUID
*FormSetId
,
773 OUT EFI_FORM_ID
*FormId
776 if ((This
== NULL
) || (Hii
== NULL
) ||
777 (FormSetId
== NULL
) || (FormId
== NULL
)) {
778 return EFI_INVALID_PARAMETER
;
780 return EFI_NOT_FOUND
;
785 Returns bitmap used to describe the credential provider type.
787 This optional function returns a bitmap which is less than or equal to the number
788 of pixels specified by Width and Height. If no such bitmap exists, then EFI_NOT_FOUND
791 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
792 @param[in, out] Width On entry, points to the desired bitmap width. If NULL then no
793 bitmap information will be returned. On exit, points to the
794 width of the bitmap returned.
795 @param[in, out] Height On entry, points to the desired bitmap height. If NULL then no
796 bitmap information will be returned. On exit, points to the
797 height of the bitmap returned.
798 @param[out] Hii On return, holds the HII database handle.
799 @param[out] Image On return, holds the HII image identifier.
801 @retval EFI_SUCCESS Image identifier returned successfully.
802 @retval EFI_NOT_FOUND Image identifier not returned.
803 @retval EFI_INVALID_PARAMETER Hii is NULL or Image is NULL.
809 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL
*This
,
811 IN OUT UINTN
*Height
,
812 OUT EFI_HII_HANDLE
*Hii
,
813 OUT EFI_IMAGE_ID
*Image
816 if ((This
== NULL
) || (Hii
== NULL
) || (Image
== NULL
)) {
817 return EFI_INVALID_PARAMETER
;
819 return EFI_NOT_FOUND
;
824 Returns string used to describe the credential provider type.
826 This function returns a string which describes the credential provider. If no
827 such string exists, then EFI_NOT_FOUND is returned.
829 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
830 @param[out] Hii On return, holds the HII database handle.
831 @param[out] String On return, holds the HII string identifier.
833 @retval EFI_SUCCESS String identifier returned successfully.
834 @retval EFI_NOT_FOUND String identifier not returned.
835 @retval EFI_INVALID_PARAMETER Hii is NULL or String is NULL.
841 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL
*This
,
842 OUT EFI_HII_HANDLE
*Hii
,
843 OUT EFI_STRING_ID
*String
846 if ((This
== NULL
) || (Hii
== NULL
) || (String
== NULL
)) {
847 return EFI_INVALID_PARAMETER
;
850 // Set Hii handle and String ID.
852 *Hii
= mCallbackInfo
->HiiHandle
;
853 *String
= STRING_TOKEN (STR_CREDENTIAL_TITLE
);
860 Return the user identifier associated with the currently authenticated user.
862 This function returns the user identifier of the user authenticated by this credential
863 provider. This function is called after the credential-related information has been
864 submitted on a form OR after a call to Default() has returned that this credential is
867 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
868 @param[in] User The user profile handle of the user profile currently being
869 considered by the user identity manager. If NULL, then no user
870 profile is currently under consideration.
871 @param[out] Identifier On return, points to the user identifier.
873 @retval EFI_SUCCESS User identifier returned successfully.
874 @retval EFI_NOT_READY No user identifier can be returned.
875 @retval EFI_ACCESS_DENIED The user has been locked out of this user credential.
876 @retval EFI_INVALID_PARAMETER This is NULL, or Identifier is NULL.
877 @retval EFI_NOT_FOUND User is not NULL, and the specified user handle can't be
878 found in user profile database.
884 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL
*This
,
885 IN EFI_USER_PROFILE_HANDLE User
,
886 OUT EFI_USER_INFO_IDENTIFIER
*Identifier
891 EFI_USER_INFO
*UserInfo
;
895 UINT8 ReadToken
[HASHED_CREDENTIAL_LEN
];
900 if ((This
== NULL
) || (Identifier
== NULL
)) {
901 return EFI_INVALID_PARAMETER
;
906 // Verify the auto logon user, get user id by matched token.
908 if (mUsbTable
->Count
== 0) {
909 return EFI_NOT_READY
;
913 // No user selected, get token first and verify the user existed in user database.
915 Status
= GetToken (ReadToken
);
916 if (EFI_ERROR (Status
)) {
917 return EFI_NOT_READY
;
920 for (Index
= 0; Index
< mUsbTable
->Count
; Index
++) {
922 // find the specified credential in the Usb credential database.
924 UserToken
= mUsbTable
->UserInfo
[Index
].Token
;
925 if (CompareMem (UserToken
, ReadToken
, HASHED_CREDENTIAL_LEN
) == 0) {
926 UserId
= (UINT8
*) &mUsbTable
->UserInfo
[Index
].UserId
;
927 CopyMem (Identifier
, UserId
, sizeof (EFI_USER_INFO_IDENTIFIER
));
932 return EFI_NOT_READY
;
936 // User is not NULL here. Read a token, and check whether the token matches with
937 // the selected user's Token. If not, try to find a token in token DB to matches
941 Status
= GetToken (ReadToken
);
942 if (EFI_ERROR (Status
)) {
943 QuestionStr
= GetStringById (STRING_TOKEN (STR_READ_USB_TOKEN_ERROR
));
944 PromptStr
= GetStringById (STRING_TOKEN (STR_INSERT_USB_TOKEN
));
946 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
953 FreePool (QuestionStr
);
954 FreePool (PromptStr
);
955 return EFI_NOT_FOUND
;
959 // Get the selected user's identifier.
961 Status
= FindUserInfoByType (User
, EFI_USER_INFO_IDENTIFIER_RECORD
, &UserInfo
);
962 if (EFI_ERROR (Status
)) {
963 return EFI_NOT_FOUND
;
967 // Check the selected user's Token with the read token.
969 for (Index
= 0; Index
< mUsbTable
->Count
; Index
++) {
970 UserId
= (UINT8
*) &mUsbTable
->UserInfo
[Index
].UserId
;
971 NewUserId
= (UINT8
*) (UserInfo
+ 1);
972 if (CompareMem (UserId
, NewUserId
, sizeof (EFI_USER_INFO_IDENTIFIER
)) == 0) {
974 // The user's ID is found in the UsbTable.
976 UserToken
= mUsbTable
->UserInfo
[Index
].Token
;
977 if (CompareMem (UserToken
, ReadToken
, HASHED_CREDENTIAL_LEN
) == 0) {
979 // The read token matches with the one in UsbTable.
981 CopyMem (Identifier
, UserId
, sizeof (EFI_USER_INFO_IDENTIFIER
));
990 return EFI_NOT_READY
;
995 Indicate that user interface interaction has begun for the specified credential.
997 This function is called when a credential provider is selected by the user. If
998 AutoLogon returns FALSE, then the user interface will be constructed by the User
1001 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
1002 @param[out] AutoLogon On return, points to the credential provider's capabilities
1003 after the credential provider has been selected by the user.
1005 @retval EFI_SUCCESS Credential provider successfully selected.
1006 @retval EFI_INVALID_PARAMETER AutoLogon is NULL.
1012 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL
*This
,
1013 OUT EFI_CREDENTIAL_LOGON_FLAGS
*AutoLogon
1016 if ((This
== NULL
) || (AutoLogon
== NULL
)) {
1017 return EFI_INVALID_PARAMETER
;
1020 *AutoLogon
= EFI_CREDENTIAL_LOGON_FLAG_DEFAULT
| EFI_CREDENTIAL_LOGON_FLAG_AUTO
;
1027 Indicate that user interface interaction has ended for the specified credential.
1029 This function is called when a credential provider is deselected by the user.
1031 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
1033 @retval EFI_SUCCESS Credential provider successfully deselected.
1038 CredentialDeselect (
1039 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL
*This
1043 return EFI_INVALID_PARAMETER
;
1050 Return the default logon behavior for this user credential.
1052 This function reports the default login behavior regarding this credential provider.
1054 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
1055 @param[out] AutoLogon On return, holds whether the credential provider should be used
1056 by default to automatically log on the user.
1058 @retval EFI_SUCCESS Default information successfully returned.
1059 @retval EFI_INVALID_PARAMETER AutoLogon is NULL.
1065 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL
*This
,
1066 OUT EFI_CREDENTIAL_LOGON_FLAGS
*AutoLogon
1069 if ((This
== NULL
) || (AutoLogon
== NULL
)) {
1070 return EFI_INVALID_PARAMETER
;
1073 *AutoLogon
= EFI_CREDENTIAL_LOGON_FLAG_DEFAULT
| EFI_CREDENTIAL_LOGON_FLAG_AUTO
;
1079 Return information attached to the credential provider.
1081 This function returns user information.
1083 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
1084 @param[in] UserInfo Handle of the user information data record.
1085 @param[out] Info On entry, points to a buffer of at least *InfoSize bytes. On
1086 exit, holds the user information. If the buffer is too small
1087 to hold the information, then EFI_BUFFER_TOO_SMALL is returned
1088 and InfoSize is updated to contain the number of bytes actually
1090 @param[in, out] InfoSize On entry, points to the size of Info. On return, points to the
1091 size of the user information.
1093 @retval EFI_SUCCESS Information returned successfully.
1094 @retval EFI_BUFFER_TOO_SMALL The size specified by InfoSize is too small to hold all of the
1095 user information. The size required is returned in *InfoSize.
1096 @retval EFI_INVALID_PARAMETER Info is NULL or InfoSize is NULL.
1097 @retval EFI_NOT_FOUND The specified UserInfo does not refer to a valid user info handle.
1103 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL
*This
,
1104 IN EFI_USER_INFO_HANDLE UserInfo
,
1105 OUT EFI_USER_INFO
*Info
,
1106 IN OUT UINTN
*InfoSize
1109 EFI_USER_INFO
*CredentialInfo
;
1112 if ((This
== NULL
) || (InfoSize
== NULL
) || (Info
== NULL
)) {
1113 return EFI_INVALID_PARAMETER
;
1116 if ((UserInfo
== NULL
) || (mUsbInfoHandle
== NULL
)) {
1117 return EFI_NOT_FOUND
;
1121 // Find information handle in credential info table.
1123 for (Index
= 0; Index
< mUsbInfoHandle
->Count
; Index
++) {
1124 CredentialInfo
= mUsbInfoHandle
->Info
[Index
];
1125 if (UserInfo
== (EFI_USER_INFO_HANDLE
)CredentialInfo
) {
1127 // The handle is found, copy the user info.
1129 if (CredentialInfo
->InfoSize
> *InfoSize
) {
1130 *InfoSize
= CredentialInfo
->InfoSize
;
1131 return EFI_BUFFER_TOO_SMALL
;
1134 CopyMem (Info
, CredentialInfo
, CredentialInfo
->InfoSize
);
1139 return EFI_NOT_FOUND
;
1144 Enumerate all of the user informations on the credential provider.
1146 This function returns the next user information record. To retrieve the first user
1147 information record handle, point UserInfo at a NULL. Each subsequent call will retrieve
1148 another user information record handle until there are no more, at which point UserInfo
1151 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
1152 @param[in, out] UserInfo On entry, points to the previous user information handle or NULL
1153 to start enumeration. On exit, points to the next user information
1154 handle or NULL if there is no more user information.
1156 @retval EFI_SUCCESS User information returned.
1157 @retval EFI_NOT_FOUND No more user information found.
1158 @retval EFI_INVALID_PARAMETER UserInfo is NULL.
1163 CredentialGetNextInfo (
1164 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL
*This
,
1165 IN OUT EFI_USER_INFO_HANDLE
*UserInfo
1168 EFI_USER_INFO
*Info
;
1169 CHAR16
*ProvNameStr
;
1174 if ((This
== NULL
) || (UserInfo
== NULL
)) {
1175 return EFI_INVALID_PARAMETER
;
1178 if (mUsbInfoHandle
== NULL
) {
1180 // Initilized user info table. There are 4 user info records in the table.
1182 InfoLen
= sizeof (USB_CREDENTIAL_INFO
) + (4 - 1) * sizeof (EFI_USER_INFO
*);
1183 mUsbInfoHandle
= AllocateZeroPool (InfoLen
);
1184 if (mUsbInfoHandle
== NULL
) {
1186 return EFI_NOT_FOUND
;
1190 // The first information, Credential Provider info.
1192 InfoLen
= sizeof (EFI_USER_INFO
) + sizeof (EFI_GUID
);
1193 Info
= AllocateZeroPool (InfoLen
);
1194 ASSERT (Info
!= NULL
);
1196 Info
->InfoType
= EFI_USER_INFO_CREDENTIAL_PROVIDER_RECORD
;
1197 Info
->InfoSize
= (UINT32
) InfoLen
;
1198 Info
->InfoAttribs
= EFI_USER_INFO_PROTECTED
;
1199 CopyGuid (&Info
->Credential
, &gUsbCredentialProviderGuid
);
1200 CopyGuid ((EFI_GUID
*)(Info
+ 1), &gUsbCredentialProviderGuid
);
1202 mUsbInfoHandle
->Info
[0] = Info
;
1203 mUsbInfoHandle
->Count
++;
1206 // The second information, Credential Provider name info.
1208 ProvNameStr
= GetStringById (STRING_TOKEN (STR_PROVIDER_NAME
));
1209 ProvStrLen
= StrSize (ProvNameStr
);
1210 InfoLen
= sizeof (EFI_USER_INFO
) + ProvStrLen
;
1211 Info
= AllocateZeroPool (InfoLen
);
1212 ASSERT (Info
!= NULL
);
1214 Info
->InfoType
= EFI_USER_INFO_CREDENTIAL_PROVIDER_NAME_RECORD
;
1215 Info
->InfoSize
= (UINT32
) InfoLen
;
1216 Info
->InfoAttribs
= EFI_USER_INFO_PROTECTED
;
1217 CopyGuid (&Info
->Credential
, &gUsbCredentialProviderGuid
);
1218 CopyMem ((UINT8
*)(Info
+ 1), ProvNameStr
, ProvStrLen
);
1219 FreePool (ProvNameStr
);
1221 mUsbInfoHandle
->Info
[1] = Info
;
1222 mUsbInfoHandle
->Count
++;
1225 // The third information, Credential Provider type info.
1227 InfoLen
= sizeof (EFI_USER_INFO
) + sizeof (EFI_GUID
);
1228 Info
= AllocateZeroPool (InfoLen
);
1229 ASSERT (Info
!= NULL
);
1231 Info
->InfoType
= EFI_USER_INFO_CREDENTIAL_TYPE_RECORD
;
1232 Info
->InfoSize
= (UINT32
) InfoLen
;
1233 Info
->InfoAttribs
= EFI_USER_INFO_PROTECTED
;
1234 CopyGuid (&Info
->Credential
, &gUsbCredentialProviderGuid
);
1235 CopyGuid ((EFI_GUID
*)(Info
+ 1), &gEfiUserCredentialClassSecureCardGuid
);
1237 mUsbInfoHandle
->Info
[2] = Info
;
1238 mUsbInfoHandle
->Count
++;
1241 // The fourth information, Credential Provider type name info.
1243 ProvNameStr
= GetStringById (STRING_TOKEN (STR_PROVIDER_TYPE_NAME
));
1244 ProvStrLen
= StrSize (ProvNameStr
);
1245 InfoLen
= sizeof (EFI_USER_INFO
) + ProvStrLen
;
1246 Info
= AllocateZeroPool (InfoLen
);
1247 ASSERT (Info
!= NULL
);
1249 Info
->InfoType
= EFI_USER_INFO_CREDENTIAL_PROVIDER_NAME_RECORD
;
1250 Info
->InfoSize
= (UINT32
) InfoLen
;
1251 Info
->InfoAttribs
= EFI_USER_INFO_PROTECTED
;
1252 CopyGuid (&Info
->Credential
, &gUsbCredentialProviderGuid
);
1253 CopyMem ((UINT8
*)(Info
+ 1), ProvNameStr
, ProvStrLen
);
1254 FreePool (ProvNameStr
);
1256 mUsbInfoHandle
->Info
[3] = Info
;
1257 mUsbInfoHandle
->Count
++;
1260 if (*UserInfo
== NULL
) {
1262 // Return the first info handle.
1264 *UserInfo
= (EFI_USER_INFO_HANDLE
) mUsbInfoHandle
->Info
[0];
1269 // Find information handle in credential info table.
1271 for (Index
= 0; Index
< mUsbInfoHandle
->Count
; Index
++) {
1272 Info
= mUsbInfoHandle
->Info
[Index
];
1273 if (*UserInfo
== (EFI_USER_INFO_HANDLE
)Info
) {
1275 // The handle is found, get the next one.
1277 if (Index
== mUsbInfoHandle
->Count
- 1) {
1279 // Already last one.
1282 return EFI_NOT_FOUND
;
1285 *UserInfo
= (EFI_USER_INFO_HANDLE
)mUsbInfoHandle
->Info
[Index
];
1291 return EFI_NOT_FOUND
;
1296 Delete a user on this credential provider.
1298 This function deletes a user on this credential provider.
1300 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
1301 @param[in] User The user profile handle to delete.
1303 @retval EFI_SUCCESS User profile was successfully deleted.
1304 @retval EFI_ACCESS_DENIED Current user profile does not permit deletion on the user profile handle.
1305 Either the user profile cannot delete on any user profile or cannot delete
1306 on a user profile other than the current user profile.
1307 @retval EFI_UNSUPPORTED This credential provider does not support deletion in the pre-OS.
1308 @retval EFI_DEVICE_ERROR The new credential could not be deleted because of a device error.
1309 @retval EFI_INVALID_PARAMETER User does not refer to a valid user profile handle.
1314 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL
*This
,
1315 IN EFI_USER_PROFILE_HANDLE User
1319 EFI_USER_INFO
*UserInfo
;
1324 if ((This
== NULL
) || (User
== NULL
)) {
1325 return EFI_INVALID_PARAMETER
;
1329 // Get User Identifier.
1332 Status
= FindUserInfoByType (
1334 EFI_USER_INFO_IDENTIFIER_RECORD
,
1337 if (EFI_ERROR (Status
)) {
1338 return EFI_INVALID_PARAMETER
;
1342 // Find the user by user identifier in mPwdTable.
1344 for (Index
= 0; Index
< mUsbTable
->Count
; Index
++) {
1345 UserId
= (UINT8
*) &mUsbTable
->UserInfo
[Index
].UserId
;
1346 NewUserId
= (UINT8
*) (UserInfo
+ 1);
1347 if (CompareMem (UserId
, NewUserId
, sizeof (EFI_USER_INFO_IDENTIFIER
)) == 0) {
1349 // Found the user, delete it.
1351 ModifyTable (Index
, NULL
);
1356 FreePool (UserInfo
);
1362 Main entry for this driver.
1364 @param ImageHandle Image handle this driver.
1365 @param SystemTable Pointer to SystemTable.
1367 @retval EFI_SUCESS This function always complete successfully.
1373 IN EFI_HANDLE ImageHandle
,
1374 IN EFI_SYSTEM_TABLE
*SystemTable
1380 // It is NOT robust enough to be included in production.
1382 #error "This implementation is just a sample, please comment this line if you really want to use this driver."
1385 // Init credential table.
1387 Status
= InitCredentialTable ();
1388 if (EFI_ERROR (Status
)) {
1393 // Init Form Browser
1395 Status
= InitFormBrowser ();
1396 if (EFI_ERROR (Status
)) {
1401 // Install protocol interfaces for the Usb Credential Provider.
1403 Status
= gBS
->InstallProtocolInterface (
1404 &mCallbackInfo
->DriverHandle
,
1405 &gEfiUserCredential2ProtocolGuid
,
1406 EFI_NATIVE_INTERFACE
,
1407 &gUsbCredentialProviderDriver