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