summaryrefslogtreecommitdiff
path: root/src/libimcv/pts/components/pts_comp_evidence.c
blob: 08c3d5e9a316525b8215e22de81113453a178c8f (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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/*
 * Copyright (C) 2011 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.
 */

#include "pts/components/pts_comp_evidence.h"

#include <utils/debug.h>

typedef struct private_pts_comp_evidence_t private_pts_comp_evidence_t;

/**
 * Private data of a pts_comp_evidence_t object.
 */
struct private_pts_comp_evidence_t {

	/**
	 * Public pts_comp_evidence_t interface.
	 */
	pts_comp_evidence_t public;

	/**
	 * Component Functional Name
	 */
	pts_comp_func_name_t *name;

	/**
	 * Sub-Component Depth
	 */
	u_int32_t depth;

	/**
	 * Measurement Time
	 */
	time_t measurement_time;

	/**
	 * Measurement Time
	 */
	chunk_t measurement;

	/**
	 * Measurement Hash Algorithm
	 */
	pts_meas_algorithms_t hash_algorithm;

	/**
	 * Is PCR Information included?
	 */
	bool has_pcr_info;

	/**
	 * PCR the measurement was extended into
	 */
	u_int32_t extended_pcr;

	/**
	 * PCR value before extension
	 */
	chunk_t pcr_before;

	/**
	 * PCR value after extension
	 */
	chunk_t pcr_after;

	/**
	 * Transformation used for extending measurement into PCR
	 */
	pts_pcr_transform_t transform;

	/**
	 * Component Validation Result
	 */
	pts_comp_evid_validation_t validation;

	/**
	 * Verification Policy URI
	 */
	char *policy_uri;

};

METHOD(pts_comp_evidence_t, get_comp_func_name, pts_comp_func_name_t*,
	private_pts_comp_evidence_t *this, u_int32_t *depth)
{
	if (depth)
	{
		*depth = this->depth;
	}
	return this->name;
}

METHOD(pts_comp_evidence_t, get_extended_pcr, u_int32_t,
	private_pts_comp_evidence_t *this)
{
	return this->extended_pcr;
}

METHOD(pts_comp_evidence_t, get_measurement, chunk_t,
	private_pts_comp_evidence_t *this, u_int32_t *extended_pcr,
	pts_meas_algorithms_t *algo, pts_pcr_transform_t *transform,
	time_t *measurement_time)
{
	if (extended_pcr)
	{
		*extended_pcr = this->extended_pcr;
	}
	if (algo)
	{
		*algo = this->hash_algorithm;
	}
	if (transform)
	{
		*transform = this->transform;
	}
	if (measurement_time)
	{
		*measurement_time = this->measurement_time;
	}
	return this->measurement;
}

METHOD(pts_comp_evidence_t, get_pcr_info, bool,
	private_pts_comp_evidence_t *this, chunk_t *pcr_before, chunk_t *pcr_after)
{
	if (pcr_before)
	{
		*pcr_before = this->pcr_before;
	}
	if (pcr_after)
	{
		*pcr_after = this->pcr_after;
	}
	return this->has_pcr_info;
}

METHOD(pts_comp_evidence_t, set_pcr_info, void,
	private_pts_comp_evidence_t *this, chunk_t pcr_before, chunk_t pcr_after)
{
	this->has_pcr_info = TRUE;
	this->pcr_before = pcr_before;
	this->pcr_after =  pcr_after;

	DBG3(DBG_PTS, "PCR %2d before value : %#B", this->extended_pcr, &pcr_before);
	DBG3(DBG_PTS, "PCR %2d after value  : %#B", this->extended_pcr, &pcr_after);
}

METHOD(pts_comp_evidence_t, get_validation, pts_comp_evid_validation_t,
	private_pts_comp_evidence_t *this, char **uri)
{
	if (uri)
	{
		*uri = this->policy_uri;
	}
	return this->validation;
}

METHOD(pts_comp_evidence_t, set_validation, void,
	private_pts_comp_evidence_t *this, pts_comp_evid_validation_t validation,
	char *uri)
{
	this->validation = validation;
	if (uri)
	{
		this->policy_uri = strdup(uri);
		DBG3(DBG_PTS, "'%s'", uri);
	}
}

METHOD(pts_comp_evidence_t, destroy, void,
	private_pts_comp_evidence_t *this)
{
	this->name->destroy(this->name);
	free(this->measurement.ptr);
	free(this->pcr_before.ptr);
	free(this->pcr_after.ptr);
	free(this->policy_uri);
	free(this);
}

/**
 * See header
 */
pts_comp_evidence_t *pts_comp_evidence_create(pts_comp_func_name_t *name,
											  u_int32_t depth,
											  u_int32_t extended_pcr,
											  pts_meas_algorithms_t algo,
											  pts_pcr_transform_t transform,
											  time_t measurement_time,
											  chunk_t measurement)
{
	private_pts_comp_evidence_t *this;

	INIT(this,
		.public = {
			.get_comp_func_name = _get_comp_func_name,
			.get_extended_pcr = _get_extended_pcr,
			.get_measurement = _get_measurement,
			.get_pcr_info = _get_pcr_info,
			.set_pcr_info = _set_pcr_info,
			.get_validation = _get_validation,
			.set_validation = _set_validation,
			.destroy = _destroy,
		},
		.name = name,
		.depth = depth,
		.extended_pcr = extended_pcr,
		.hash_algorithm = algo,
		.transform = transform,
		.measurement_time = measurement_time,
		.measurement = measurement,
	);

	name->log(name, "");
	DBG3(DBG_PTS, "measurement time: %T", &measurement_time, FALSE);
	DBG3(DBG_PTS, "PCR %2d extended with: %#B", extended_pcr, &measurement);

	return &this->public;
}

/**
 * See header
 */
pts_pcr_transform_t pts_meas_algo_to_pcr_transform(pts_meas_algorithms_t algo,
												   size_t pcr_len)
{
	size_t hash_size;

	hash_size = pts_meas_algo_hash_size(algo);
	if (hash_size == 0)
	{
		return PTS_PCR_TRANSFORM_NO;
	}
	if (hash_size == pcr_len)
	{
		return PTS_PCR_TRANSFORM_MATCH;
	}
	if (hash_size > pcr_len)
	{
		return PTS_PCR_TRANSFORM_LONG;
	}
	return PTS_PCR_TRANSFORM_SHORT;
}