TianoCore EDK2 master
Loading...
Searching...
No Matches
SpdmSecurityLib.c
Go to the documentation of this file.
1
11
19BOOLEAN
20EFIAPI
22 VOID
23 )
24{
25 EFI_STATUS Status;
26 UINT8 *DeviceAuthBootMode;
27
28 DeviceAuthBootMode = NULL;
29
30 Status = GetEfiGlobalVariable2 (EFI_DEVICE_AUTH_BOOT_MODE_NAME, (VOID **)&DeviceAuthBootMode, NULL);
31 //
32 // Skip verification if DeviceAuthBootMode variable doesn't exist.
33 //
34 if (EFI_ERROR (Status)) {
35 DEBUG ((DEBUG_ERROR, "Cannot check DeviceAuthBootMode variable %r \n ", Status));
36 return FALSE;
37 }
38
39 //
40 // Skip verification if DeviceAuthBootMode is disabled but not AuditMode
41 //
42 if (*DeviceAuthBootMode == DEVICE_AUTH_BOOT_MODE_DISABLE) {
43 FreePool (DeviceAuthBootMode);
44 return FALSE;
45 } else {
46 FreePool (DeviceAuthBootMode);
47 return TRUE;
48 }
49}
50
63EFIAPI
65 IN EDKII_SPDM_DEVICE_INFO *SpdmDeviceInfo,
66 IN EDKII_DEVICE_SECURITY_POLICY *SecurityPolicy,
67 OUT EDKII_DEVICE_SECURITY_STATE *SecurityState
68 )
69{
70 EFI_STATUS Status;
71 SPDM_DEVICE_CONTEXT *SpdmDeviceContext;
72 UINT8 AuthState;
73 UINT8 SlotId;
74 BOOLEAN IsValidCertChain;
75 BOOLEAN RootCertMatch;
76
77 if ((PcdGet32 (PcdTcgPfpMeasurementRevision) < TCG_EfiSpecIDEventStruct_SPEC_ERRATA_TPM2_REV_106) ||
78 (PcdGet8 (PcdEnableSpdmDeviceAuthentication) == 0))
79 {
80 return EFI_UNSUPPORTED;
81 }
82
83 SpdmDeviceContext = CreateSpdmDeviceContext (SpdmDeviceInfo, SecurityState);
84 if (SpdmDeviceContext == NULL) {
85 return EFI_UNSUPPORTED;
86 }
87
88 Status = EFI_SUCCESS;
89 AuthState = TCG_DEVICE_SECURITY_EVENT_DATA_DEVICE_AUTH_STATE_SUCCESS;
90 SlotId = 0;
91 IsValidCertChain = FALSE;
92 RootCertMatch = FALSE;
93
94 if (((SecurityPolicy->AuthenticationPolicy & EDKII_DEVICE_AUTHENTICATION_REQUIRED) != 0) ||
95 ((SecurityPolicy->MeasurementPolicy & EDKII_DEVICE_MEASUREMENT_REQUIRED) != 0))
96 {
97 Status = DoDeviceCertificate (SpdmDeviceContext, &AuthState, &SlotId, SecurityState, &IsValidCertChain, &RootCertMatch);
98 if (EFI_ERROR (Status)) {
99 DEBUG ((DEBUG_ERROR, "DoDeviceCertificate failed - %r\n", Status));
100 goto Ret;
101 } else if ((AuthState == TCG_DEVICE_SECURITY_EVENT_DATA_DEVICE_AUTH_STATE_FAIL_NO_SIG) ||
102 (AuthState == TCG_DEVICE_SECURITY_EVENT_DATA_DEVICE_AUTH_STATE_FAIL_INVALID))
103 {
104 goto Ret;
105 }
106 }
107
108 if (((SecurityPolicy->AuthenticationPolicy & EDKII_DEVICE_AUTHENTICATION_REQUIRED) != 0) && (IsDeviceAuthBootEnabled ())) {
109 Status = DoDeviceAuthentication (SpdmDeviceContext, &AuthState, SlotId, IsValidCertChain, RootCertMatch, SecurityState);
110 if (EFI_ERROR (Status)) {
111 DEBUG ((DEBUG_ERROR, "DoDeviceAuthentication failed - %r\n", Status));
112 goto Ret;
113 } else if ((AuthState == TCG_DEVICE_SECURITY_EVENT_DATA_DEVICE_AUTH_STATE_FAIL_NO_SIG) ||
114 (AuthState == TCG_DEVICE_SECURITY_EVENT_DATA_DEVICE_AUTH_STATE_FAIL_INVALID))
115 {
116 goto Ret;
117 }
118 }
119
120 if ((SecurityPolicy->MeasurementPolicy & EDKII_DEVICE_MEASUREMENT_REQUIRED) != 0) {
121 Status = DoDeviceMeasurement (SpdmDeviceContext, SlotId, SecurityState);
122 if (EFI_ERROR (Status)) {
123 DEBUG ((DEBUG_ERROR, "DoDeviceMeasurement failed - %r\n", Status));
124 }
125 }
126
127Ret:
128 DestroySpdmDeviceContext (SpdmDeviceContext);
129
130 return Status;
131}
132
141VOID *
142EFIAPI
144 IN VOID *SpdmContext
145 )
146{
147 return GetSpdmIoProtocolViaSpdmContext (SpdmContext);
148}
#define EDKII_DEVICE_MEASUREMENT_REQUIRED
VOID EFIAPI FreePool(IN VOID *Buffer)
#define EFI_DEVICE_AUTH_BOOT_MODE_NAME
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define PcdGet8(TokenName)
Definition: PcdLib.h:336
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
EFI_STATUS EFIAPI DoDeviceCertificate(IN SPDM_DEVICE_CONTEXT *SpdmDeviceContext, OUT UINT8 *AuthState, OUT UINT8 *ValidSlotId, OUT EDKII_DEVICE_SECURITY_STATE *SecurityState, OUT BOOLEAN *IsValidCertChain, OUT BOOLEAN *RootCertMatch)
EFI_STATUS EFIAPI DoDeviceAuthentication(IN SPDM_DEVICE_CONTEXT *SpdmDeviceContext, OUT UINT8 *AuthState, IN UINT8 ValidSlotId, IN BOOLEAN IsValidCertChain, IN BOOLEAN RootCertMatch, OUT EDKII_DEVICE_SECURITY_STATE *SecurityState)
VOID *EFIAPI GetSpdmIoProtocolViaSpdmContext(IN VOID *SpdmContext)
SPDM_DEVICE_CONTEXT *EFIAPI CreateSpdmDeviceContext(IN EDKII_SPDM_DEVICE_INFO *SpdmDeviceInfo, OUT EDKII_DEVICE_SECURITY_STATE *SecurityState)
VOID EFIAPI DestroySpdmDeviceContext(IN SPDM_DEVICE_CONTEXT *SpdmDeviceContext)
EFI_STATUS EFIAPI DoDeviceMeasurement(IN SPDM_DEVICE_CONTEXT *SpdmDeviceContext, IN UINT8 SlotId, OUT EDKII_DEVICE_SECURITY_STATE *SecurityState)
VOID *EFIAPI SpdmGetIoProtocolViaSpdmContext(IN VOID *SpdmContext)
EFI_STATUS EFIAPI SpdmDeviceAuthenticationAndMeasurement(IN EDKII_SPDM_DEVICE_INFO *SpdmDeviceInfo, IN EDKII_DEVICE_SECURITY_POLICY *SecurityPolicy, OUT EDKII_DEVICE_SECURITY_STATE *SecurityState)
BOOLEAN EFIAPI IsDeviceAuthBootEnabled(VOID)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_STATUS EFIAPI GetEfiGlobalVariable2(IN CONST CHAR16 *Name, OUT VOID **Value, OUT UINTN *Size OPTIONAL)
Definition: UefiLib.c:1470