]> git.proxmox.com Git - mirror_edk2.git/blame - EdkModulePkg/Core/Pei/Security/Security.c
1. Rename PeiCoreLib to PeiServicesLib and rename all the interfaces from PeiCoreXXX...
[mirror_edk2.git] / EdkModulePkg / Core / Pei / Security / Security.c
CommitLineData
878ddf1f 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 Security.c\r
15\r
16Abstract:\r
17\r
18 EFI PEI Core Security services\r
19\r
20--*/\r
21\r
22#include <PeiMain.h>\r
23\r
24EFI_STATUS\r
25EFIAPI\r
26SecurityPpiNotifyCallback (\r
27 IN EFI_PEI_SERVICES **PeiServices,\r
28 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r
29 IN VOID *Ppi\r
30 );\r
31\r
32static EFI_PEI_NOTIFY_DESCRIPTOR mNotifyList = {\r
33 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,\r
34 &gEfiPeiSecurityPpiGuid,\r
35 SecurityPpiNotifyCallback\r
36};\r
37\r
38VOID\r
39InitializeSecurityServices (\r
40 IN EFI_PEI_SERVICES **PeiServices,\r
41 IN PEI_CORE_INSTANCE *OldCoreData\r
42 )\r
43/*++\r
44\r
45Routine Description:\r
46\r
47 Initialize the security services.\r
48\r
49Arguments:\r
50\r
51 PeiServices - The PEI core services table.\r
52 OldCoreData - Pointer to the old core data.\r
53 NULL if being run in non-permament memory mode.\r
54Returns:\r
55\r
56 None\r
57\r
58--*/\r
59{\r
60 if (OldCoreData == NULL) {\r
84a99d48 61 PeiServicesNotifyPpi (&mNotifyList);\r
878ddf1f 62 }\r
63 return;\r
64}\r
65\r
66EFI_STATUS\r
67EFIAPI\r
68SecurityPpiNotifyCallback (\r
69 IN EFI_PEI_SERVICES **PeiServices,\r
70 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r
71 IN VOID *Ppi\r
72 )\r
73/*++\r
74\r
75Routine Description:\r
76\r
77 Provide a callback for when the security PPI is installed.\r
78\r
79Arguments:\r
80\r
81 PeiServices - The PEI core services table.\r
82 NotifyDescriptor - The descriptor for the notification event.\r
83 Ppi - Pointer to the PPI in question.\r
84\r
85Returns:\r
86\r
87 EFI_SUCCESS - The function is successfully processed.\r
88\r
89--*/\r
90{\r
91 PEI_CORE_INSTANCE *PrivateData;\r
92\r
93 //\r
94 // Get PEI Core private data\r
95 //\r
96 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
97 \r
98 //\r
99 // If there isn't a security PPI installed, use the one from notification\r
100 //\r
101 if (PrivateData->PrivateSecurityPpi == NULL) {\r
102 PrivateData->PrivateSecurityPpi = (EFI_PEI_SECURITY_PPI *)Ppi;\r
103 }\r
104 return EFI_SUCCESS;\r
105}\r
106\r
107EFI_STATUS\r
108VerifyPeim (\r
109 IN EFI_PEI_SERVICES **PeiServices,\r
110 IN EFI_FFS_FILE_HEADER *CurrentPeimAddress\r
111 )\r
112/*++\r
113\r
114Routine Description:\r
115\r
116 Provide a callout to the security verification service.\r
117\r
118Arguments:\r
119\r
120 PeiServices - The PEI core services table.\r
121 CurrentPeimAddress - Pointer to the Firmware File under investigation.\r
122\r
123Returns:\r
124\r
125 EFI_SUCCESS - Image is OK\r
126 EFI_SECURITY_VIOLATION - Image is illegal\r
127\r
128--*/\r
129{\r
130 PEI_CORE_INSTANCE *PrivateData;\r
131 EFI_STATUS Status;\r
132 UINT32 AuthenticationStatus;\r
133 BOOLEAN StartCrisisRecovery;\r
134\r
135 //\r
136 // Set a default authentication state\r
137 //\r
138 AuthenticationStatus = 0;\r
139\r
140 //\r
141 // get security PPI instance from PEI private data\r
142 //\r
143 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
144\r
145 if (PrivateData->PrivateSecurityPpi == NULL) {\r
146 Status = EFI_NOT_FOUND;\r
147 } else {\r
148 //\r
149 // Check to see if the image is OK\r
150 //\r
151 Status = PrivateData->PrivateSecurityPpi->AuthenticationState (\r
152 PeiServices,\r
153 PrivateData->PrivateSecurityPpi,\r
154 AuthenticationStatus,\r
155 CurrentPeimAddress,\r
156 &StartCrisisRecovery\r
157 );\r
158 if (StartCrisisRecovery) {\r
159 Status = EFI_SECURITY_VIOLATION;\r
160 }\r
161 }\r
162 return Status;\r
163}\r
164\r
165\r
166EFI_STATUS\r
167VerifyFv (\r
168 IN EFI_FIRMWARE_VOLUME_HEADER *CurrentFvAddress\r
169 )\r
170/*++\r
171\r
172Routine Description:\r
173\r
174 Verify a Firmware volume\r
175\r
176Arguments:\r
177\r
178 CurrentFvAddress - Pointer to the current Firmware Volume under consideration\r
179\r
180Returns:\r
181\r
182 EFI_SUCCESS - Firmware Volume is legal\r
183 EFI_SECURITY_VIOLATION - Firmware Volume fails integrity test\r
184\r
185--*/\r
186{\r
187 //\r
188 // Right now just pass the test. Future can authenticate and/or check the\r
189 // FV-header or other metric for goodness of binary.\r
190 //\r
191 return EFI_SUCCESS;\r
192}\r