summaryrefslogtreecommitdiff
path: root/futility/traversal.h
blob: 48bc3b6aeee16f2dbee4c616b0522ea6f4da94e7 (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
/*
 * Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */
#ifndef VBOOT_REFERENCE_FUTILITY_TRAVERSAL_H_
#define VBOOT_REFERENCE_FUTILITY_TRAVERSAL_H_
#include <stdint.h>


/* What type of things do I know how to handle? */
enum futil_file_type {
	FILE_TYPE_UNKNOWN = 0,
	FILE_TYPE_PUBKEY,			/* 1 VbPublicKey */
	FILE_TYPE_KEYBLOCK,			/* 2 VbKeyBlockHeader */
	FILE_TYPE_FIRMWARE,			/* 3 VbFirmwarePreambleHeader */
	FILE_TYPE_GBB,				/* 4 GoogleBinaryBlockHeader */
	FILE_TYPE_BIOS_IMAGE,			/* 5 Chrome OS BIOS image */
	FILE_TYPE_OLD_BIOS_IMAGE,		/* 6 Old Chrome OS BIOS image */

	NUM_FILE_TYPES
};

/* What are we trying to accomplish? */
enum futil_op_type {
	FUTIL_OP_SHOW,
	FUTIL_OP_SIGN,

	NUM_FUTIL_OPS
};

/* What component are we currently handling in the callback routine? */
enum futil_cb_component {
	/* entire input buffer */
	CB_BEGIN_TRAVERSAL,
	CB_END_TRAVERSAL,
	/* fmap areas within a bios image */
	CB_FMAP_GBB,
	CB_FMAP_VBLOCK_A,
	CB_FMAP_VBLOCK_B,
	CB_FMAP_FW_MAIN_A,
	CB_FMAP_FW_MAIN_B,
	/* individual files (extracted from a bios, for example) */
	CB_PUBKEY,
	CB_KEYBLOCK,
	CB_GBB,
	CB_FW_PREAMBLE,

	NUM_CB_COMPONENTS
};

/* Where is the component we're poking at? */
struct cb_area_s {
	uint32_t offset;			/* to avoid pointer math */
	uint8_t *buf;
	uint32_t len;
	uint32_t _flags;			/* for callback use */
};

/* What do we know at this point in time? */
struct futil_traverse_state_s {
	/* These two should be initialized by the caller */
	const char *in_filename;
	enum futil_op_type op;
	/* Current activity during traversal */
	enum futil_cb_component component;
	struct cb_area_s *my_area;
	const char *name;
	/* Other activites, possibly before or after the current one */
	struct cb_area_s cb_area[NUM_CB_COMPONENTS];
	struct cb_area_s recovery_key;
	struct cb_area_s rootkey;
	enum futil_file_type in_type;
	int errors;
};

/*
 * Traverse the input file using the provided state
 * Return nonzero (but no details) if there were any errors.
 */
int futil_traverse(int ifd, struct futil_traverse_state_s *state,
		   int writeable);

/* These are invoked by the traversal. They also return nonzero on error. */
int futil_cb_show_begin(struct futil_traverse_state_s *state);
int futil_cb_show_key(struct futil_traverse_state_s *state);
int futil_cb_show_gbb(struct futil_traverse_state_s *state);
int futil_cb_show_keyblock(struct futil_traverse_state_s *state);
int futil_cb_show_fw_main(struct futil_traverse_state_s *state);
int futil_cb_show_fw_preamble(struct futil_traverse_state_s *state);

int futil_cb_sign_bogus(struct futil_traverse_state_s *state);
int futil_cb_sign_notyet(struct futil_traverse_state_s *state);
int futil_cb_sign_fw_main(struct futil_traverse_state_s *state);
int futil_cb_sign_fw_preamble(struct futil_traverse_state_s *state);
int futil_cb_sign_begin(struct futil_traverse_state_s *state);
int futil_cb_sign_end(struct futil_traverse_state_s *state);


#endif /* VBOOT_REFERENCE_FUTILITY_TRAVERSAL_H_ */