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
;
22 // Used for save password credential and form browser
23 // And used as provider identifier
25 EFI_GUID mUsbCredentialGuid
= USB_CREDENTIAL_PROVIDER_GUID
;
27 HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath
= {
33 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
34 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
37 { 0x9463f883, 0x48f6, 0x4a7a, { 0x97, 0x2d, 0x9f, 0x8f, 0x38, 0xf2, 0xdd, 0x91 } }
41 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
43 (UINT8
) (END_DEVICE_PATH_LENGTH
),
44 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
49 EFI_USER_CREDENTIAL_PROTOCOL gUsbCredentialProviderDriver
= {
50 USB_CREDENTIAL_PROVIDER_GUID
,
51 EFI_USER_CREDENTIAL_CLASS_SECURE_CARD
,
66 Get string by string id from HII Interface.
69 @param[in] Id String ID to get the string from.
71 @retval CHAR16 * String from ID.
72 @retval NULL If error occurs.
81 // Get the current string for the current Language
83 return HiiGetString (mCallbackInfo
->HiiHandle
, Id
, NULL
);
88 Expand password table size.
96 CREDENTIAL_TABLE
*NewTable
;
99 Count
= mUsbTable
->MaxCount
+ USB_TABLE_INC
;
101 // Create new credential table.
103 NewTable
= AllocateZeroPool (
104 sizeof (CREDENTIAL_TABLE
) - sizeof (USB_INFO
) +
105 Count
* sizeof (USB_INFO
)
107 ASSERT (NewTable
!= NULL
);
109 NewTable
->MaxCount
= Count
;
110 NewTable
->Count
= mUsbTable
->Count
;
117 &mUsbTable
->UserInfo
,
118 mUsbTable
->Count
* sizeof (USB_INFO
)
120 FreePool (mUsbTable
);
121 mUsbTable
= NewTable
;
126 Add or delete info in table, and sync with NV variable.
128 @param[in] Index The index of the password in table. The index begin from 1.
129 If index is found in table, delete the info, else add the
131 @param[in] Info The new password info to add into table.
133 @retval EFI_INVALID_PARAMETER Info is NULL when save the info.
134 @retval EFI_SUCCESS Modify the table successfully.
135 @retval Others Failed to modify the table.
141 IN USB_INFO
* Info OPTIONAL
146 if (Index
< mUsbTable
->Count
) {
148 // Delete the specified entry
151 if (Index
!= mUsbTable
->Count
) {
153 &mUsbTable
->UserInfo
[Index
],
154 &mUsbTable
->UserInfo
[mUsbTable
->Count
],
163 return EFI_INVALID_PARAMETER
;
166 if (mUsbTable
->Count
>= mUsbTable
->MaxCount
) {
171 &mUsbTable
->UserInfo
[mUsbTable
->Count
],
179 // Save the credential table.
181 Status
= gRT
->SetVariable (
184 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
185 mUsbTable
->Count
* sizeof (USB_INFO
),
193 Create a credential table
195 @retval EFI_SUCCESS Create a credential table successfully.
196 @retval Others Failed to create a password.
200 InitCredentialTable (
209 // Get Usb credential data from NV variable.
213 Status
= gRT
->GetVariable (
220 if (Status
== EFI_BUFFER_TOO_SMALL
) {
221 Var
= AllocateZeroPool (VarSize
);
223 return EFI_OUT_OF_RESOURCES
;
225 Status
= gRT
->GetVariable (
233 if (EFI_ERROR (Status
) && (Status
!= EFI_NOT_FOUND
)) {
238 // Init Usb credential table.
240 mUsbTable
= AllocateZeroPool (
241 sizeof (CREDENTIAL_TABLE
) - sizeof (USB_INFO
) +
242 USB_TABLE_INC
* sizeof (USB_INFO
) +
245 if (mUsbTable
== NULL
) {
247 return EFI_OUT_OF_RESOURCES
;
250 mUsbTable
->Count
= VarSize
/ sizeof (USB_INFO
);
251 mUsbTable
->MaxCount
= mUsbTable
->Count
+ USB_TABLE_INC
;
253 CopyMem (mUsbTable
->UserInfo
, Var
, VarSize
);
261 Read the specified file by FileName in the Usb key and return the file size in BufferSize
262 and file content in Buffer.
263 Note: the caller is responsible to free the buffer memory.
265 @param FileName File to read.
266 @param Buffer Returned with data read from the file.
267 @param BufferSize Size of the data buffer.
269 @retval EFI_SUCCESS The command completed successfully.
270 @retval EFI_OUT_OF_RESOURCES Resource allocation failed.
271 @retval EFI_NOT_FOUND File not found.
272 @retval EFI_DEVICE_ERROR Device I/O error.
279 OUT UINTN
*BufferSize
285 UINTN ScratchBufferSize
;
286 EFI_HANDLE
*HandleBuffer
;
288 EFI_FILE
*FileHandle
;
289 EFI_FILE_INFO
*FileInfo
;
290 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*SimpleFileSystem
;
291 EFI_BLOCK_IO_PROTOCOL
*BlkIo
;
296 Status
= gBS
->LocateHandleBuffer (
298 &gEfiSimpleFileSystemProtocolGuid
,
303 if (EFI_ERROR (Status
)) {
304 DEBUG ((DEBUG_ERROR
, "Can not Locate SimpleFileSystemProtocol\n"));
309 // Find and open the file in removable media disk.
311 for (Index
= 0; Index
< HandleCount
; Index
++) {
312 Status
= gBS
->HandleProtocol (
314 &gEfiBlockIoProtocolGuid
,
317 if (EFI_ERROR (Status
)) {
321 if (BlkIo
->Media
->RemovableMedia
) {
322 Status
= gBS
->HandleProtocol (
324 &gEfiSimpleFileSystemProtocolGuid
,
325 (VOID
**) &SimpleFileSystem
327 if (EFI_ERROR (Status
)) {
331 Status
= SimpleFileSystem
->OpenVolume (
335 if (EFI_ERROR (Status
)) {
339 Status
= RootFs
->Open (
346 if (!EFI_ERROR (Status
)) {
352 FreePool (HandleBuffer
);
354 if (Index
>= HandleCount
) {
355 DEBUG ((DEBUG_ERROR
, "Can not found the token file!\n"));
356 Status
= EFI_NOT_FOUND
;
361 // Figure out how big the file is.
363 ScratchBufferSize
= 0;
364 Status
= FileHandle
->GetInfo (
370 if (EFI_ERROR (Status
) && (Status
!= EFI_BUFFER_TOO_SMALL
)) {
371 DEBUG ((DEBUG_ERROR
, "Can not obtain file size info!\n"));
372 Status
= EFI_DEVICE_ERROR
;
376 FileInfo
= AllocateZeroPool (ScratchBufferSize
);
377 if (FileInfo
== NULL
) {
378 DEBUG ((DEBUG_ERROR
, "Can not allocate enough memory for the token file!\n"));
379 Status
= EFI_OUT_OF_RESOURCES
;
383 Status
= FileHandle
->GetInfo (
389 if (EFI_ERROR (Status
)) {
390 DEBUG ((DEBUG_ERROR
, "Can not obtain file info from the token file!\n"));
391 Status
= EFI_DEVICE_ERROR
;
396 // Allocate a buffer for the file.
398 *BufferSize
= (UINT32
) FileInfo
->FileSize
;
399 *Buffer
= AllocateZeroPool (*BufferSize
);
400 if (*Buffer
== NULL
) {
401 DEBUG ((DEBUG_ERROR
, "Can not allocate a buffer for the file!\n"));
402 Status
= EFI_OUT_OF_RESOURCES
;
407 // Load file into the allocated memory.
409 Status
= FileHandle
->Read (FileHandle
, BufferSize
, *Buffer
);
410 if (EFI_ERROR (Status
)) {
412 DEBUG ((DEBUG_ERROR
, "Can not read the token file!\n"));
413 Status
= EFI_DEVICE_ERROR
;
420 Status
= FileHandle
->Close (FileHandle
);
421 if (EFI_ERROR (Status
)) {
423 DEBUG ((DEBUG_ERROR
, "Can not close the token file !\n"));
424 Status
= EFI_DEVICE_ERROR
;
429 if (FileInfo
!= NULL
) {
438 Hash the data to get credential.
440 @param[in] Buffer Points to the data buffer
441 @param[in] BufferSize The size of data in buffer, in bytes.
442 @param[out] Credential Points to the hashed result
444 @retval TRUE Hash the data successfully.
445 @retval FALSE Failed to hash the data.
452 OUT UINT8
*Credential
459 HashSize
= Sha1GetContextSize ();
460 Hash
= AllocatePool (HashSize
);
461 ASSERT (Hash
!= NULL
);
463 Status
= Sha1Init (Hash
);
468 Status
= Sha1Update (Hash
, Buffer
, BufferSize
);
473 Status
= Sha1Final (Hash
, Credential
);
482 Read the token file, and default the Token is saved at the begining of the file.
484 @param[out] Token Token read from a Token file.
486 @retval EFI_SUCCESS Read a Token successfully.
487 @retval Others Fails to read a Token.
502 TokenFile
= FixedPcdGetPtr (PcdFixedUsbCredentialProviderTokenFileName
);
503 Status
= GetFileData (TokenFile
, (VOID
*)&Buffer
, &BufSize
);
504 if (EFI_ERROR (Status
)) {
505 DEBUG ((DEBUG_ERROR
, "Read file %s from USB error! Status=(%r)\n", TokenFile
, Status
));
509 if (!GenerateCredential (Buffer
, BufSize
, Token
)) {
510 DEBUG ((DEBUG_ERROR
, "Generate credential from read data failed!\n"));
512 return EFI_SECURITY_VIOLATION
;
521 Find a user infomation record by the information record type.
523 This function searches all user information records of User from beginning
524 until either the information is found or there are no more user infomation
525 record. A match occurs when a Info.InfoType field matches the user information
528 @param[in] User Points to the user profile record to search.
529 @param[in] InfoType The infomation type to be searched.
530 @param[out] Info Points to the user info found, the caller is responsible
533 @retval EFI_SUCCESS Find the user information successfully.
534 @retval Others Fail to find the user information.
539 IN EFI_USER_PROFILE_HANDLE User
,
541 OUT EFI_USER_INFO
**Info
545 EFI_USER_INFO
*UserInfo
;
547 EFI_USER_INFO_HANDLE UserInfoHandle
;
548 EFI_USER_MANAGER_PROTOCOL
*UserManager
;
551 // Find user information by information type.
554 return EFI_INVALID_PARAMETER
;
557 Status
= gBS
->LocateProtocol (
558 &gEfiUserManagerProtocolGuid
,
560 (VOID
**) &UserManager
562 if (EFI_ERROR (Status
)) {
563 return EFI_NOT_FOUND
;
567 // Get each user information.
570 UserInfoHandle
= NULL
;
574 Status
= UserManager
->GetNextInfo (UserManager
, User
, &UserInfoHandle
);
575 if (EFI_ERROR (Status
)) {
581 Status
= UserManager
->GetInfo (
588 if (Status
== EFI_BUFFER_TOO_SMALL
) {
589 if (UserInfo
!= NULL
) {
592 UserInfo
= AllocateZeroPool (UserInfoSize
);
593 if (UserInfo
== NULL
) {
594 return EFI_OUT_OF_RESOURCES
;
596 Status
= UserManager
->GetInfo (
604 if (EFI_ERROR (Status
)) {
608 ASSERT (UserInfo
!= NULL
);
609 if (UserInfo
->InfoType
== InfoType
) {
615 if (UserInfo
!= NULL
) {
623 This function initialize the data mainly used in form browser.
625 @retval EFI_SUCCESS Initialize form data successfully.
626 @retval Others Fail to Initialize form data.
634 USB_PROVIDER_CALLBACK_INFO
*CallbackInfo
;
637 // Initialize driver private data.
639 CallbackInfo
= AllocateZeroPool (sizeof (USB_PROVIDER_CALLBACK_INFO
));
640 if (CallbackInfo
== NULL
) {
641 return EFI_OUT_OF_RESOURCES
;
644 CallbackInfo
->DriverHandle
= NULL
;
649 CallbackInfo
->HiiHandle
= HiiAddPackages (
651 CallbackInfo
->DriverHandle
,
652 UsbCredentialProviderStrings
,
655 if (CallbackInfo
->HiiHandle
== NULL
) {
656 return EFI_OUT_OF_RESOURCES
;
658 mCallbackInfo
= CallbackInfo
;
665 Enroll a user on a credential provider.
667 This function enrolls and deletes a user profile using this credential provider.
668 If a user profile is successfully enrolled, it calls the User Manager Protocol
669 function Notify() to notify the user manager driver that credential information
670 has changed. If an enrolled user does exist, delete the user on the credential
673 @param[in] This Points to this instance of EFI_USER_CREDENTIAL_PROTOCOL.
674 @param[in] User The user profile to enroll.
676 @retval EFI_SUCCESS User profile was successfully enrolled.
677 @retval EFI_ACCESS_DENIED Current user profile does not permit enrollment on the
678 user profile handle. Either the user profile cannot enroll
679 on any user profile or cannot enroll on a user profile
680 other than the current user profile.
681 @retval EFI_UNSUPPORTED This credential provider does not support enrollment in
683 @retval EFI_DEVICE_ERROR The new credential could not be created because of a device
685 @retval EFI_INVALID_PARAMETER User does not refer to a valid user profile handle.
691 IN CONST EFI_USER_CREDENTIAL_PROTOCOL
*This
,
692 IN EFI_USER_PROFILE_HANDLE User
698 EFI_USER_INFO
*UserInfo
;
700 EFI_USER_MANAGER_PROTOCOL
*UserManager
;
707 if ((This
== NULL
) || (User
== NULL
)) {
708 return EFI_INVALID_PARAMETER
;
711 Status
= gBS
->LocateProtocol (
712 &gEfiUserManagerProtocolGuid
,
714 (VOID
**) &UserManager
716 if (EFI_ERROR (Status
)) {
717 return EFI_UNSUPPORTED
;
721 // Get User Identifier
724 Status
= FindUserInfoByType (
726 EFI_USER_INFO_IDENTIFIER_RECORD
,
729 if (EFI_ERROR (Status
)) {
730 return EFI_INVALID_PARAMETER
;
734 // If User exists in mUsbTable, delete User.
736 for (Index
= 0; Index
< mUsbTable
->Count
; Index
++) {
737 UserId
= (UINT8
*) &mUsbTable
->UserInfo
[Index
].UserId
;
738 NewUserId
= (UINT8
*) (UserInfo
+ 1);
739 if (CompareMem (UserId
, NewUserId
, sizeof (EFI_USER_INFO_IDENTIFIER
)) == 0) {
741 // Delete the exist Token.
744 return ModifyTable (Index
, NULL
);
749 // Get Token and User ID to UsbInfo.
751 Status
= GetToken (UsbInfo
.Token
);
752 if (EFI_ERROR (Status
)) {
753 QuestionStr
= GetStringById (STRING_TOKEN (STR_READ_USB_TOKEN_ERROR
));
754 PromptStr
= GetStringById (STRING_TOKEN (STR_INSERT_USB_TOKEN
));
755 OldTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
756 gBS
->RestoreTPL (TPL_APPLICATION
);
758 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
765 gBS
->RaiseTPL (OldTpl
);
766 FreePool (QuestionStr
);
767 FreePool (PromptStr
);
773 (UINT8
*) (UserInfo
+ 1),
774 sizeof (EFI_USER_INFO_IDENTIFIER
)
779 // Save the new added entry.
781 Status
= ModifyTable (mUsbTable
->Count
, &UsbInfo
);
782 if (EFI_ERROR (Status
)) {
787 // Notify the user manager driver that credential information has changed.
789 UserManager
->Notify (UserManager
, mCallbackInfo
->DriverHandle
);
796 Returns the user interface information used during user identification.
798 This function returns information about the form used when interacting with the
799 user during user identification. The form is the first enabled form in the form-set
800 class EFI_HII_USER_CREDENTIAL_FORMSET_GUID installed on the HII handle HiiHandle. If
801 the user credential provider does not require a form to identify the user, then this
802 function should return EFI_NOT_FOUND.
804 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.
805 @param[out] Hii On return, holds the HII database handle.
806 @param[out] FormSetId On return, holds the identifier of the form set which contains
807 the form used during user identification.
808 @param[out] FormId On return, holds the identifier of the form used during user
811 @retval EFI_SUCCESS Form returned successfully.
812 @retval EFI_NOT_FOUND Form not returned.
813 @retval EFI_INVALID_PARAMETER Hii is NULL or FormSetId is NULL or FormId is NULL.
819 IN CONST EFI_USER_CREDENTIAL_PROTOCOL
*This
,
820 OUT EFI_HII_HANDLE
*Hii
,
821 OUT EFI_GUID
*FormSetId
,
822 OUT EFI_FORM_ID
*FormId
825 if ((This
== NULL
) || (Hii
== NULL
) ||
826 (FormSetId
== NULL
) || (FormId
== NULL
)) {
827 return EFI_INVALID_PARAMETER
;
829 return EFI_NOT_FOUND
;
834 Returns bitmap used to describe the credential provider type.
836 This optional function returns a bitmap which is less than or equal to the number
837 of pixels specified by Width and Height. If no such bitmap exists, then EFI_NOT_FOUND
840 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.
841 @param[in, out] Width On entry, points to the desired bitmap width. If NULL then no
842 bitmap information will be returned. On exit, points to the
843 width of the bitmap returned.
844 @param[in, out] Height On entry, points to the desired bitmap height. If NULL then no
845 bitmap information will be returned. On exit, points to the
846 height of the bitmap returned.
847 @param[out] Hii On return, holds the HII database handle.
848 @param[out] Image On return, holds the HII image identifier.
850 @retval EFI_SUCCESS Image identifier returned successfully.
851 @retval EFI_NOT_FOUND Image identifier not returned.
852 @retval EFI_INVALID_PARAMETER Hii is NULL or Image is NULL.
858 IN CONST EFI_USER_CREDENTIAL_PROTOCOL
*This
,
860 IN OUT UINTN
*Height
,
861 OUT EFI_HII_HANDLE
*Hii
,
862 OUT EFI_IMAGE_ID
*Image
865 if ((This
== NULL
) || (Hii
== NULL
) || (Image
== NULL
)) {
866 return EFI_INVALID_PARAMETER
;
868 return EFI_NOT_FOUND
;
873 Returns string used to describe the credential provider type.
875 This function returns a string which describes the credential provider. If no
876 such string exists, then EFI_NOT_FOUND is returned.
878 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.
879 @param[out] Hii On return, holds the HII database handle.
880 @param[out] String On return, holds the HII string identifier.
882 @retval EFI_SUCCESS String identifier returned successfully.
883 @retval EFI_NOT_FOUND String identifier not returned.
884 @retval EFI_INVALID_PARAMETER Hii is NULL or String is NULL.
890 IN CONST EFI_USER_CREDENTIAL_PROTOCOL
*This
,
891 OUT EFI_HII_HANDLE
*Hii
,
892 OUT EFI_STRING_ID
*String
895 if ((This
== NULL
) || (Hii
== NULL
) || (String
== NULL
)) {
896 return EFI_INVALID_PARAMETER
;
899 // Set Hii handle and String ID.
901 *Hii
= mCallbackInfo
->HiiHandle
;
902 *String
= STRING_TOKEN (STR_CREDENTIAL_TITLE
);
909 Return the user identifier associated with the currently authenticated user.
911 This function returns the user identifier of the user authenticated by this credential
912 provider. This function is called after the credential-related information has been
913 submitted on a form OR after a call to Default() has returned that this credential is
916 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.
917 @param[in] User The user profile handle of the user profile currently being
918 considered by the user identity manager. If NULL, then no user
919 profile is currently under consideration.
920 @param[out] Identifier On return, points to the user identifier.
922 @retval EFI_SUCCESS User identifier returned successfully.
923 @retval EFI_NOT_READY No user identifier can be returned.
924 @retval EFI_ACCESS_DENIED The user has been locked out of this user credential.
925 @retval EFI_INVALID_PARAMETER This is NULL, or Identifier is NULL.
926 @retval EFI_NOT_FOUND User is not NULL, and the specified user handle can't be
927 found in user profile database.
933 IN CONST EFI_USER_CREDENTIAL_PROTOCOL
*This
,
934 IN EFI_USER_PROFILE_HANDLE User
,
935 OUT EFI_USER_INFO_IDENTIFIER
*Identifier
940 EFI_USER_INFO
*UserInfo
;
944 UINT8 ReadToken
[HASHED_CREDENTIAL_LEN
];
950 if ((This
== NULL
) || (Identifier
== NULL
)) {
951 return EFI_INVALID_PARAMETER
;
956 // Verify the auto logon user, get user id by matched token.
958 if (mUsbTable
->Count
== 0) {
959 return EFI_NOT_READY
;
963 // No user selected, get token first and verify the user existed in user database.
965 Status
= GetToken (ReadToken
);
966 if (EFI_ERROR (Status
)) {
967 return EFI_NOT_READY
;
970 for (Index
= 0; Index
< mUsbTable
->Count
; Index
++) {
972 // find the specified credential in the Usb credential database.
974 UserToken
= mUsbTable
->UserInfo
[Index
].Token
;
975 if (CompareMem (UserToken
, ReadToken
, HASHED_CREDENTIAL_LEN
) == 0) {
976 UserId
= (UINT8
*) &mUsbTable
->UserInfo
[Index
].UserId
;
977 CopyMem (Identifier
, UserId
, sizeof (EFI_USER_INFO_IDENTIFIER
));
982 return EFI_NOT_READY
;
986 // User is not NULL here. Read a token, and check whether the token matches with
987 // the selected user's Token. If not, try to find a token in token DB to matches
991 Status
= GetToken (ReadToken
);
992 if (EFI_ERROR (Status
)) {
993 QuestionStr
= GetStringById (STRING_TOKEN (STR_READ_USB_TOKEN_ERROR
));
994 PromptStr
= GetStringById (STRING_TOKEN (STR_INSERT_USB_TOKEN
));
995 OldTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
996 gBS
->RestoreTPL (TPL_APPLICATION
);
998 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1005 gBS
->RaiseTPL (OldTpl
);
1006 FreePool (QuestionStr
);
1007 FreePool (PromptStr
);
1008 return EFI_NOT_FOUND
;
1012 // Get the selected user's identifier.
1014 Status
= FindUserInfoByType (User
, EFI_USER_INFO_IDENTIFIER_RECORD
, &UserInfo
);
1015 if (EFI_ERROR (Status
)) {
1016 return EFI_NOT_FOUND
;
1020 // Check the selected user's Token with the read token.
1022 for (Index
= 0; Index
< mUsbTable
->Count
; Index
++) {
1023 UserId
= (UINT8
*) &mUsbTable
->UserInfo
[Index
].UserId
;
1024 NewUserId
= (UINT8
*) (UserInfo
+ 1);
1025 if (CompareMem (UserId
, NewUserId
, sizeof (EFI_USER_INFO_IDENTIFIER
)) == 0) {
1027 // The user's ID is found in the UsbTable.
1029 UserToken
= mUsbTable
->UserInfo
[Index
].Token
;
1030 if (CompareMem (UserToken
, ReadToken
, HASHED_CREDENTIAL_LEN
) == 0) {
1032 // The read token matches with the one in UsbTable.
1034 CopyMem (Identifier
, UserId
, sizeof (EFI_USER_INFO_IDENTIFIER
));
1035 FreePool (UserInfo
);
1041 FreePool (UserInfo
);
1043 return EFI_NOT_READY
;
1048 Indicate that user interface interaction has begun for the specified credential.
1050 This function is called when a credential provider is selected by the user. If
1051 AutoLogon returns FALSE, then the user interface will be constructed by the User
1054 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.
1055 @param[out] AutoLogon On return, points to the credential provider's capabilities
1056 after the credential provider has been selected by the user.
1058 @retval EFI_SUCCESS Credential provider successfully selected.
1059 @retval EFI_INVALID_PARAMETER AutoLogon is NULL.
1065 IN CONST EFI_USER_CREDENTIAL_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
;
1080 Indicate that user interface interaction has ended for the specified credential.
1082 This function is called when a credential provider is deselected by the user.
1084 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.
1086 @retval EFI_SUCCESS Credential provider successfully deselected.
1091 CredentialDeselect (
1092 IN CONST EFI_USER_CREDENTIAL_PROTOCOL
*This
1096 return EFI_INVALID_PARAMETER
;
1103 Return the default logon behavior for this user credential.
1105 This function reports the default login behavior regarding this credential provider.
1107 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.
1108 @param[out] AutoLogon On return, holds whether the credential provider should be used
1109 by default to automatically log on the user.
1111 @retval EFI_SUCCESS Default information successfully returned.
1112 @retval EFI_INVALID_PARAMETER AutoLogon is NULL.
1118 IN CONST EFI_USER_CREDENTIAL_PROTOCOL
*This
,
1119 OUT EFI_CREDENTIAL_LOGON_FLAGS
*AutoLogon
1122 if ((This
== NULL
) || (AutoLogon
== NULL
)) {
1123 return EFI_INVALID_PARAMETER
;
1126 *AutoLogon
= EFI_CREDENTIAL_LOGON_FLAG_DEFAULT
| EFI_CREDENTIAL_LOGON_FLAG_AUTO
;
1132 Return information attached to the credential provider.
1134 This function returns user information.
1136 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.
1137 @param[in] UserInfo Handle of the user information data record.
1138 @param[out] Info On entry, points to a buffer of at least *InfoSize bytes. On
1139 exit, holds the user information. If the buffer is too small
1140 to hold the information, then EFI_BUFFER_TOO_SMALL is returned
1141 and InfoSize is updated to contain the number of bytes actually
1143 @param[in, out] InfoSize On entry, points to the size of Info. On return, points to the
1144 size of the user information.
1146 @retval EFI_SUCCESS Information returned successfully.
1147 @retval EFI_BUFFER_TOO_SMALL The size specified by InfoSize is too small to hold all of the
1148 user information. The size required is returned in *InfoSize.
1149 @retval EFI_INVALID_PARAMETER Info is NULL or InfoSize is NULL.
1150 @retval EFI_NOT_FOUND The specified UserInfo does not refer to a valid user info handle.
1156 IN CONST EFI_USER_CREDENTIAL_PROTOCOL
*This
,
1157 IN EFI_USER_INFO_HANDLE UserInfo
,
1158 OUT EFI_USER_INFO
*Info
,
1159 IN OUT UINTN
*InfoSize
1162 EFI_USER_INFO
*CredentialInfo
;
1165 if ((This
== NULL
) || (InfoSize
== NULL
) || (Info
== NULL
)) {
1166 return EFI_INVALID_PARAMETER
;
1169 if ((UserInfo
== NULL
) || (mUsbInfoHandle
== NULL
)) {
1170 return EFI_NOT_FOUND
;
1174 // Find information handle in credential info table.
1176 for (Index
= 0; Index
< mUsbInfoHandle
->Count
; Index
++) {
1177 CredentialInfo
= mUsbInfoHandle
->Info
[Index
];
1178 if (UserInfo
== (EFI_USER_INFO_HANDLE
)CredentialInfo
) {
1180 // The handle is found, copy the user info.
1182 if (CredentialInfo
->InfoSize
> *InfoSize
) {
1183 *InfoSize
= CredentialInfo
->InfoSize
;
1184 return EFI_BUFFER_TOO_SMALL
;
1187 CopyMem (Info
, CredentialInfo
, CredentialInfo
->InfoSize
);
1192 return EFI_NOT_FOUND
;
1197 Enumerate all of the user informations on the credential provider.
1199 This function returns the next user information record. To retrieve the first user
1200 information record handle, point UserInfo at a NULL. Each subsequent call will retrieve
1201 another user information record handle until there are no more, at which point UserInfo
1204 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.
1205 @param[in, out] UserInfo On entry, points to the previous user information handle or NULL
1206 to start enumeration. On exit, points to the next user information
1207 handle or NULL if there is no more user information.
1209 @retval EFI_SUCCESS User information returned.
1210 @retval EFI_NOT_FOUND No more user information found.
1211 @retval EFI_INVALID_PARAMETER UserInfo is NULL.
1216 CredentialGetNextInfo (
1217 IN CONST EFI_USER_CREDENTIAL_PROTOCOL
*This
,
1218 IN OUT EFI_USER_INFO_HANDLE
*UserInfo
1221 EFI_USER_INFO
*Info
;
1222 CHAR16
*ProvNameStr
;
1227 if ((This
== NULL
) || (UserInfo
== NULL
)) {
1228 return EFI_INVALID_PARAMETER
;
1231 if (mUsbInfoHandle
== NULL
) {
1233 // Initilized user info table. There are 4 user info records in the table.
1235 InfoLen
= sizeof (USB_CREDENTIAL_INFO
) + (4 - 1) * sizeof (EFI_USER_INFO
*);
1236 mUsbInfoHandle
= AllocateZeroPool (InfoLen
);
1237 if (mUsbInfoHandle
== NULL
) {
1239 return EFI_NOT_FOUND
;
1243 // The first information, Credential Provider info.
1245 InfoLen
= sizeof (EFI_USER_INFO
) + sizeof (EFI_GUID
);
1246 Info
= AllocateZeroPool (InfoLen
);
1247 ASSERT (Info
!= NULL
);
1249 Info
->InfoType
= EFI_USER_INFO_CREDENTIAL_PROVIDER_RECORD
;
1250 Info
->InfoSize
= (UINT32
) InfoLen
;
1251 Info
->InfoAttribs
= EFI_USER_INFO_PROTECTED
;
1252 CopyGuid (&Info
->Credential
, &mUsbCredentialGuid
);
1253 CopyGuid ((EFI_GUID
*)(Info
+ 1), &mUsbCredentialGuid
);
1255 mUsbInfoHandle
->Info
[0] = Info
;
1256 mUsbInfoHandle
->Count
++;
1259 // The second information, Credential Provider name info.
1261 ProvNameStr
= GetStringById (STRING_TOKEN (STR_PROVIDER_NAME
));
1262 ProvStrLen
= StrSize (ProvNameStr
);
1263 InfoLen
= sizeof (EFI_USER_INFO
) + ProvStrLen
;
1264 Info
= AllocateZeroPool (InfoLen
);
1265 ASSERT (Info
!= NULL
);
1267 Info
->InfoType
= EFI_USER_INFO_CREDENTIAL_PROVIDER_NAME_RECORD
;
1268 Info
->InfoSize
= (UINT32
) InfoLen
;
1269 Info
->InfoAttribs
= EFI_USER_INFO_PROTECTED
;
1270 CopyGuid (&Info
->Credential
, &mUsbCredentialGuid
);
1271 CopyMem ((UINT8
*)(Info
+ 1), ProvNameStr
, ProvStrLen
);
1272 FreePool (ProvNameStr
);
1274 mUsbInfoHandle
->Info
[1] = Info
;
1275 mUsbInfoHandle
->Count
++;
1278 // The third information, Credential Provider type info.
1280 InfoLen
= sizeof (EFI_USER_INFO
) + sizeof (EFI_GUID
);
1281 Info
= AllocateZeroPool (InfoLen
);
1282 ASSERT (Info
!= NULL
);
1284 Info
->InfoType
= EFI_USER_INFO_CREDENTIAL_TYPE_RECORD
;
1285 Info
->InfoSize
= (UINT32
) InfoLen
;
1286 Info
->InfoAttribs
= EFI_USER_INFO_PROTECTED
;
1287 CopyGuid (&Info
->Credential
, &mUsbCredentialGuid
);
1288 CopyGuid ((EFI_GUID
*)(Info
+ 1), &gEfiUserCredentialClassSecureCardGuid
);
1290 mUsbInfoHandle
->Info
[2] = Info
;
1291 mUsbInfoHandle
->Count
++;
1294 // The fourth information, Credential Provider type name info.
1296 ProvNameStr
= GetStringById (STRING_TOKEN (STR_PROVIDER_TYPE_NAME
));
1297 ProvStrLen
= StrSize (ProvNameStr
);
1298 InfoLen
= sizeof (EFI_USER_INFO
) + ProvStrLen
;
1299 Info
= AllocateZeroPool (InfoLen
);
1300 ASSERT (Info
!= NULL
);
1302 Info
->InfoType
= EFI_USER_INFO_CREDENTIAL_PROVIDER_NAME_RECORD
;
1303 Info
->InfoSize
= (UINT32
) InfoLen
;
1304 Info
->InfoAttribs
= EFI_USER_INFO_PROTECTED
;
1305 CopyGuid (&Info
->Credential
, &mUsbCredentialGuid
);
1306 CopyMem ((UINT8
*)(Info
+ 1), ProvNameStr
, ProvStrLen
);
1307 FreePool (ProvNameStr
);
1309 mUsbInfoHandle
->Info
[3] = Info
;
1310 mUsbInfoHandle
->Count
++;
1313 if (*UserInfo
== NULL
) {
1315 // Return the first info handle.
1317 *UserInfo
= (EFI_USER_INFO_HANDLE
) mUsbInfoHandle
->Info
[0];
1322 // Find information handle in credential info table.
1324 for (Index
= 0; Index
< mUsbInfoHandle
->Count
; Index
++) {
1325 Info
= mUsbInfoHandle
->Info
[Index
];
1326 if (*UserInfo
== (EFI_USER_INFO_HANDLE
)Info
) {
1328 // The handle is found, get the next one.
1330 if (Index
== mUsbInfoHandle
->Count
- 1) {
1332 // Already last one.
1335 return EFI_NOT_FOUND
;
1338 *UserInfo
= (EFI_USER_INFO_HANDLE
)mUsbInfoHandle
->Info
[Index
];
1344 return EFI_NOT_FOUND
;
1349 Main entry for this driver.
1351 @param ImageHandle Image handle this driver.
1352 @param SystemTable Pointer to SystemTable.
1354 @retval EFI_SUCESS This function always complete successfully.
1360 IN EFI_HANDLE ImageHandle
,
1361 IN EFI_SYSTEM_TABLE
*SystemTable
1367 // Init credential table.
1369 Status
= InitCredentialTable ();
1370 if (EFI_ERROR (Status
)) {
1375 // Init Form Browser
1377 Status
= InitFormBrowser ();
1378 if (EFI_ERROR (Status
)) {
1383 // Install protocol interfaces for the Usb Credential Provider.
1385 Status
= gBS
->InstallProtocolInterface (
1386 &mCallbackInfo
->DriverHandle
,
1387 &gEfiUserCredentialProtocolGuid
,
1388 EFI_NATIVE_INTERFACE
,
1389 &gUsbCredentialProviderDriver