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_tgrub.h"
18 #include "ita_comp_func_name.h"
20 #include "pts/components/pts_component.h"
25 typedef struct pts_ita_comp_tgrub_t pts_ita_comp_tgrub_t
;
28 * Private data of a pts_ita_comp_tgrub_t object.
31 struct pts_ita_comp_tgrub_t
{
34 * Public pts_component_t interface.
36 pts_component_t
public;
39 * Component Functional Name
41 pts_comp_func_name_t
*name
;
44 METHOD(pts_component_t
, get_comp_func_name
, pts_comp_func_name_t
*,
45 pts_ita_comp_tgrub_t
*this)
50 METHOD(pts_component_t
, get_evidence_flags
, u_int8_t
,
51 pts_ita_comp_tgrub_t
*this)
53 return PTS_REQ_FUNC_COMP_EVID_PCR
;
56 METHOD(pts_component_t
, measure
, status_t
,
57 pts_ita_comp_tgrub_t
*this, pts_t
*pts
, pts_comp_evidence_t
**evidence
)
59 pts_comp_evidence_t
*evid
;
60 u_int32_t extended_pcr
;
61 time_t measurement_time
;
62 chunk_t measurement
, pcr_before
, pcr_after
;
64 /* Provisional implementation for TGRUB */
65 extended_pcr
= PCR_DEBUG
;
66 time(&measurement_time
);
68 if (!pts
->read_pcr(pts
, extended_pcr
, &pcr_after
))
70 DBG1(DBG_PTS
, "error occured while reading PCR: %d", extended_pcr
);
74 measurement
= chunk_alloc(HASH_SIZE_SHA1
);
75 memset(measurement
.ptr
, 0x00, measurement
.len
);
77 pcr_before
= chunk_alloc(PCR_LEN
);
78 memset(pcr_before
.ptr
, 0x00, pcr_before
.len
);
80 evid
= *evidence
= pts_comp_evidence_create(this->name
->clone(this->name
),
82 PTS_MEAS_ALGO_SHA1
, PTS_PCR_TRANSFORM_NO
,
83 measurement_time
, measurement
);
84 evid
->set_pcr_info(evid
, pcr_before
, pcr_after
);
89 METHOD(pts_component_t
, verify
, status_t
,
90 pts_ita_comp_tgrub_t
*this, pts_t
*pts
, pts_database_t
*pts_db
,
91 pts_comp_evidence_t
*evidence
)
94 u_int32_t extended_pcr
;
95 pts_meas_algorithms_t algo
;
96 pts_pcr_transform_t transform
;
97 time_t measurement_time
;
98 chunk_t measurement
, pcr_before
, pcr_after
;
100 measurement
= evidence
->get_measurement(evidence
, &extended_pcr
,
101 &algo
, &transform
, &measurement_time
);
102 if (extended_pcr
!= PCR_DEBUG
)
107 /* TODO check measurement in database */
109 has_pcr_info
= evidence
->get_pcr_info(evidence
, &pcr_before
, &pcr_after
);
112 if (!pts
->add_pcr(pts
, extended_pcr
, pcr_before
, pcr_after
))
121 METHOD(pts_component_t
, destroy
, void,
122 pts_ita_comp_tgrub_t
*this)
124 this->name
->destroy(this->name
);
131 pts_component_t
*pts_ita_comp_tgrub_create(u_int8_t qualifier
)
133 pts_ita_comp_tgrub_t
*this;
137 .get_comp_func_name
= _get_comp_func_name
,
138 .get_evidence_flags
= _get_evidence_flags
,
143 .name
= pts_comp_func_name_create(PEN_ITA
, PTS_ITA_COMP_FUNC_NAME_TBOOT
,
147 return &this->public;