File: shim_protocol.c

package info (click to toggle)
efitools 1.9.2-3.5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 940 kB
  • sloc: ansic: 7,547; makefile: 131; perl: 119; sh: 35
file content (54 lines) | stat: -rw-r--r-- 1,194 bytes parent folder | download
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
#include <efi.h>
#include <efilib.h>

#include <guid.h>
#include <pecoff.h>
#include <sha256.h>
#include <efiauthenticated.h>
#include <pkcs7verify.h>
#include <variables.h>
#include <shim_protocol.h>
#include <console.h>

static EFI_STATUS shimprotocol_context(void *data, unsigned int size,
				       PE_COFF_LOADER_IMAGE_CONTEXT *context)
{
	return pecoff_read_header(context, data, size);
}

static EFI_STATUS shimprotocol_verify(void *buffer, UINT32 size)
{
	EFI_STATUS status;

	if (!variable_is_secureboot() || variable_is_setupmode())
		return EFI_SUCCESS;

	if (pkcs7verify_deny(buffer, size))
		return EFI_ACCESS_DENIED;

	if (pkcs7verify_allow(buffer, size))
		return EFI_SUCCESS;

	return EFI_ACCESS_DENIED;


	return status;
}

static SHIM_LOCK shim_protocol_interface = {
	.Verify = shimprotocol_verify,
	.Context = shimprotocol_context,
};
static EFI_HANDLE shim_protocol_handle;

EFI_STATUS
shim_protocol_install(void)
{
	return BS->InstallProtocolInterface(&shim_protocol_handle, &MOK_OWNER, EFI_NATIVE_INTERFACE, &shim_protocol_interface);
}

void
shim_protocol_uninstall(void)
{
	BS->UninstallProtocolInterface(shim_protocol_handle, &MOK_OWNER, &shim_protocol_interface);
}