2 This driver produces Security2 and Security architectural protocol based on SecurityManagementLib.
4 Copyright (c) 2006 - 2013, 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.
17 #include <Protocol/Security.h>
18 #include <Protocol/Security2.h>
19 #include <Library/DebugLib.h>
20 #include <Library/UefiBootServicesTableLib.h>
21 #include <Library/UefiDriverEntryPoint.h>
22 #include <Library/SecurityManagementLib.h>
25 // Handle for the Security Architectural Protocol instance produced by this driver
27 EFI_HANDLE mSecurityArchProtocolHandle
= NULL
;
30 The EFI_SECURITY_ARCH_PROTOCOL (SAP) is used to abstract platform-specific
31 policy from the DXE core response to an attempt to use a file that returns a
32 given status for the authentication check from the section extraction protocol.
34 The possible responses in a given SAP implementation may include locking
35 flash upon failure to authenticate, attestation logging for all signed drivers,
36 and other exception operations. The File parameter allows for possible logging
37 within the SAP of the driver.
39 If File is NULL, then EFI_INVALID_PARAMETER is returned.
41 If the file specified by File with an authentication status specified by
42 AuthenticationStatus is safe for the DXE Core to use, then EFI_SUCCESS is returned.
44 If the file specified by File with an authentication status specified by
45 AuthenticationStatus is not safe for the DXE Core to use under any circumstances,
46 then EFI_ACCESS_DENIED is returned.
48 If the file specified by File with an authentication status specified by
49 AuthenticationStatus is not safe for the DXE Core to use right now, but it
50 might be possible to use it at a future time, then EFI_SECURITY_VIOLATION is
53 @param This The EFI_SECURITY_ARCH_PROTOCOL instance.
54 @param AuthenticationStatus
55 This is the authentication type returned from the Section
56 Extraction protocol. See the Section Extraction Protocol
57 Specification for details on this type.
58 @param File This is a pointer to the device path of the file that is
59 being dispatched. This will optionally be used for logging.
61 @retval EFI_SUCCESS Do nothing and return success.
62 @retval EFI_INVALID_PARAMETER File is NULL.
66 SecurityStubAuthenticateState (
67 IN CONST EFI_SECURITY_ARCH_PROTOCOL
*This
,
68 IN UINT32 AuthenticationStatus
,
69 IN CONST EFI_DEVICE_PATH_PROTOCOL
*File
74 Status
= ExecuteSecurity2Handlers (EFI_AUTH_OPERATION_AUTHENTICATION_STATE
,
81 if (Status
== EFI_SUCCESS
) {
82 Status
= ExecuteSecurityHandlers (AuthenticationStatus
, File
);
89 The DXE Foundation uses this service to measure and/or verify a UEFI image.
91 This service abstracts the invocation of Trusted Computing Group (TCG) measured boot, UEFI
92 Secure boot, and UEFI User Identity infrastructure. For the former two, the DXE Foundation
93 invokes the FileAuthentication() with a DevicePath and corresponding image in
94 FileBuffer memory. The TCG measurement code will record the FileBuffer contents into the
95 appropriate PCR. The image verification logic will confirm the integrity and provenance of the
96 image in FileBuffer of length FileSize . The origin of the image will be DevicePath in
98 If the FileBuffer is NULL, the interface will determine if the DevicePath can be connected
99 in order to support the User Identification policy.
101 @param This The EFI_SECURITY2_ARCH_PROTOCOL instance.
102 @param File A pointer to the device path of the file that is
103 being dispatched. This will optionally be used for logging.
104 @param FileBuffer A pointer to the buffer with the UEFI file image.
105 @param FileSize The size of the file.
106 @param BootPolicy A boot policy that was used to call LoadImage() UEFI service. If
107 FileAuthentication() is invoked not from the LoadImage(),
108 BootPolicy must be set to FALSE.
110 @retval EFI_SUCCESS The file specified by DevicePath and non-NULL
111 FileBuffer did authenticate, and the platform policy dictates
112 that the DXE Foundation may use the file.
113 @retval EFI_SUCCESS The device path specified by NULL device path DevicePath
114 and non-NULL FileBuffer did authenticate, and the platform
115 policy dictates that the DXE Foundation may execute the image in
117 @retval EFI_SUCCESS FileBuffer is NULL and current user has permission to start
118 UEFI device drivers on the device path specified by DevicePath.
119 @retval EFI_SECURITY_VIOLATION The file specified by DevicePath and FileBuffer did not
120 authenticate, and the platform policy dictates that the file should be
121 placed in the untrusted state. The image has been added to the file
123 @retval EFI_ACCESS_DENIED The file specified by File and FileBuffer did not
124 authenticate, and the platform policy dictates that the DXE
125 Foundation many not use File.
126 @retval EFI_SECURITY_VIOLATION FileBuffer is NULL and the user has no
127 permission to start UEFI device drivers on the device path specified
129 @retval EFI_SECURITY_VIOLATION FileBuffer is not NULL and the user has no permission to load
130 drivers from the device path specified by DevicePath. The
131 image has been added into the list of the deferred images.
135 Security2StubAuthenticate (
136 IN CONST EFI_SECURITY2_ARCH_PROTOCOL
*This
,
137 IN CONST EFI_DEVICE_PATH_PROTOCOL
*File
,
140 IN BOOLEAN BootPolicy
143 return ExecuteSecurity2Handlers (EFI_AUTH_OPERATION_VERIFY_IMAGE
|
144 EFI_AUTH_OPERATION_DEFER_IMAGE_LOAD
|
145 EFI_AUTH_OPERATION_MEASURE_IMAGE
|
146 EFI_AUTH_OPERATION_CONNECT_POLICY
,
156 // Security2 and Security Architectural Protocol instance produced by this driver
158 EFI_SECURITY_ARCH_PROTOCOL mSecurityStub
= {
159 SecurityStubAuthenticateState
162 EFI_SECURITY2_ARCH_PROTOCOL mSecurity2Stub
= {
163 Security2StubAuthenticate
167 Installs Security2 and Security Architectural Protocol.
169 @param ImageHandle The image handle of this driver.
170 @param SystemTable A pointer to the EFI System Table.
172 @retval EFI_SUCCESS Install the sample Security Architectural Protocol successfully.
177 SecurityStubInitialize (
178 IN EFI_HANDLE ImageHandle
,
179 IN EFI_SYSTEM_TABLE
*SystemTable
185 // Make sure the Security Architectural Protocol is not already installed in the system
187 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL
, &gEfiSecurity2ArchProtocolGuid
);
188 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL
, &gEfiSecurityArchProtocolGuid
);
191 // Install the Security Architectural Protocol onto a new handle
193 Status
= gBS
->InstallMultipleProtocolInterfaces (
194 &mSecurityArchProtocolHandle
,
195 &gEfiSecurity2ArchProtocolGuid
,
197 &gEfiSecurityArchProtocolGuid
,
201 ASSERT_EFI_ERROR (Status
);