2 Usb Credential Provider driver implemenetation.
4 Copyright (c) 2009 - 2010, 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
);
1040 FreePool (UserInfo
);
1043 // The read token mismatch with the User's Token.
1044 // Only check token.
1046 for (Index
= 0; Index
< mUsbTable
->Count
; Index
++) {
1047 UserToken
= mUsbTable
->UserInfo
[Index
].Token
;
1048 if (CompareMem (UserToken
, ReadToken
, HASHED_CREDENTIAL_LEN
) == 0) {
1050 // The read token matches with the one in UsbTable.
1052 UserId
= (UINT8
*) &mUsbTable
->UserInfo
[Index
].UserId
;
1053 CopyMem (Identifier
, UserId
, sizeof (EFI_USER_INFO_IDENTIFIER
));
1058 return EFI_NOT_FOUND
;
1063 Indicate that user interface interaction has begun for the specified credential.
1065 This function is called when a credential provider is selected by the user. If
1066 AutoLogon returns FALSE, then the user interface will be constructed by the User
1069 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.
1070 @param[out] AutoLogon On return, points to the credential provider's capabilities
1071 after the credential provider has been selected by the user.
1073 @retval EFI_SUCCESS Credential provider successfully selected.
1074 @retval EFI_INVALID_PARAMETER AutoLogon is NULL.
1080 IN CONST EFI_USER_CREDENTIAL_PROTOCOL
*This
,
1081 OUT EFI_CREDENTIAL_LOGON_FLAGS
*AutoLogon
1084 if ((This
== NULL
) || (AutoLogon
== NULL
)) {
1085 return EFI_INVALID_PARAMETER
;
1088 *AutoLogon
= EFI_CREDENTIAL_LOGON_FLAG_DEFAULT
| EFI_CREDENTIAL_LOGON_FLAG_AUTO
;
1095 Indicate that user interface interaction has ended for the specified credential.
1097 This function is called when a credential provider is deselected by the user.
1099 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.
1101 @retval EFI_SUCCESS Credential provider successfully deselected.
1106 CredentialDeselect (
1107 IN CONST EFI_USER_CREDENTIAL_PROTOCOL
*This
1111 return EFI_INVALID_PARAMETER
;
1118 Return the default logon behavior for this user credential.
1120 This function reports the default login behavior regarding this credential provider.
1122 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.
1123 @param[out] AutoLogon On return, holds whether the credential provider should be used
1124 by default to automatically log on the user.
1126 @retval EFI_SUCCESS Default information successfully returned.
1127 @retval EFI_INVALID_PARAMETER AutoLogon is NULL.
1133 IN CONST EFI_USER_CREDENTIAL_PROTOCOL
*This
,
1134 OUT EFI_CREDENTIAL_LOGON_FLAGS
*AutoLogon
1137 if ((This
== NULL
) || (AutoLogon
== NULL
)) {
1138 return EFI_INVALID_PARAMETER
;
1141 *AutoLogon
= EFI_CREDENTIAL_LOGON_FLAG_DEFAULT
| EFI_CREDENTIAL_LOGON_FLAG_AUTO
;
1147 Return information attached to the credential provider.
1149 This function returns user information.
1151 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.
1152 @param[in] UserInfo Handle of the user information data record.
1153 @param[out] Info On entry, points to a buffer of at least *InfoSize bytes. On
1154 exit, holds the user information. If the buffer is too small
1155 to hold the information, then EFI_BUFFER_TOO_SMALL is returned
1156 and InfoSize is updated to contain the number of bytes actually
1158 @param[in, out] InfoSize On entry, points to the size of Info. On return, points to the
1159 size of the user information.
1161 @retval EFI_SUCCESS Information returned successfully.
1162 @retval EFI_BUFFER_TOO_SMALL The size specified by InfoSize is too small to hold all of the
1163 user information. The size required is returned in *InfoSize.
1164 @retval EFI_INVALID_PARAMETER Info is NULL or InfoSize is NULL.
1165 @retval EFI_NOT_FOUND The specified UserInfo does not refer to a valid user info handle.
1171 IN CONST EFI_USER_CREDENTIAL_PROTOCOL
*This
,
1172 IN EFI_USER_INFO_HANDLE UserInfo
,
1173 OUT EFI_USER_INFO
*Info
,
1174 IN OUT UINTN
*InfoSize
1177 EFI_USER_INFO
*CredentialInfo
;
1180 if ((This
== NULL
) || (InfoSize
== NULL
) || (Info
== NULL
)) {
1181 return EFI_INVALID_PARAMETER
;
1184 if ((UserInfo
== NULL
) || (mUsbInfoHandle
== NULL
)) {
1185 return EFI_NOT_FOUND
;
1189 // Find information handle in credential info table.
1191 for (Index
= 0; Index
< mUsbInfoHandle
->Count
; Index
++) {
1192 CredentialInfo
= mUsbInfoHandle
->Info
[Index
];
1193 if (UserInfo
== (EFI_USER_INFO_HANDLE
)CredentialInfo
) {
1195 // The handle is found, copy the user info.
1197 if (CredentialInfo
->InfoSize
> *InfoSize
) {
1198 *InfoSize
= CredentialInfo
->InfoSize
;
1199 return EFI_BUFFER_TOO_SMALL
;
1202 CopyMem (Info
, CredentialInfo
, CredentialInfo
->InfoSize
);
1207 return EFI_NOT_FOUND
;
1212 Enumerate all of the user informations on the credential provider.
1214 This function returns the next user information record. To retrieve the first user
1215 information record handle, point UserInfo at a NULL. Each subsequent call will retrieve
1216 another user information record handle until there are no more, at which point UserInfo
1219 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.
1220 @param[in, out] UserInfo On entry, points to the previous user information handle or NULL
1221 to start enumeration. On exit, points to the next user information
1222 handle or NULL if there is no more user information.
1224 @retval EFI_SUCCESS User information returned.
1225 @retval EFI_NOT_FOUND No more user information found.
1226 @retval EFI_INVALID_PARAMETER UserInfo is NULL.
1231 CredentialGetNextInfo (
1232 IN CONST EFI_USER_CREDENTIAL_PROTOCOL
*This
,
1233 IN OUT EFI_USER_INFO_HANDLE
*UserInfo
1236 EFI_USER_INFO
*Info
;
1237 CHAR16
*ProvNameStr
;
1242 if ((This
== NULL
) || (UserInfo
== NULL
)) {
1243 return EFI_INVALID_PARAMETER
;
1246 if (mUsbInfoHandle
== NULL
) {
1248 // Initilized user info table. There are 4 user info records in the table.
1250 InfoLen
= sizeof (USB_CREDENTIAL_INFO
) + (4 - 1) * sizeof (EFI_USER_INFO
*);
1251 mUsbInfoHandle
= AllocateZeroPool (InfoLen
);
1252 if (mUsbInfoHandle
== NULL
) {
1254 return EFI_NOT_FOUND
;
1258 // The first information, Credential Provider info.
1260 InfoLen
= sizeof (EFI_USER_INFO
) + sizeof (EFI_GUID
);
1261 Info
= AllocateZeroPool (InfoLen
);
1262 ASSERT (Info
!= NULL
);
1264 Info
->InfoType
= EFI_USER_INFO_CREDENTIAL_PROVIDER_RECORD
;
1265 Info
->InfoSize
= (UINT32
) InfoLen
;
1266 Info
->InfoAttribs
= EFI_USER_INFO_PROTECTED
;
1267 CopyGuid (&Info
->Credential
, &mUsbCredentialGuid
);
1268 CopyGuid ((EFI_GUID
*)(Info
+ 1), &mUsbCredentialGuid
);
1270 mUsbInfoHandle
->Info
[0] = Info
;
1271 mUsbInfoHandle
->Count
++;
1274 // The second information, Credential Provider name info.
1276 ProvNameStr
= GetStringById (STRING_TOKEN (STR_PROVIDER_NAME
));
1277 ProvStrLen
= StrSize (ProvNameStr
);
1278 InfoLen
= sizeof (EFI_USER_INFO
) + ProvStrLen
;
1279 Info
= AllocateZeroPool (InfoLen
);
1280 ASSERT (Info
!= NULL
);
1282 Info
->InfoType
= EFI_USER_INFO_CREDENTIAL_PROVIDER_NAME_RECORD
;
1283 Info
->InfoSize
= (UINT32
) InfoLen
;
1284 Info
->InfoAttribs
= EFI_USER_INFO_PROTECTED
;
1285 CopyGuid (&Info
->Credential
, &mUsbCredentialGuid
);
1286 CopyMem ((UINT8
*)(Info
+ 1), ProvNameStr
, ProvStrLen
);
1287 FreePool (ProvNameStr
);
1289 mUsbInfoHandle
->Info
[1] = Info
;
1290 mUsbInfoHandle
->Count
++;
1293 // The third information, Credential Provider type info.
1295 InfoLen
= sizeof (EFI_USER_INFO
) + sizeof (EFI_GUID
);
1296 Info
= AllocateZeroPool (InfoLen
);
1297 ASSERT (Info
!= NULL
);
1299 Info
->InfoType
= EFI_USER_INFO_CREDENTIAL_TYPE_RECORD
;
1300 Info
->InfoSize
= (UINT32
) InfoLen
;
1301 Info
->InfoAttribs
= EFI_USER_INFO_PROTECTED
;
1302 CopyGuid (&Info
->Credential
, &mUsbCredentialGuid
);
1303 CopyGuid ((EFI_GUID
*)(Info
+ 1), &gEfiUserCredentialClassSecureCardGuid
);
1305 mUsbInfoHandle
->Info
[2] = Info
;
1306 mUsbInfoHandle
->Count
++;
1309 // The fourth information, Credential Provider type name info.
1311 ProvNameStr
= GetStringById (STRING_TOKEN (STR_PROVIDER_TYPE_NAME
));
1312 ProvStrLen
= StrSize (ProvNameStr
);
1313 InfoLen
= sizeof (EFI_USER_INFO
) + ProvStrLen
;
1314 Info
= AllocateZeroPool (InfoLen
);
1315 ASSERT (Info
!= NULL
);
1317 Info
->InfoType
= EFI_USER_INFO_CREDENTIAL_PROVIDER_NAME_RECORD
;
1318 Info
->InfoSize
= (UINT32
) InfoLen
;
1319 Info
->InfoAttribs
= EFI_USER_INFO_PROTECTED
;
1320 CopyGuid (&Info
->Credential
, &mUsbCredentialGuid
);
1321 CopyMem ((UINT8
*)(Info
+ 1), ProvNameStr
, ProvStrLen
);
1322 FreePool (ProvNameStr
);
1324 mUsbInfoHandle
->Info
[3] = Info
;
1325 mUsbInfoHandle
->Count
++;
1328 if (*UserInfo
== NULL
) {
1330 // Return the first info handle.
1332 *UserInfo
= (EFI_USER_INFO_HANDLE
) mUsbInfoHandle
->Info
[0];
1337 // Find information handle in credential info table.
1339 for (Index
= 0; Index
< mUsbInfoHandle
->Count
; Index
++) {
1340 Info
= mUsbInfoHandle
->Info
[Index
];
1341 if (*UserInfo
== (EFI_USER_INFO_HANDLE
)Info
) {
1343 // The handle is found, get the next one.
1345 if (Index
== mUsbInfoHandle
->Count
- 1) {
1347 // Already last one.
1350 return EFI_NOT_FOUND
;
1353 *UserInfo
= (EFI_USER_INFO_HANDLE
)mUsbInfoHandle
->Info
[Index
];
1359 return EFI_NOT_FOUND
;
1364 Main entry for this driver.
1366 @param ImageHandle Image handle this driver.
1367 @param SystemTable Pointer to SystemTable.
1369 @retval EFI_SUCESS This function always complete successfully.
1375 IN EFI_HANDLE ImageHandle
,
1376 IN EFI_SYSTEM_TABLE
*SystemTable
1382 // Init credential table.
1384 Status
= InitCredentialTable ();
1385 if (EFI_ERROR (Status
)) {
1390 // Init Form Browser
1392 Status
= InitFormBrowser ();
1393 if (EFI_ERROR (Status
)) {
1398 // Install protocol interfaces for the Usb Credential Provider.
1400 Status
= gBS
->InstallProtocolInterface (
1401 &mCallbackInfo
->DriverHandle
,
1402 &gEfiUserCredentialProtocolGuid
,
1403 EFI_NATIVE_INTERFACE
,
1404 &gUsbCredentialProviderDriver