1 /** @file
2   Usb Credential Provider driver header file.
3 
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
9 
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.
12 
13 **/
14 
15 #ifndef _USB_CREDENTIAL_PROVIDER_H_
16 #define _USB_CREDENTIAL_PROVIDER_H_
17 
18 #include <Uefi.h>
19 
20 #include <Guid/GlobalVariable.h>
21 #include <Guid/FileInfo.h>
22 #include <Guid/SecurityPkgTokenSpace.h>
23 #include <Guid/UsbCredentialProviderHii.h>
24 
25 #include <Protocol/SimpleFileSystem.h>
26 #include <Protocol/BlockIo.h>
27 #include <Protocol/UserCredential2.h>
28 #include <Protocol/UserManager.h>
29 
30 #include <Library/UefiRuntimeServicesTableLib.h>
31 #include <Library/UefiBootServicesTableLib.h>
32 #include <Library/MemoryAllocationLib.h>
33 #include <Library/BaseMemoryLib.h>
34 #include <Library/DevicePathLib.h>
35 #include <Library/BaseCryptLib.h>
36 #include <Library/DebugLib.h>
37 #include <Library/UefiLib.h>
38 #include <Library/PrintLib.h>
39 #include <Library/HiiLib.h>
40 #include <Library/PcdLib.h>
41 
42 extern UINT8      UsbCredentialProviderStrings[];
43 
44 #define USB_TABLE_INC          16
45 #define HASHED_CREDENTIAL_LEN  20
46 
47 //
48 // Save the enroll user credential Information.
49 //
50 typedef struct {
51   EFI_USER_INFO_IDENTIFIER  UserId;
52   UINT8                     Token[HASHED_CREDENTIAL_LEN];
53 } USB_INFO;
54 
55 //
56 // USB Credential Table.
57 //
58 typedef struct {
59   UINTN     Count;
60   UINTN     MaxCount;
61   USB_INFO  UserInfo[1];
62 } CREDENTIAL_TABLE;
63 
64 //
65 // The user information on the USB provider.
66 //
67 typedef struct {
68   UINTN                         Count;
69   EFI_USER_INFO                 *Info[1];
70 } USB_CREDENTIAL_INFO;
71 
72 #define USB_PROVIDER_SIGNATURE  SIGNATURE_32 ('U', 'S', 'B', 'P')
73 
74 typedef struct {
75   UINTN                           Signature;
76   EFI_HANDLE                      DriverHandle;
77   EFI_HII_HANDLE                  HiiHandle;
78 } USB_PROVIDER_CALLBACK_INFO;
79 
80 /**
81   Enroll a user on a credential provider.
82 
83   This function enrolls and deletes a user profile using this credential provider.
84   If a user profile is successfully enrolled, it calls the User Manager Protocol
85   function Notify() to notify the user manager driver that credential information
86   has changed. If an enrolled user does exist, delete the user on the credential
87   provider.
88 
89   @param[in] This                Points to this instance of EFI_USER_CREDENTIAL2_PROTOCOL.
90   @param[in] User                The user profile to enroll.
91 
92   @retval EFI_SUCCESS            User profile was successfully enrolled.
93   @retval EFI_ACCESS_DENIED      Current user profile does not permit enrollment on the
94                                  user profile handle. Either the user profile cannot enroll
95                                  on any user profile or cannot enroll on a user profile
96                                  other than the current user profile.
97   @retval EFI_UNSUPPORTED        This credential provider does not support enrollment in
98                                  the pre-OS.
99   @retval EFI_DEVICE_ERROR       The new credential could not be created because of a device
100                                  error.
101   @retval EFI_INVALID_PARAMETER  User does not refer to a valid user profile handle.
102 
103 **/
104 EFI_STATUS
105 EFIAPI
106 CredentialEnroll (
107   IN CONST  EFI_USER_CREDENTIAL2_PROTOCOL       *This,
108   IN        EFI_USER_PROFILE_HANDLE             User
109   );
110 
111 /**
112   Returns the user interface information used during user identification.
113 
114   This function enrolls a user on this credential provider. If the user exists on
115   this credential provider, update the user information on this credential provider;
116   otherwise delete the user information on credential provider.
117 
118   @param[in]  This       Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
119   @param[out] Hii        On return, holds the HII database handle.
120   @param[out] FormSetId  On return, holds the identifier of the form set which contains
121                          the form used during user identification.
122   @param[out] FormId     On return, holds the identifier of the form used during user
123                          identification.
124 
125   @retval EFI_SUCCESS            Form returned successfully.
126   @retval EFI_NOT_FOUND          Form not returned.
127   @retval EFI_INVALID_PARAMETER  Hii is NULL or FormSetId is NULL or FormId is NULL.
128 
129 **/
130 EFI_STATUS
131 EFIAPI
132 CredentialForm (
133   IN CONST  EFI_USER_CREDENTIAL2_PROTOCOL       *This,
134   OUT       EFI_HII_HANDLE                      *Hii,
135   OUT       EFI_GUID                            *FormSetId,
136   OUT       EFI_FORM_ID                         *FormId
137   );
138 
139 /**
140   Returns bitmap used to describe the credential provider type.
141 
142   This optional function returns a bitmap which is less than or equal to the number
143   of pixels specified by Width and Height. If no such bitmap exists, then EFI_NOT_FOUND
144   is returned.
145 
146   @param[in]     This    Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
147   @param[in, out] Width  On entry, points to the desired bitmap width. If NULL then no
148                          bitmap information will be returned. On exit, points to the
149                          width of the bitmap returned.
150   @param[in, out] Height On entry, points to the desired bitmap height. If NULL then no
151                          bitmap information will be returned. On exit, points to the
152                          height of the bitmap returned.
153   @param[out]    Hii     On return, holds the HII database handle.
154   @param[out]    Image   On return, holds the HII image identifier.
155 
156   @retval EFI_SUCCESS            Image identifier returned successfully.
157   @retval EFI_NOT_FOUND          Image identifier not returned.
158   @retval EFI_INVALID_PARAMETER  Hii is NULL or Image is NULL.
159 
160 **/
161 EFI_STATUS
162 EFIAPI
163 CredentialTile (
164   IN CONST  EFI_USER_CREDENTIAL2_PROTOCOL       *This,
165   IN OUT    UINTN                               *Width,
166   IN OUT    UINTN                               *Height,
167   OUT       EFI_HII_HANDLE                      *Hii,
168   OUT       EFI_IMAGE_ID                        *Image
169   );
170 
171 /**
172   Returns string used to describe the credential provider type.
173 
174   This function returns a string which describes the credential provider. If no
175   such string exists, then EFI_NOT_FOUND is returned.
176 
177   @param[in]  This       Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
178   @param[out] Hii        On return, holds the HII database handle.
179   @param[out] String     On return, holds the HII string identifier.
180 
181   @retval EFI_SUCCESS            String identifier returned successfully.
182   @retval EFI_NOT_FOUND          String identifier not returned.
183   @retval EFI_INVALID_PARAMETER  Hii is NULL or String is NULL.
184 
185 **/
186 EFI_STATUS
187 EFIAPI
188 CredentialTitle (
189   IN CONST  EFI_USER_CREDENTIAL2_PROTOCOL       *This,
190   OUT       EFI_HII_HANDLE                      *Hii,
191   OUT       EFI_STRING_ID                       *String
192   );
193 
194 /**
195   Return the user identifier associated with the currently authenticated user.
196 
197   This function returns the user identifier of the user authenticated by this credential
198   provider. This function is called after the credential-related information has been
199   submitted on a form OR after a call to Default() has returned that this credential is
200   ready to log on.
201 
202   @param[in]  This           Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
203   @param[in]  User           The user profile handle of the user profile currently being
204                              considered by the user identity manager. If NULL, then no user
205                              profile is currently under consideration.
206   @param[out] Identifier     On return, points to the user identifier.
207 
208   @retval EFI_SUCCESS        User identifier returned successfully.
209   @retval EFI_NOT_READY      No user identifier can be returned.
210   @retval EFI_ACCESS_DENIED  The user has been locked out of this user credential.
211   @retval EFI_INVALID_PARAMETER  This is NULL, or Identifier is NULL.
212   @retval EFI_NOT_FOUND          User is not NULL, and the specified user handle can't be
213                                  found in user profile database.
214 
215 **/
216 EFI_STATUS
217 EFIAPI
218 CredentialUser (
219   IN CONST  EFI_USER_CREDENTIAL2_PROTOCOL       *This,
220   IN        EFI_USER_PROFILE_HANDLE             User,
221   OUT       EFI_USER_INFO_IDENTIFIER            *Identifier
222   );
223 
224 /**
225   Indicate that user interface interaction has begun for the specified credential.
226 
227   This function is called when a credential provider is selected by the user. If
228   AutoLogon returns FALSE, then the user interface will be constructed by the User
229   Identity Manager.
230 
231   @param[in]  This       Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
232   @param[out] AutoLogon  On return, points to the credential provider's capabilities
233                          after the credential provider has been selected by the user.
234 
235   @retval EFI_SUCCESS            Credential provider successfully selected.
236   @retval EFI_INVALID_PARAMETER  AutoLogon is NULL.
237 
238 **/
239 EFI_STATUS
240 EFIAPI
241 CredentialSelect (
242   IN  CONST  EFI_USER_CREDENTIAL2_PROTOCOL   *This,
243   OUT        EFI_CREDENTIAL_LOGON_FLAGS      *AutoLogon
244   );
245 
246 /**
247   Indicate that user interface interaction has ended for the specified credential.
248 
249   This function is called when a credential provider is deselected by the user.
250 
251   @param[in] This        Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
252 
253   @retval EFI_SUCCESS    Credential provider successfully deselected.
254 
255 **/
256 EFI_STATUS
257 EFIAPI
258 CredentialDeselect (
259   IN CONST  EFI_USER_CREDENTIAL2_PROTOCOL       *This
260   );
261 
262 /**
263   Return the default logon behavior for this user credential.
264 
265   This function reports the default login behavior regarding this credential provider.
266 
267   @param[in]  This       Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
268   @param[out] AutoLogon  On return, holds whether the credential provider should be used
269                          by default to automatically log on the user.
270 
271   @retval EFI_SUCCESS            Default information successfully returned.
272   @retval EFI_INVALID_PARAMETER  AutoLogon is NULL.
273 
274 **/
275 EFI_STATUS
276 EFIAPI
277 CredentialDefault (
278   IN CONST  EFI_USER_CREDENTIAL2_PROTOCOL       *This,
279   OUT       EFI_CREDENTIAL_LOGON_FLAGS          *AutoLogon
280   );
281 
282 /**
283   Return information attached to the credential provider.
284 
285   This function returns user information.
286 
287   @param[in]      This          Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
288   @param[in]      UserInfo      Handle of the user information data record.
289   @param[out]     Info          On entry, points to a buffer of at least *InfoSize bytes. On
290                                 exit, holds the user information. If the buffer is too small
291                                 to hold the information, then EFI_BUFFER_TOO_SMALL is returned
292                                 and InfoSize is updated to contain the number of bytes actually
293                                 required.
294   @param[in, out] InfoSize      On entry, points to the size of Info. On return, points to the
295                                 size of the user information.
296 
297   @retval EFI_SUCCESS           Information returned successfully.
298   @retval EFI_BUFFER_TOO_SMALL  The size specified by InfoSize is too small to hold all of the
299                                 user information. The size required is returned in *InfoSize.
300   @retval EFI_INVALID_PARAMETER Info is NULL or InfoSize is NULL.
301   @retval EFI_NOT_FOUND         The specified UserInfo does not refer to a valid user info handle.
302 
303 **/
304 EFI_STATUS
305 EFIAPI
306 CredentialGetInfo (
307   IN CONST  EFI_USER_CREDENTIAL2_PROTOCOL       *This,
308   IN        EFI_USER_INFO_HANDLE                UserInfo,
309   OUT       EFI_USER_INFO                       *Info,
310   IN OUT    UINTN                               *InfoSize
311   );
312 
313 /**
314   Enumerate all of the user informations on the credential provider.
315 
316   This function returns the next user information record. To retrieve the first user
317   information record handle, point UserInfo at a NULL. Each subsequent call will retrieve
318   another user information record handle until there are no more, at which point UserInfo
319   will point to NULL.
320 
321   @param[in]      This     Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
322   @param[in, out] UserInfo On entry, points to the previous user information handle or NULL
323                            to start enumeration. On exit, points to the next user information
324                            handle or NULL if there is no more user information.
325 
326   @retval EFI_SUCCESS            User information returned.
327   @retval EFI_NOT_FOUND          No more user information found.
328   @retval EFI_INVALID_PARAMETER  UserInfo is NULL.
329 
330 **/
331 EFI_STATUS
332 EFIAPI
333 CredentialGetNextInfo (
334   IN CONST  EFI_USER_CREDENTIAL2_PROTOCOL       *This,
335   IN OUT    EFI_USER_INFO_HANDLE                *UserInfo
336   );
337 
338 /**
339   Delete a user on this credential provider.
340 
341   This function deletes a user on this credential provider.
342 
343   @param[in]     This            Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.
344   @param[in]     User            The user profile handle to delete.
345 
346   @retval EFI_SUCCESS            User profile was successfully deleted.
347   @retval EFI_ACCESS_DENIED      Current user profile does not permit deletion on the user profile handle.
348                                  Either the user profile cannot delete on any user profile or cannot delete
349                                  on a user profile other than the current user profile.
350   @retval EFI_UNSUPPORTED        This credential provider does not support deletion in the pre-OS.
351   @retval EFI_DEVICE_ERROR       The new credential could not be deleted because of a device error.
352   @retval EFI_INVALID_PARAMETER  User does not refer to a valid user profile handle.
353 **/
354 EFI_STATUS
355 EFIAPI
356 CredentialDelete (
357   IN CONST  EFI_USER_CREDENTIAL2_PROTOCOL       *This,
358   IN        EFI_USER_PROFILE_HANDLE             User
359   );
360 
361 #endif
362