2 * Copyright (C) 2011 Sansar Choinyambuu, Andreas Steffen
3 * HSR Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 #include "pts/components/pts_comp_evidence.h"
20 typedef struct private_pts_comp_evidence_t private_pts_comp_evidence_t
;
23 * Private data of a pts_comp_evidence_t object.
25 struct private_pts_comp_evidence_t
{
28 * Public pts_comp_evidence_t interface.
30 pts_comp_evidence_t
public;
33 * Component Functional Name
35 pts_comp_func_name_t
*name
;
45 time_t measurement_time
;
53 * Measurement Hash Algorithm
55 pts_meas_algorithms_t hash_algorithm
;
58 * Is PCR Information included?
63 * PCR the measurement was extended into
65 u_int32_t extended_pcr
;
68 * PCR value before extension
73 * PCR value after extension
78 * Transformation used for extending measurement into PCR
80 pts_pcr_transform_t transform
;
83 * Component Validation Result
85 pts_comp_evid_validation_t validation
;
88 * Verification Policy URI
94 METHOD(pts_comp_evidence_t
, get_comp_func_name
, pts_comp_func_name_t
*,
95 private_pts_comp_evidence_t
*this, u_int32_t
*depth
)
104 METHOD(pts_comp_evidence_t
, get_extended_pcr
, u_int32_t
,
105 private_pts_comp_evidence_t
*this)
107 return this->extended_pcr
;
109 METHOD(pts_comp_evidence_t
, get_measurement
, chunk_t
,
110 private_pts_comp_evidence_t
*this, u_int32_t
*extended_pcr
,
111 pts_meas_algorithms_t
*algo
, pts_pcr_transform_t
*transform
,
112 time_t *measurement_time
)
116 *extended_pcr
= this->extended_pcr
;
120 *algo
= this->hash_algorithm
;
124 *transform
= this->transform
;
126 if (measurement_time
)
128 *measurement_time
= this->measurement_time
;
130 return this->measurement
;
133 METHOD(pts_comp_evidence_t
, get_pcr_info
, bool,
134 private_pts_comp_evidence_t
*this, chunk_t
*pcr_before
, chunk_t
*pcr_after
)
138 *pcr_before
= this->pcr_before
;
142 *pcr_after
= this->pcr_after
;
144 return this->has_pcr_info
;
147 METHOD(pts_comp_evidence_t
, set_pcr_info
, void,
148 private_pts_comp_evidence_t
*this, chunk_t pcr_before
, chunk_t pcr_after
)
150 this->has_pcr_info
= TRUE
;
151 this->pcr_before
= pcr_before
;
152 this->pcr_after
= pcr_after
;
154 DBG2(DBG_PTS
, "PCR %2d before value : %#B", this->extended_pcr
, &pcr_before
);
155 DBG2(DBG_PTS
, "PCR %2d after value : %#B", this->extended_pcr
, &pcr_after
);
158 METHOD(pts_comp_evidence_t
, get_validation
, pts_comp_evid_validation_t
,
159 private_pts_comp_evidence_t
*this, chunk_t
*uri
)
163 *uri
= this->policy_uri
;
165 return this->validation
;
168 METHOD(pts_comp_evidence_t
, set_validation
, void,
169 private_pts_comp_evidence_t
*this, pts_comp_evid_validation_t validation
,
172 this->validation
= validation
;
173 this->policy_uri
= chunk_clone(uri
);
176 METHOD(pts_comp_evidence_t
, destroy
, void,
177 private_pts_comp_evidence_t
*this)
179 this->name
->destroy(this->name
);
180 free(this->measurement
.ptr
);
181 free(this->pcr_before
.ptr
);
182 free(this->pcr_after
.ptr
);
183 free(this->policy_uri
.ptr
);
190 pts_comp_evidence_t
*pts_comp_evidence_create(pts_comp_func_name_t
*name
,
192 u_int32_t extended_pcr
,
193 pts_meas_algorithms_t algo
,
194 pts_pcr_transform_t transform
,
195 time_t measurement_time
,
198 private_pts_comp_evidence_t
*this;
202 .get_comp_func_name
= _get_comp_func_name
,
203 .get_extended_pcr
= _get_extended_pcr
,
204 .get_measurement
= _get_measurement
,
205 .get_pcr_info
= _get_pcr_info
,
206 .set_pcr_info
= _set_pcr_info
,
207 .get_validation
= _get_validation
,
208 .set_validation
= _set_validation
,
211 .name
= name
->clone(name
),
213 .extended_pcr
= extended_pcr
,
214 .hash_algorithm
= algo
,
215 .transform
= transform
,
216 .measurement_time
= measurement_time
,
217 .measurement
= measurement
,
221 DBG2(DBG_PTS
, "PCR %2d extended with: %#B", extended_pcr
, &measurement
);
223 return &this->public;