aboutsummaryrefslogtreecommitdiffstats
path: root/src/libpts/plugins/imv_attestation/imv_attestation_state.h
blob: f64314e71d12dc18900ef0410134bef296ed73f4 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
 * Copyright (C) 2011-2012 Sansar Choinyambuu, Andreas Steffen
 * HSR Hochschule fuer Technik Rapperswil
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */

/**
 *
 * @defgroup imv_attestation_state_t imv_attestation_state
 * @{ @ingroup imv_attestation_state
 */

#ifndef IMV_ATTESTATION_STATE_H_
#define IMV_ATTESTATION_STATE_H_

#include <imv/imv_state.h>
#include <pts/pts.h>
#include <pts/pts_database.h>
#include <pts/components/pts_component.h>
#include <library.h>

typedef struct imv_attestation_state_t imv_attestation_state_t;
typedef enum imv_attestation_handshake_state_t imv_attestation_handshake_state_t;
typedef enum imv_meas_error_t imv_meas_error_t;

/**
 * IMV Attestation Handshake States (state machine)
 */
enum imv_attestation_handshake_state_t {
	IMV_ATTESTATION_STATE_INIT,
	IMV_ATTESTATION_STATE_NONCE_REQ,
	IMV_ATTESTATION_STATE_TPM_INIT,
	IMV_ATTESTATION_STATE_MEAS,
	IMV_ATTESTATION_STATE_COMP_EVID,
	IMV_ATTESTATION_STATE_EVID_FINAL,
	IMV_ATTESTATION_STATE_END,
};

/**
 * IMV Measurement Error Types
 */
enum imv_meas_error_t {
	IMV_ATTESTATION_ERROR_FILE_MEAS_FAIL =  1,
	IMV_ATTESTATION_ERROR_FILE_MEAS_PEND =  2,
	IMV_ATTESTATION_ERROR_COMP_EVID_FAIL =  4,
	IMV_ATTESTATION_ERROR_COMP_EVID_PEND =  8,
	IMV_ATTESTATION_ERROR_TPM_QUOTE_FAIL = 16
};

/**
 * Internal state of an imv_attestation_t connection instance
 */
struct imv_attestation_state_t {

	/**
	 * imv_state_t interface
	 */
	imv_state_t interface;

	/**
	 * Get state of the handshake
	 *
	 * @return					the handshake state of IMV
	 */
	imv_attestation_handshake_state_t (*get_handshake_state)(
		imv_attestation_state_t *this);
	
	/**
	 * Set state of the handshake
	 *
	 * @param new_state			the handshake state of IMV
	 */
	void (*set_handshake_state)(imv_attestation_state_t *this,
								imv_attestation_handshake_state_t new_state);

	/**
	 * Get the PTS object
	 *
	 * @return					PTS object
	 */
	pts_t* (*get_pts)(imv_attestation_state_t *this);

	/**
	 * Add an entry to the list of pending file/directory measurement requests
	 *
	 * @param file_id			primary key into file table
	 * @param is_dir			TRUE if directory
	 * @return					unique request ID
	 */
	u_int16_t (*add_file_meas_request)(imv_attestation_state_t *this,
									   int file_id, bool is_dir);

	/**
	 * Returns the number of pending file/directory measurement requests
	 *
	 * @return					number of pending requests
	 */
	int (*get_file_meas_request_count)(imv_attestation_state_t *this);

	/**
	 * Check for presence of request_id and if found remove it from the list
	 *
	 * @param id				unique request ID
	 * @param file_id			primary key into file table
	 * @param is_dir			return TRUE if request was for a directory
	 * @return					TRUE if request ID found, FALSE otherwise
	 */
	bool (*check_off_file_meas_request)(imv_attestation_state_t *this,
										u_int16_t id, int *file_id, bool *is_dir);

	/**
	 * Create and add an entry to the list of Functional Components
	 *
	 * @param name				Component Functional Name
	 * @param depth				Sub-component Depth
	 * @param pts_db			PTS measurement database
	 * @return					created functional component instance or NULL
	 */
	pts_component_t* (*create_component)(imv_attestation_state_t *this,
										 pts_comp_func_name_t *name,
										 u_int32_t depth,
										 pts_database_t *pts_db);

	/**
	 * Get a Functional Component with a given name
	 *
	 * @param name			 	Name of the requested Functional Component
	 * @return					Functional Component if found, NULL otherwise
	 */
	pts_component_t* (*get_component)(imv_attestation_state_t *this,
									  pts_comp_func_name_t *name);

	/**
	 * Tell the Functional Components to finalize any measurement registrations
	 * and to check if all expected measurements were received
	 */
	void (*finalize_components)(imv_attestation_state_t *this);

	/**
	 * Have the Functional Component measurements been finalized?
	 */
	bool (*components_finalized)(imv_attestation_state_t *this);

	/**
	 * Indicates the types of measurement errors that occurred
	 *
	 * @return					Measurement error flags
	 */
	u_int32_t (*get_measurement_error)(imv_attestation_state_t *this);

	/**
	 * Call if a measurement error is encountered
	 *
	 * @param error				Measurement error type
	 */
	void (*set_measurement_error)(imv_attestation_state_t *this,
								  u_int32_t error);

};

/**
 * Create an imv_attestation_state_t instance
 *
 * @param id					connection ID
 */
imv_state_t* imv_attestation_state_create(TNC_ConnectionID id);

#endif /** IMV_ATTESTATION_STATE_H_ @}*/