2 * Copyright (C) 2011 Andreas Steffen
4 * HSR Hochschule fuer Technik Rapperswil
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 #include "ita_comp_tboot.h"
18 #include "ita_comp_func_name.h"
20 #include "pts/components/pts_component.h"
21 #include "pts/components/pts_comp_evidence.h"
26 #define TBOOT_SEQUENCE 2
28 typedef struct pts_ita_comp_tboot_t pts_ita_comp_tboot_t
;
31 * Private data of a pts_ita_comp_tboot_t object.
34 struct pts_ita_comp_tboot_t
{
37 * Public pts_component_t interface.
39 pts_component_t
public;
42 * Component Functional Name
44 pts_comp_func_name_t
*name
;
52 * Time of TBOOT measurement
54 time_t measurement_time
;
57 * Measurement sequence number
63 METHOD(pts_component_t
, get_comp_func_name
, pts_comp_func_name_t
*,
64 pts_ita_comp_tboot_t
*this)
69 METHOD(pts_component_t
, get_evidence_flags
, u_int8_t
,
70 pts_ita_comp_tboot_t
*this)
72 return PTS_REQ_FUNC_COMP_EVID_PCR
;
75 METHOD(pts_component_t
, get_depth
, u_int32_t
,
76 pts_ita_comp_tboot_t
*this)
81 METHOD(pts_component_t
, measure
, status_t
,
82 pts_ita_comp_tboot_t
*this, pts_t
*pts
, pts_comp_evidence_t
**evidence
)
84 pts_comp_evidence_t
*evid
;
85 char *meas_hex
, *pcr_before_hex
, *pcr_after_hex
;
86 chunk_t measurement
, pcr_before
, pcr_after
;
87 size_t hash_size
, pcr_len
;
88 u_int32_t extended_pcr
;
89 pts_pcr_transform_t pcr_transform
;
90 pts_meas_algorithms_t hash_algo
;
92 switch (this->seq_no
++)
95 /* dummy data since currently the TBOOT log is not retrieved */
96 time(&this->measurement_time
);
97 meas_hex
= lib
->settings
->get_str(lib
->settings
,
98 "libimcv.plugins.imc-attestation.pcr17_meas", NULL
);
99 pcr_before_hex
= lib
->settings
->get_str(lib
->settings
,
100 "libimcv.plugins.imc-attestation.pcr17_before", NULL
);
101 pcr_after_hex
= lib
->settings
->get_str(lib
->settings
,
102 "libimcv.plugins.imc-attestation.pcr17_after", NULL
);
103 extended_pcr
= PCR_TBOOT_POLICY
;
106 /* dummy data since currently the TBOOT log is not retrieved */
107 meas_hex
= lib
->settings
->get_str(lib
->settings
,
108 "libimcv.plugins.imc-attestation.pcr18_meas", NULL
);
109 pcr_before_hex
= lib
->settings
->get_str(lib
->settings
,
110 "libimcv.plugins.imc-attestation.pcr18_before", NULL
);
111 pcr_after_hex
= lib
->settings
->get_str(lib
->settings
,
112 "libimcv.plugins.imc-attestation.pcr18_after", NULL
);
113 extended_pcr
= PCR_TBOOT_MLE
;
119 hash_algo
= pts
->get_meas_algorithm(pts
);
120 hash_size
= pts_meas_algo_hash_size(hash_algo
);
121 pcr_len
= pts
->get_pcr_len(pts
);
122 pcr_transform
= pts_meas_algo_to_pcr_transform(hash_algo
, pcr_len
);
124 /* get and check the measurement data */
125 measurement
= chunk_from_hex(
126 chunk_create(meas_hex
, strlen(meas_hex
)), NULL
);
127 pcr_before
= chunk_from_hex(
128 chunk_create(pcr_before_hex
, strlen(pcr_before_hex
)), NULL
);
129 pcr_after
= chunk_from_hex(
130 chunk_create(pcr_after_hex
, strlen(pcr_after_hex
)), NULL
);
131 if (pcr_before
.len
!= pcr_len
|| pcr_after
.len
!= pcr_len
||
132 measurement
.len
!= hash_size
)
134 DBG1(DBG_PTS
, "TBOOT measurement or pcr data have the wrong size");
135 free(measurement
.ptr
);
136 free(pcr_before
.ptr
);
141 evid
= *evidence
= pts_comp_evidence_create(this->name
->clone(this->name
),
142 this->depth
, extended_pcr
,
143 hash_algo
, pcr_transform
,
144 this->measurement_time
, measurement
);
145 evid
->set_pcr_info(evid
, pcr_before
, pcr_after
);
147 return (this->seq_no
< TBOOT_SEQUENCE
) ? NEED_MORE
: SUCCESS
;
150 METHOD(pts_component_t
, verify
, status_t
,
151 pts_ita_comp_tboot_t
*this, pts_t
*pts
, pts_database_t
*pts_db
,
152 pts_comp_evidence_t
*evidence
)
156 u_int32_t extended_pcr
;
157 pts_meas_algorithms_t algo
;
158 pts_pcr_transform_t transform
;
159 time_t measurement_time
;
160 chunk_t measurement
, pcr_before
, pcr_after
, hash
;
162 platform_info
= pts
->get_platform_info(pts
);
163 if (!pts_db
|| !platform_info
)
165 DBG1(DBG_PTS
, "%s%s%s not available",
166 (pts_db
) ?
"" : "pts database",
167 (!pts_db
&& !platform_info
) ?
"and" : "",
168 (platform_info
) ?
"" : "platform info");
171 measurement
= evidence
->get_measurement(evidence
, &extended_pcr
,
172 &algo
, &transform
, &measurement_time
);
174 if (pts_db
->check_comp_measurement(pts_db
, measurement
, this->name
,
175 platform_info
, ++this->seq_no
, extended_pcr
, algo
) != SUCCESS
)
180 has_pcr_info
= evidence
->get_pcr_info(evidence
, &pcr_before
, &pcr_after
);
183 if (!pts
->add_pcr(pts
, extended_pcr
, pcr_before
, pcr_after
))
189 return (this->seq_no
< TBOOT_SEQUENCE
) ? NEED_MORE
: SUCCESS
;
192 METHOD(pts_component_t
, destroy
, void,
193 pts_ita_comp_tboot_t
*this)
195 this->name
->destroy(this->name
);
202 pts_component_t
*pts_ita_comp_tboot_create(u_int8_t qualifier
, u_int32_t depth
)
204 pts_ita_comp_tboot_t
*this;
208 .get_comp_func_name
= _get_comp_func_name
,
209 .get_evidence_flags
= _get_evidence_flags
,
210 .get_depth
= _get_depth
,
215 .name
= pts_comp_func_name_create(PEN_ITA
, PTS_ITA_COMP_FUNC_NAME_TBOOT
,
220 return &this->public;