]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Pei/Security/Security.c
1. Enable use-cases in PEI using SecurityPPI co-equal to the use-cases in DXE using...
[mirror_edk2.git] / MdeModulePkg / Core / Pei / Security / Security.c
CommitLineData
615c6dd0 1/** @file\r
b1f6a7c6 2 EFI PEI Core Security services\r
3 \r
c7935105 4Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
cd5ebaa0 5This program and the accompanying materials \r
192f6d4c 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
b1f6a7c6 13**/\r
192f6d4c 14\r
0d516397 15#include "PeiMain.h"\r
192f6d4c 16\r
192f6d4c 17\r
fe1e36e5 18EFI_PEI_NOTIFY_DESCRIPTOR mNotifyList = {\r
192f6d4c 19 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,\r
b0d803fe 20 &gEfiPeiSecurity2PpiGuid,\r
192f6d4c 21 SecurityPpiNotifyCallback\r
22};\r
23\r
b1f6a7c6 24/**\r
192f6d4c 25 Initialize the security services.\r
26\r
dc857d56 27 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
40f26b8f 28 @param OldCoreData Pointer to the old core data.\r
b1f6a7c6 29 NULL if being run in non-permament memory mode.\r
192f6d4c 30\r
b1f6a7c6 31**/\r
32VOID\r
33InitializeSecurityServices (\r
34 IN EFI_PEI_SERVICES **PeiServices,\r
35 IN PEI_CORE_INSTANCE *OldCoreData\r
36 )\r
192f6d4c 37{\r
38 if (OldCoreData == NULL) {\r
39 PeiServicesNotifyPpi (&mNotifyList);\r
40 }\r
41 return;\r
42}\r
43\r
b1f6a7c6 44/**\r
45\r
46 Provide a callback for when the security PPI is installed.\r
82b8c8df 47 This routine will cache installed security PPI into PeiCore's private data.\r
48 \r
dc857d56 49 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
50 @param NotifyDescriptor The descriptor for the notification event.\r
51 @param Ppi Pointer to the PPI in question.\r
b1f6a7c6 52\r
53 @return Always success\r
54\r
55**/\r
192f6d4c 56EFI_STATUS\r
57EFIAPI\r
58SecurityPpiNotifyCallback (\r
59 IN EFI_PEI_SERVICES **PeiServices,\r
60 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r
61 IN VOID *Ppi\r
62 )\r
192f6d4c 63{\r
64 PEI_CORE_INSTANCE *PrivateData;\r
65\r
66 //\r
67 // Get PEI Core private data\r
68 //\r
69 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
70 \r
71 //\r
72 // If there isn't a security PPI installed, use the one from notification\r
73 //\r
74 if (PrivateData->PrivateSecurityPpi == NULL) {\r
b0d803fe 75 PrivateData->PrivateSecurityPpi = (EFI_PEI_SECURITY2_PPI *)Ppi;\r
192f6d4c 76 }\r
77 return EFI_SUCCESS;\r
78}\r
79\r
b1f6a7c6 80/**\r
192f6d4c 81 Provide a callout to the security verification service.\r
82\r
b1f6a7c6 83 @param PrivateData PeiCore's private data structure\r
84 @param VolumeHandle Handle of FV\r
85 @param FileHandle Handle of PEIM's ffs\r
c7935105 86 @param AuthenticationStatus Authentication status\r
192f6d4c 87\r
b1f6a7c6 88 @retval EFI_SUCCESS Image is OK\r
89 @retval EFI_SECURITY_VIOLATION Image is illegal\r
82b8c8df 90 @retval EFI_NOT_FOUND If security PPI is not installed.\r
b1f6a7c6 91**/\r
92EFI_STATUS\r
93VerifyPeim (\r
94 IN PEI_CORE_INSTANCE *PrivateData,\r
95 IN EFI_PEI_FV_HANDLE VolumeHandle,\r
c7935105
SZ
96 IN EFI_PEI_FILE_HANDLE FileHandle,\r
97 IN UINT32 AuthenticationStatus\r
b1f6a7c6 98 )\r
192f6d4c 99{\r
192f6d4c 100 EFI_STATUS Status;\r
b0d803fe 101 BOOLEAN DeferExection;\r
192f6d4c 102\r
192f6d4c 103\r
192f6d4c 104 if (PrivateData->PrivateSecurityPpi == NULL) {\r
105 Status = EFI_NOT_FOUND;\r
106 } else {\r
107 //\r
108 // Check to see if the image is OK\r
109 //\r
110 Status = PrivateData->PrivateSecurityPpi->AuthenticationState (\r
4140a663 111 (CONST EFI_PEI_SERVICES **) &PrivateData->Ps,\r
192f6d4c 112 PrivateData->PrivateSecurityPpi,\r
113 AuthenticationStatus,\r
b0d803fe 114 VolumeHandle,\r
115 FileHandle,\r
116 &DeferExection\r
192f6d4c 117 );\r
b0d803fe 118 if (DeferExection) {\r
192f6d4c 119 Status = EFI_SECURITY_VIOLATION;\r
120 }\r
121 }\r
122 return Status;\r
123}\r
124\r
125\r
b1f6a7c6 126/**\r
127 Verify a Firmware volume.\r
128\r
82b8c8df 129 @param CurrentFvAddress Pointer to the current Firmware Volume under consideration\r
b1f6a7c6 130\r
82b8c8df 131 @retval EFI_SUCCESS Firmware Volume is legal\r
b1f6a7c6 132\r
133**/\r
192f6d4c 134EFI_STATUS\r
135VerifyFv (\r
136 IN EFI_FIRMWARE_VOLUME_HEADER *CurrentFvAddress\r
137 )\r
192f6d4c 138{\r
139 //\r
140 // Right now just pass the test. Future can authenticate and/or check the\r
141 // FV-header or other metric for goodness of binary.\r
142 //\r
143 return EFI_SUCCESS;\r
144}\r