]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/SecurityStubDxe/SecurityStub.c
Removes a useless condition in PxeBcImpl.c.
[mirror_edk2.git] / MdeModulePkg / Universal / SecurityStubDxe / SecurityStub.c
CommitLineData
ce2f5557 1/** @file\r
bc2dfdbc 2 This driver produces Security2 and Security architectural protocol based on SecurityManagementLib.\r
cd98f305 3 \r
bc2dfdbc 4 Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
e5eed7d3 5 This program and the accompanying materials \r
ce2f5557 6 are licensed and made available under the terms and conditions of the BSD License \r
7 which accompanies this distribution. The full text of the license may be found at \r
8 http://opensource.org/licenses/bsd-license.php \r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
12\r
13**/\r
14\r
15\r
109e9a61
LG
16#include <Uefi.h>\r
17#include <Protocol/Security.h>\r
bc2dfdbc 18#include <Protocol/Security2.h>\r
109e9a61
LG
19#include <Library/DebugLib.h>\r
20#include <Library/UefiBootServicesTableLib.h>\r
21#include <Library/UefiDriverEntryPoint.h>\r
cd98f305 22#include <Library/SecurityManagementLib.h>\r
ce2f5557 23\r
24//\r
25// Handle for the Security Architectural Protocol instance produced by this driver\r
26//\r
27EFI_HANDLE mSecurityArchProtocolHandle = NULL;\r
28\r
ce2f5557 29/**\r
30 The EFI_SECURITY_ARCH_PROTOCOL (SAP) is used to abstract platform-specific \r
31 policy from the DXE core response to an attempt to use a file that returns a \r
32 given status for the authentication check from the section extraction protocol. \r
33\r
34 The possible responses in a given SAP implementation may include locking \r
35 flash upon failure to authenticate, attestation logging for all signed drivers, \r
36 and other exception operations. The File parameter allows for possible logging \r
37 within the SAP of the driver.\r
38\r
39 If File is NULL, then EFI_INVALID_PARAMETER is returned.\r
40\r
41 If the file specified by File with an authentication status specified by \r
42 AuthenticationStatus is safe for the DXE Core to use, then EFI_SUCCESS is returned.\r
43\r
44 If the file specified by File with an authentication status specified by \r
45 AuthenticationStatus is not safe for the DXE Core to use under any circumstances, \r
46 then EFI_ACCESS_DENIED is returned.\r
47\r
48 If the file specified by File with an authentication status specified by \r
49 AuthenticationStatus is not safe for the DXE Core to use right now, but it \r
50 might be possible to use it at a future time, then EFI_SECURITY_VIOLATION is \r
51 returned.\r
52\r
53 @param This The EFI_SECURITY_ARCH_PROTOCOL instance.\r
54 @param AuthenticationStatus \r
55 This is the authentication type returned from the Section\r
56 Extraction protocol. See the Section Extraction Protocol\r
57 Specification for details on this type.\r
58 @param File This is a pointer to the device path of the file that is\r
59 being dispatched. This will optionally be used for logging.\r
60\r
109e9a61 61 @retval EFI_SUCCESS Do nothing and return success.\r
5d69642d 62 @retval EFI_INVALID_PARAMETER File is NULL.\r
ce2f5557 63**/\r
64EFI_STATUS\r
65EFIAPI\r
66SecurityStubAuthenticateState (\r
c48d41d2
LG
67 IN CONST EFI_SECURITY_ARCH_PROTOCOL *This,\r
68 IN UINT32 AuthenticationStatus,\r
69 IN CONST EFI_DEVICE_PATH_PROTOCOL *File\r
ce2f5557 70 )\r
71{\r
bc2dfdbc
LG
72 return ExecuteSecurity2Handlers (EFI_AUTH_OPERATION_AUTHENTICATION_STATE, \r
73 AuthenticationStatus, \r
74 File,\r
75 NULL, \r
76 0, \r
77 FALSE\r
78 );\r
79}\r
80\r
81/**\r
82 The DXE Foundation uses this service to measure and/or verify a UEFI image.\r
83\r
84 This service abstracts the invocation of Trusted Computing Group (TCG) measured boot, UEFI\r
85 Secure boot, and UEFI User Identity infrastructure. For the former two, the DXE Foundation\r
86 invokes the FileAuthentication() with a DevicePath and corresponding image in\r
87 FileBuffer memory. The TCG measurement code will record the FileBuffer contents into the\r
88 appropriate PCR. The image verification logic will confirm the integrity and provenance of the\r
89 image in FileBuffer of length FileSize . The origin of the image will be DevicePath in\r
90 these cases.\r
91 If the FileBuffer is NULL, the interface will determine if the DevicePath can be connected\r
92 in order to support the User Identification policy.\r
93 \r
94 @param This The EFI_SECURITY2_ARCH_PROTOCOL instance.\r
95 @param File A pointer to the device path of the file that is\r
96 being dispatched. This will optionally be used for logging.\r
97 @param FileBuffer A pointer to the buffer with the UEFI file image.\r
98 @param FileSize The size of the file.\r
99 @param BootPolicy A boot policy that was used to call LoadImage() UEFI service. If\r
100 FileAuthentication() is invoked not from the LoadImage(),\r
101 BootPolicy must be set to FALSE.\r
102 \r
103 @retval EFI_SUCCESS The file specified by DevicePath and non-NULL\r
104 FileBuffer did authenticate, and the platform policy dictates\r
105 that the DXE Foundation may use the file.\r
106 @retval EFI_SUCCESS The device path specified by NULL device path DevicePath\r
107 and non-NULL FileBuffer did authenticate, and the platform\r
108 policy dictates that the DXE Foundation may execute the image in\r
109 FileBuffer.\r
110 @retval EFI_SUCCESS FileBuffer is NULL and current user has permission to start\r
111 UEFI device drivers on the device path specified by DevicePath.\r
112 @retval EFI_SECURITY_VIOLATION The file specified by DevicePath and FileBuffer did not\r
113 authenticate, and the platform policy dictates that the file should be\r
114 placed in the untrusted state. The image has been added to the file\r
115 execution table.\r
116 @retval EFI_ACCESS_DENIED The file specified by File and FileBuffer did not\r
117 authenticate, and the platform policy dictates that the DXE\r
118 Foundation many not use File.\r
119 @retval EFI_SECURITY_VIOLATION FileBuffer is NULL and the user has no\r
120 permission to start UEFI device drivers on the device path specified\r
121 by DevicePath.\r
122 @retval EFI_SECURITY_VIOLATION FileBuffer is not NULL and the user has no permission to load\r
123 drivers from the device path specified by DevicePath. The\r
124 image has been added into the list of the deferred images.\r
125**/\r
126EFI_STATUS\r
127EFIAPI\r
128Security2StubAuthenticate (\r
129 IN CONST EFI_SECURITY2_ARCH_PROTOCOL *This,\r
130 IN CONST EFI_DEVICE_PATH_PROTOCOL *File,\r
131 IN VOID *FileBuffer,\r
132 IN UINTN FileSize,\r
133 IN BOOLEAN BootPolicy\r
134 )\r
135{\r
136 return ExecuteSecurity2Handlers (EFI_AUTH_OPERATION_VERIFY_IMAGE | \r
137 EFI_AUTH_OPERATION_DEFER_IMAGE_LOAD | \r
138 EFI_AUTH_OPERATION_MEASURE_IMAGE |\r
139 EFI_AUTH_OPERATION_CONNECT_POLICY, \r
140 0, \r
141 File,\r
142 FileBuffer, \r
143 FileSize, \r
144 BootPolicy\r
145 );\r
ce2f5557 146}\r
147\r
109e9a61 148//\r
bc2dfdbc 149// Security2 and Security Architectural Protocol instance produced by this driver\r
109e9a61
LG
150//\r
151EFI_SECURITY_ARCH_PROTOCOL mSecurityStub = { \r
152 SecurityStubAuthenticateState \r
153};\r
ce2f5557 154\r
bc2dfdbc
LG
155EFI_SECURITY2_ARCH_PROTOCOL mSecurity2Stub = { \r
156 Security2StubAuthenticate \r
157};\r
158\r
ce2f5557 159/**\r
bc2dfdbc 160 Installs Security2 and Security Architectural Protocol.\r
ce2f5557 161\r
109e9a61
LG
162 @param ImageHandle The image handle of this driver.\r
163 @param SystemTable A pointer to the EFI System Table.\r
ce2f5557 164 \r
5d69642d 165 @retval EFI_SUCCESS Install the sample Security Architectural Protocol successfully.\r
ce2f5557 166\r
167**/\r
168EFI_STATUS\r
169EFIAPI\r
170SecurityStubInitialize (\r
171 IN EFI_HANDLE ImageHandle,\r
172 IN EFI_SYSTEM_TABLE *SystemTable\r
173 )\r
174{\r
175 EFI_STATUS Status;\r
176\r
177 //\r
178 // Make sure the Security Architectural Protocol is not already installed in the system\r
179 //\r
bc2dfdbc 180 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiSecurity2ArchProtocolGuid);\r
ce2f5557 181 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiSecurityArchProtocolGuid);\r
182\r
183 //\r
184 // Install the Security Architectural Protocol onto a new handle\r
185 //\r
186 Status = gBS->InstallMultipleProtocolInterfaces (\r
187 &mSecurityArchProtocolHandle,\r
bc2dfdbc
LG
188 &gEfiSecurity2ArchProtocolGuid,\r
189 &mSecurity2Stub,\r
ce2f5557 190 &gEfiSecurityArchProtocolGuid,\r
191 &mSecurityStub,\r
192 NULL\r
193 );\r
194 ASSERT_EFI_ERROR (Status);\r
195\r
5d69642d 196 return EFI_SUCCESS;\r
ce2f5557 197}\r