18#define SECURITY_HANDLER_TABLE_SIZE 0x10
23#define EFI_AUTH_IMAGE_OPERATION_MASK (EFI_AUTH_OPERATION_VERIFY_IMAGE \
24 | EFI_AUTH_OPERATION_DEFER_IMAGE_LOAD \
25 | EFI_AUTH_OPERATION_MEASURE_IMAGE)
26#define EFI_AUTH_NONE_IMAGE_OPERATION_MASK (EFI_AUTH_OPERATION_CONNECT_POLICY \
27 | EFI_AUTH_OPERATION_AUTHENTICATION_STATE)
30 UINT32 SecurityOperation;
35 UINT32 Security2Operation;
39UINT32 mCurrentAuthOperation = 0;
40UINT32 mNumberOfSecurityHandler = 0;
41UINT32 mMaxNumberOfSecurityHandler = 0;
44UINT32 mCurrentAuthOperation2 = 0;
45UINT32 mNumberOfSecurity2Handler = 0;
46UINT32 mMaxNumberOfSecurity2Handler = 0;
66 (mMaxNumberOfSecurityHandler + SECURITY_HANDLER_TABLE_SIZE) *
sizeof (
SECURITY_INFO),
73 if (mSecurityTable ==
NULL) {
80 mMaxNumberOfSecurityHandler = mMaxNumberOfSecurityHandler + SECURITY_HANDLER_TABLE_SIZE;
96 IN UINT32 CurrentAuthOperation,
97 IN UINT32 CheckAuthOperation
109 if ((CurrentAuthOperation & EFI_AUTH_OPERATION_MEASURE_IMAGE) == EFI_AUTH_OPERATION_MEASURE_IMAGE) {
110 if (((CheckAuthOperation & EFI_AUTH_OPERATION_MEASURE_IMAGE) == EFI_AUTH_OPERATION_MEASURE_IMAGE) ||
111 ((CheckAuthOperation & EFI_AUTH_IMAGE_OPERATION_MASK) == EFI_AUTH_OPERATION_NONE))
144 IN UINT32 AuthenticationOperation
149 ASSERT (SecurityHandler !=
NULL);
155 mCurrentAuthOperation = mCurrentAuthOperation | AuthenticationOperation;
160 if (mNumberOfSecurityHandler == mMaxNumberOfSecurityHandler) {
171 mSecurityTable[mNumberOfSecurityHandler].SecurityOperation = AuthenticationOperation;
172 mSecurityTable[mNumberOfSecurityHandler].SecurityHandler = SecurityHandler;
173 mNumberOfSecurityHandler++;
212 IN UINT32 AuthenticationStatus,
218 UINT32 HandlerAuthenticationStatus;
225 if (FilePath ==
NULL) {
226 return EFI_INVALID_PARAMETER;
232 if (mNumberOfSecurityHandler == 0) {
239 HandlerAuthenticationStatus = AuthenticationStatus;
244 for (Index = 0; Index < mNumberOfSecurityHandler; Index++) {
249 if (FileBuffer ==
NULL) {
250 Node = FilePathToVerfiy;
251 Status =
gBS->LocateDevicePath (&gEfiLoadFileProtocolGuid, &Node, &Handle);
256 if (FileBuffer ==
NULL) {
263 if ((FileBuffer !=
NULL) && (!EFI_ERROR (Status))) {
272 Status = mSecurityTable[Index].SecurityHandler (
273 HandlerAuthenticationStatus,
278 if (EFI_ERROR (Status)) {
283 if (FileBuffer !=
NULL) {
287 if (FilePathToVerfiy != FilePath) {
311 (mMaxNumberOfSecurity2Handler + SECURITY_HANDLER_TABLE_SIZE) *
sizeof (
SECURITY2_INFO),
318 if (mSecurity2Table ==
NULL) {
325 mMaxNumberOfSecurity2Handler = mMaxNumberOfSecurity2Handler + SECURITY_HANDLER_TABLE_SIZE;
346 IN UINT32 CurrentAuthOperation,
347 IN UINT32 CheckAuthOperation
353 if (CheckAuthOperation == EFI_AUTH_OPERATION_NONE) {
357 if ((CheckAuthOperation & ~(EFI_AUTH_IMAGE_OPERATION_MASK |
358 EFI_AUTH_NONE_IMAGE_OPERATION_MASK |
368 if ((CurrentAuthOperation & EFI_AUTH_OPERATION_MEASURE_IMAGE) == EFI_AUTH_OPERATION_MEASURE_IMAGE) {
369 if (((CheckAuthOperation & EFI_AUTH_OPERATION_MEASURE_IMAGE) == EFI_AUTH_OPERATION_MEASURE_IMAGE) ||
370 ((CheckAuthOperation & EFI_AUTH_IMAGE_OPERATION_MASK) == 0))
403 IN UINT32 AuthenticationOperation
408 ASSERT (Security2Handler !=
NULL);
414 mCurrentAuthOperation2 = mCurrentAuthOperation2 | AuthenticationOperation;
419 if (mNumberOfSecurity2Handler == mMaxNumberOfSecurity2Handler) {
430 mSecurity2Table[mNumberOfSecurity2Handler].Security2Operation = AuthenticationOperation;
431 mSecurity2Table[mNumberOfSecurity2Handler].Security2Handler = Security2Handler;
432 mNumberOfSecurity2Handler++;
481 IN UINT32 AuthenticationOperation,
482 IN UINT32 AuthenticationStatus,
486 IN BOOLEAN BootPolicy
495 if ((File ==
NULL) && (FileBuffer ==
NULL)) {
496 return EFI_INVALID_PARAMETER;
502 if (mNumberOfSecurity2Handler == 0) {
509 for (Index = 0; Index < mNumberOfSecurity2Handler; Index++) {
515 if (((FileBuffer !=
NULL) && ((mSecurity2Table[Index].Security2Operation & EFI_AUTH_IMAGE_OPERATION_MASK) != 0)) ||
516 ((FileBuffer ==
NULL) && ((mSecurity2Table[Index].Security2Operation & EFI_AUTH_NONE_IMAGE_OPERATION_MASK) != 0)))
521 if ((mSecurity2Table[Index].Security2Operation & AuthenticationOperation) != 0) {
522 Status = mSecurity2Table[Index].Security2Handler (
523 AuthenticationStatus,
529 if (EFI_ERROR (Status)) {
EFI_DEVICE_PATH_PROTOCOL *EFIAPI DevicePathFromHandle(IN EFI_HANDLE Handle)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI AppendDevicePath(IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath OPTIONAL, IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL)
EFI_STATUS EFIAPI ExecuteSecurity2Handlers(IN UINT32 AuthenticationOperation, IN UINT32 AuthenticationStatus, IN CONST EFI_DEVICE_PATH_PROTOCOL *File OPTIONAL, IN VOID *FileBuffer, IN UINTN FileSize, IN BOOLEAN BootPolicy)
RETURN_STATUS EFIAPI ReallocateSecurity2HandlerTable(VOID)
RETURN_STATUS EFIAPI ReallocateSecurityHandlerTable(VOID)
EFI_STATUS EFIAPI RegisterSecurityHandler(IN SECURITY_FILE_AUTHENTICATION_STATE_HANDLER SecurityHandler, IN UINT32 AuthenticationOperation)
BOOLEAN CheckAuthentication2Operation(IN UINT32 CurrentAuthOperation, IN UINT32 CheckAuthOperation)
BOOLEAN CheckAuthenticationOperation(IN UINT32 CurrentAuthOperation, IN UINT32 CheckAuthOperation)
EFI_STATUS EFIAPI RegisterSecurity2Handler(IN SECURITY2_FILE_AUTHENTICATION_HANDLER Security2Handler, IN UINT32 AuthenticationOperation)
EFI_STATUS EFIAPI ExecuteSecurityHandlers(IN UINT32 AuthenticationStatus, IN CONST EFI_DEVICE_PATH_PROTOCOL *FilePath)
VOID *EFIAPI GetFileBufferByFilePath(IN BOOLEAN BootPolicy, IN CONST EFI_DEVICE_PATH_PROTOCOL *FilePath, OUT UINTN *FileSize, OUT UINT32 *AuthenticationStatus)
VOID *EFIAPI ReallocatePool(IN UINTN OldSize, IN UINTN NewSize, IN VOID *OldBuffer OPTIONAL)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define RETURN_OUT_OF_RESOURCES
#define ASSERT_EFI_ERROR(StatusParameter)
#define EFI_AUTH_OPERATION_IMAGE_REQUIRED
EFI_STATUS(EFIAPI * SECURITY2_FILE_AUTHENTICATION_HANDLER)(IN UINT32 AuthenticationStatus, IN CONST EFI_DEVICE_PATH_PROTOCOL *File, IN VOID *FileBuffer, IN UINTN FileSize, IN BOOLEAN BootPolicy)
EFI_STATUS(EFIAPI * SECURITY_FILE_AUTHENTICATION_STATE_HANDLER)(IN OUT UINT32 AuthenticationStatus, IN CONST EFI_DEVICE_PATH_PROTOCOL *File, IN VOID *FileBuffer, IN UINTN FileSize)