/** Execute registered handlers until one returns an error and that error is returned. If none of the handlers return an error, then EFI_SUCCESS is returned. Before exectue handler, get the image buffer by file device path if a handler requires the image file. And return the image buffer to each handler when exectue handler. The handlers are executed in same order to their registered order. @param[in] AuthenticationStatus This is the authentication type returned from the Section Extraction protocol. See the Section Extraction Protocol Specification for details on this type. @param[in] FilePath This is a pointer to the device path of the file that is being dispatched. This will optionally be used for logging. @retval EFI_SUCCESS The file specified by File did authenticate when more than one security handler services were registered, or the file did not authenticate when no security handler service was registered. And the platform policy dictates that the DXE Core may use File. @retval EFI_INVALID_PARAMETER File is NULL. @retval EFI_SECURITY_VIOLATION The file specified by File did not authenticate, and the platform policy dictates that File should be placed in the untrusted state. A file may be promoted from the untrusted to the trusted state at a future time with a call to the Trust() DXE Service. @retval EFI_ACCESS_DENIED The file specified by File did not authenticate, and the platform policy dictates that File should not be used for any purpose. **/ EFI_STATUS EFIAPI ExecuteSecurityHandlers ( IN UINT32 AuthenticationStatus, IN CONST EFI_DEVICE_PATH_PROTOCOL *FilePath ) { UINT32 Index; EFI_STATUS Status; UINT32 HandlerAuthenticationStatus; VOID *FileBuffer; UINTN FileSize; if (FilePath == NULL) { return EFI_INVALID_PARAMETER; } // // Directly return successfully when no handler is registered. // if (mNumberOfSecurityHandler == 0) { return EFI_SUCCESS; } Status = EFI_SUCCESS; FileBuffer = NULL; FileSize = 0; HandlerAuthenticationStatus = AuthenticationStatus; // // Run security handler in same order to their registered list // for (Index = 0; Index < mNumberOfSecurityHandler; Index ++) { if ((mSecurityTable[Index].SecurityOperation & EFI_AUTH_OPERATION_IMAGE_REQUIRED) == EFI_AUTH_OPERATION_IMAGE_REQUIRED) { // // Try get file buffer when the handler requires image buffer. // if (FileBuffer == NULL) { // // Try to get image by FALSE boot policy for the exact boot file path. // FileBuffer = GetFileBufferByFilePath (FALSE, FilePath, &FileSize, &AuthenticationStatus); if (FileBuffer == NULL) { // // Try to get image by TRUE boot policy for the inexact boot file path. // FileBuffer = GetFileBufferByFilePath (TRUE, FilePath, &FileSize, &AuthenticationStatus); } } } Status = mSecurityTable[Index].SecurityHandler ( HandlerAuthenticationStatus, FilePath, FileBuffer, FileSize ); if (EFI_ERROR (Status)) { break; } } if (FileBuffer != NULL) { FreePool (FileBuffer); } return Status; }
/** Execute registered handlers until one returns an error and that error is returned. If none of the handlers return an error, then EFI_SUCCESS is returned. Before exectue handler, get the image buffer by file device path if a handler requires the image file. And return the image buffer to each handler when exectue handler. The handlers are executed in same order to their registered order. @param[in] AuthenticationStatus This is the authentication type returned from the Section Extraction protocol. See the Section Extraction Protocol Specification for details on this type. @param[in] FilePath This is a pointer to the device path of the file that is being dispatched. This will optionally be used for logging. @retval EFI_SUCCESS The file specified by File did authenticate when more than one security handler services were registered, or the file did not authenticate when no security handler service was registered. And the platform policy dictates that the DXE Core may use File. @retval EFI_INVALID_PARAMETER File is NULL. @retval EFI_SECURITY_VIOLATION The file specified by File did not authenticate, and the platform policy dictates that File should be placed in the untrusted state. A file may be promoted from the untrusted to the trusted state at a future time with a call to the Trust() DXE Service. @retval EFI_ACCESS_DENIED The file specified by File did not authenticate, and the platform policy dictates that File should not be used for any purpose. **/ EFI_STATUS EFIAPI ExecuteSecurityHandlers ( IN UINT32 AuthenticationStatus, IN CONST EFI_DEVICE_PATH_PROTOCOL *FilePath ) { UINT32 Index; EFI_STATUS Status; UINT32 HandlerAuthenticationStatus; VOID *FileBuffer; UINTN FileSize; EFI_HANDLE Handle; EFI_DEVICE_PATH_PROTOCOL *Node; EFI_DEVICE_PATH_PROTOCOL *FilePathToVerfiy; if (FilePath == NULL) { return EFI_INVALID_PARAMETER; } // // Directly return successfully when no handler is registered. // if (mNumberOfSecurityHandler == 0) { return EFI_SUCCESS; } Status = EFI_SUCCESS; FileBuffer = NULL; FileSize = 0; HandlerAuthenticationStatus = AuthenticationStatus; FilePathToVerfiy = (EFI_DEVICE_PATH_PROTOCOL *) FilePath; // // Run security handler in same order to their registered list // for (Index = 0; Index < mNumberOfSecurityHandler; Index ++) { if ((mSecurityTable[Index].SecurityOperation & EFI_AUTH_OPERATION_IMAGE_REQUIRED) == EFI_AUTH_OPERATION_IMAGE_REQUIRED) { // // Try get file buffer when the handler requires image buffer. // if (FileBuffer == NULL) { Node = FilePathToVerfiy; Status = gBS->LocateDevicePath (&gEfiLoadFileProtocolGuid, &Node, &Handle); // // Try to get image by FALSE boot policy for the exact boot file path. // FileBuffer = GetFileBufferByFilePath (FALSE, FilePath, &FileSize, &AuthenticationStatus); if (FileBuffer == NULL) { // // Try to get image by TRUE boot policy for the inexact boot file path. // FileBuffer = GetFileBufferByFilePath (TRUE, FilePath, &FileSize, &AuthenticationStatus); } if ((FileBuffer != NULL) && (!EFI_ERROR (Status))) { // // LoadFile () may cause the device path of the Handle be updated. // FilePathToVerfiy = AppendDevicePath (DevicePathFromHandle (Handle), Node); } } } Status = mSecurityTable[Index].SecurityHandler ( HandlerAuthenticationStatus, FilePathToVerfiy, FileBuffer, FileSize ); if (EFI_ERROR (Status)) { break; } } if (FileBuffer != NULL) { FreePool (FileBuffer); } if (FilePathToVerfiy != FilePath) { FreePool (FilePathToVerfiy); } return Status; }