sub-component depth from pts database on component evidence request
[strongswan.git] / src / libpts / pts / components / ita / ita_comp_tgrub.c
1 /*
2 * Copyright (C) 2011 Andreas Steffen
3 *
4 * HSR Hochschule fuer Technik Rapperswil
5 *
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>.
10 *
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
14 * for more details.
15 */
16
17 #include "ita_comp_tgrub.h"
18 #include "ita_comp_func_name.h"
19
20 #include "pts/components/pts_component.h"
21
22 #include <debug.h>
23 #include <pen/pen.h>
24
25 typedef struct pts_ita_comp_tgrub_t pts_ita_comp_tgrub_t;
26
27 /**
28 * Private data of a pts_ita_comp_tgrub_t object.
29 *
30 */
31 struct pts_ita_comp_tgrub_t {
32
33 /**
34 * Public pts_component_t interface.
35 */
36 pts_component_t public;
37
38 /**
39 * Component Functional Name
40 */
41 pts_comp_func_name_t *name;
42
43 /**
44 * Sub-component depth
45 */
46 u_int32_t depth;
47 };
48
49 METHOD(pts_component_t, get_comp_func_name, pts_comp_func_name_t*,
50 pts_ita_comp_tgrub_t *this)
51 {
52 return this->name;
53 }
54
55 METHOD(pts_component_t, get_evidence_flags, u_int8_t,
56 pts_ita_comp_tgrub_t *this)
57 {
58 return PTS_REQ_FUNC_COMP_EVID_PCR;
59 }
60
61 METHOD(pts_component_t, get_depth, u_int32_t,
62 pts_ita_comp_tgrub_t *this)
63 {
64 return this->depth;
65 }
66
67 METHOD(pts_component_t, measure, status_t,
68 pts_ita_comp_tgrub_t *this, pts_t *pts, pts_comp_evidence_t **evidence)
69 {
70 pts_comp_evidence_t *evid;
71 u_int32_t extended_pcr;
72 time_t measurement_time;
73 chunk_t measurement, pcr_before, pcr_after;
74
75 /* Provisional implementation for TGRUB */
76 extended_pcr = PCR_DEBUG;
77 time(&measurement_time);
78
79 if (!pts->read_pcr(pts, extended_pcr, &pcr_after))
80 {
81 DBG1(DBG_PTS, "error occured while reading PCR: %d", extended_pcr);
82 return FAILED;
83 }
84
85 measurement = chunk_alloc(HASH_SIZE_SHA1);
86 memset(measurement.ptr, 0x00, measurement.len);
87
88 pcr_before = chunk_alloc(PCR_LEN);
89 memset(pcr_before.ptr, 0x00, pcr_before.len);
90
91 evid = *evidence = pts_comp_evidence_create(this->name->clone(this->name),
92 0, extended_pcr,
93 PTS_MEAS_ALGO_SHA1, PTS_PCR_TRANSFORM_NO,
94 measurement_time, measurement);
95 evid->set_pcr_info(evid, pcr_before, pcr_after);
96
97 return SUCCESS;
98 }
99
100 METHOD(pts_component_t, verify, status_t,
101 pts_ita_comp_tgrub_t *this, pts_t *pts, pts_database_t *pts_db,
102 pts_comp_evidence_t *evidence)
103 {
104 bool has_pcr_info;
105 u_int32_t extended_pcr;
106 pts_meas_algorithms_t algo;
107 pts_pcr_transform_t transform;
108 time_t measurement_time;
109 chunk_t measurement, pcr_before, pcr_after;
110
111 measurement = evidence->get_measurement(evidence, &extended_pcr,
112 &algo, &transform, &measurement_time);
113 if (extended_pcr != PCR_DEBUG)
114 {
115 return FAILED;
116 }
117
118 /* TODO check measurement in database */
119
120 has_pcr_info = evidence->get_pcr_info(evidence, &pcr_before, &pcr_after);
121 if (has_pcr_info)
122 {
123 if (!pts->add_pcr(pts, extended_pcr, pcr_before, pcr_after))
124 {
125 return FAILED;
126 }
127 }
128
129 return SUCCESS;
130 }
131
132 METHOD(pts_component_t, destroy, void,
133 pts_ita_comp_tgrub_t *this)
134 {
135 this->name->destroy(this->name);
136 free(this);
137 }
138
139 /**
140 * See header
141 */
142 pts_component_t *pts_ita_comp_tgrub_create(u_int8_t qualifier, u_int32_t depth)
143 {
144 pts_ita_comp_tgrub_t *this;
145
146 INIT(this,
147 .public = {
148 .get_comp_func_name = _get_comp_func_name,
149 .get_evidence_flags = _get_evidence_flags,
150 .get_depth = _get_depth,
151 .measure = _measure,
152 .verify = _verify,
153 .destroy = _destroy,
154 },
155 .name = pts_comp_func_name_create(PEN_ITA, PTS_ITA_COMP_FUNC_NAME_TBOOT,
156 qualifier),
157 .depth = depth,
158 );
159
160 return &this->public;
161 }
162