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