summaryrefslogtreecommitdiff
path: root/EDK/Foundation/Core/Pei/Security/Security.c
blob: 928e21a1d4399e3866d31bef5e35f7c986250af4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*++

Copyright (c) 2004 - 2005, Intel Corporation                                                         
All rights reserved. This program and the accompanying materials                          
are licensed and made available under the terms and conditions of the BSD License         
which accompanies this distribution.  The full text of the license may be found at        
http://opensource.org/licenses/bsd-license.php                                            
                                                                                          
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             

Module Name:

  Security.c

Abstract:

  EFI PEI Core Security services

--*/

#include "Tiano.h"
#include "PeiCore.h"
#include EFI_PPI_DEFINITION (Security)

EFI_STATUS
EFIAPI
SecurityPpiNotifyCallback (
  IN EFI_PEI_SERVICES           **PeiServices,
  IN EFI_PEI_NOTIFY_DESCRIPTOR  *NotifyDescriptor,
  IN VOID                       *Ppi
  );

static EFI_PEI_NOTIFY_DESCRIPTOR mNotifyList = {
   EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
   &gPeiSecurityPpiGuid,
   SecurityPpiNotifyCallback
};

VOID
InitializeSecurityServices (
  IN EFI_PEI_SERVICES  **PeiServices,
  IN PEI_CORE_INSTANCE *OldCoreData
  )
/*++

Routine Description:

  Initialize the security services.

Arguments:

  PeiServices - The PEI core services table.
  OldCoreData - Pointer to the old core data.
                NULL if being run in non-permament memory mode.
Returns:

  None

--*/
{
  if (OldCoreData == NULL) {
    PeiNotifyPpi (PeiServices, &mNotifyList);
  }
  return;
}

EFI_STATUS
EFIAPI
SecurityPpiNotifyCallback (
  IN EFI_PEI_SERVICES           **PeiServices,
  IN EFI_PEI_NOTIFY_DESCRIPTOR  *NotifyDescriptor,
  IN VOID                       *Ppi
  )
/*++

Routine Description:

  Provide a callback for when the security PPI is installed.

Arguments:

  PeiServices       - The PEI core services table.
  NotifyDescriptor  - The descriptor for the notification event.
  Ppi               - Pointer to the PPI in question.

Returns:

  EFI_SUCCESS - The function is successfully processed.

--*/
{
  PEI_CORE_INSTANCE                       *PrivateData;

  //
  // Get PEI Core private data
  //
  PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
  
  //
  // If there isn't a security PPI installed, use the one from notification
  //
  if (PrivateData->PrivateSecurityPpi == NULL) {
    PrivateData->PrivateSecurityPpi = (PEI_SECURITY_PPI *)Ppi;
  }
  return EFI_SUCCESS;
}

EFI_STATUS
VerifyPeim (
  IN EFI_PEI_SERVICES     **PeiServices,
  IN EFI_FFS_FILE_HEADER  *CurrentPeimAddress
  )
/*++

Routine Description:

  Provide a callout to the security verification service.

Arguments:

  PeiServices          - The PEI core services table.
  CurrentPeimAddress   - Pointer to the Firmware File under investigation.

Returns:

  EFI_SUCCESS             - Image is OK
  EFI_SECURITY_VIOLATION  - Image is illegal

--*/
{
  PEI_CORE_INSTANCE               *PrivateData;
  EFI_STATUS                      Status;
  UINT32                          AuthenticationStatus;
  BOOLEAN                         StartCrisisRecovery;

  //
  // Set a default authentication state
  //
  AuthenticationStatus = 0;

  //
  // get security PPI instance from PEI private data
  //
  PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);

  if (PrivateData->PrivateSecurityPpi == NULL) {
    Status = EFI_NOT_FOUND;
  } else {
    //
    // Check to see if the image is OK
    //
    Status = PrivateData->PrivateSecurityPpi->AuthenticationState (
                                                PeiServices,
                                                PrivateData->PrivateSecurityPpi,
                                                AuthenticationStatus,
                                                CurrentPeimAddress,
                                                &StartCrisisRecovery
                                                );
    if (StartCrisisRecovery) {
      Status = EFI_SECURITY_VIOLATION;
    }
  }
  return Status;
}


EFI_STATUS
VerifyFv (
  IN EFI_FIRMWARE_VOLUME_HEADER  *CurrentFvAddress
  )
/*++

Routine Description:

  Verify a Firmware volume

Arguments:

  CurrentFvAddress - Pointer to the current Firmware Volume under consideration

Returns:

  EFI_SUCCESS             - Firmware Volume is legal
  EFI_SECURITY_VIOLATION  - Firmware Volume fails integrity test

--*/
{
  //
  // Right now just pass the test.  Future can authenticate and/or check the
  // FV-header or other metric for goodness of binary.
  //
  return EFI_SUCCESS;
}