introduced sending of standard IETF Assessment Result PA-TNC attribute by IMVs
[strongswan.git] / src / libpts / plugins / imc_attestation / imc_attestation_state.c
1 /*
2 * Copyright (C) 2011-2012 Sansar Choinyambuu, 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 "imc_attestation_state.h"
17
18 #include <libpts.h>
19
20 #include <tncif_names.h>
21
22 #include <utils/linked_list.h>
23 #include <debug.h>
24
25 typedef struct private_imc_attestation_state_t private_imc_attestation_state_t;
26 typedef struct func_comp_t func_comp_t;
27
28 /**
29 * Private data of an imc_attestation_state_t object.
30 */
31 struct private_imc_attestation_state_t {
32
33 /**
34 * Public members of imc_attestation_state_t
35 */
36 imc_attestation_state_t public;
37
38 /**
39 * TNCCS connection ID
40 */
41 TNC_ConnectionID connection_id;
42
43 /**
44 * TNCCS connection state
45 */
46 TNC_ConnectionState state;
47
48 /**
49 * Assessment/Evaluation Result
50 */
51 TNC_IMV_Evaluation_Result result;
52
53 /**
54 * Does the TNCCS connection support long message types?
55 */
56 bool has_long;
57
58 /**
59 * Does the TNCCS connection support exclusive delivery?
60 */
61 bool has_excl;
62
63 /**
64 * Maximum PA-TNC message size for this TNCCS connection
65 */
66 u_int32_t max_msg_len;
67
68 /**
69 * PTS object
70 */
71 pts_t *pts;
72
73 /**
74 * List of Functional Components
75 */
76 linked_list_t *components;
77
78 /**
79 * Functional Component Evidence cache list
80 */
81 linked_list_t *list;
82
83 };
84
85 METHOD(imc_state_t, get_connection_id, TNC_ConnectionID,
86 private_imc_attestation_state_t *this)
87 {
88 return this->connection_id;
89 }
90
91 METHOD(imc_state_t, has_long, bool,
92 private_imc_attestation_state_t *this)
93 {
94 return this->has_long;
95 }
96
97 METHOD(imc_state_t, has_excl, bool,
98 private_imc_attestation_state_t *this)
99 {
100 return this->has_excl;
101 }
102
103 METHOD(imc_state_t, set_flags, void,
104 private_imc_attestation_state_t *this, bool has_long, bool has_excl)
105 {
106 this->has_long = has_long;
107 this->has_excl = has_excl;
108 }
109
110 METHOD(imc_state_t, set_max_msg_len, void,
111 private_imc_attestation_state_t *this, u_int32_t max_msg_len)
112 {
113 this->max_msg_len = max_msg_len;
114 }
115
116 METHOD(imc_state_t, get_max_msg_len, u_int32_t,
117 private_imc_attestation_state_t *this)
118 {
119 return this->max_msg_len;
120 }
121
122 METHOD(imc_state_t, change_state, void,
123 private_imc_attestation_state_t *this, TNC_ConnectionState new_state)
124 {
125 this->state = new_state;
126 }
127
128 METHOD(imc_state_t, set_result, void,
129 private_imc_attestation_state_t *this, TNC_IMCID id,
130 TNC_IMV_Evaluation_Result result)
131 {
132 DBG1(DBG_IMC, "set assessment result for IMC %u to '%N'",
133 id, TNC_IMV_Evaluation_Result_names, result);
134 this->result = result;
135 }
136
137 METHOD(imc_state_t, get_result, bool,
138 private_imc_attestation_state_t *this, TNC_IMCID id,
139 TNC_IMV_Evaluation_Result *result)
140 {
141 if (result)
142 {
143 *result = this->result;
144 }
145 return this->result != TNC_IMV_EVALUATION_RESULT_DONT_KNOW;
146 }
147
148 METHOD(imc_state_t, destroy, void,
149 private_imc_attestation_state_t *this)
150 {
151 this->pts->destroy(this->pts);
152 this->components->destroy_offset(this->components,
153 offsetof(pts_component_t, destroy));
154 this->list->destroy_offset(this->list,
155 offsetof(pts_comp_evidence_t, destroy));
156 free(this);
157 }
158
159 METHOD(imc_attestation_state_t, get_pts, pts_t*,
160 private_imc_attestation_state_t *this)
161 {
162 return this->pts;
163 }
164
165 METHOD(imc_attestation_state_t, create_component, pts_component_t*,
166 private_imc_attestation_state_t *this, pts_comp_func_name_t *name,
167 u_int32_t depth)
168 {
169 enumerator_t *enumerator;
170 pts_component_t *component;
171 bool found = FALSE;
172
173 enumerator = this->components->create_enumerator(this->components);
174 while (enumerator->enumerate(enumerator, &component))
175 {
176 if (name->equals(name, component->get_comp_func_name(component)))
177 {
178 found = TRUE;
179 break;
180 }
181 }
182 enumerator->destroy(enumerator);
183
184 if (!found)
185 {
186 component = pts_components->create(pts_components, name, depth, NULL);
187 if (!component)
188 {
189 return NULL;
190 }
191 this->components->insert_last(this->components, component);
192
193 }
194 return component;
195 }
196
197 METHOD(imc_attestation_state_t, add_evidence, void,
198 private_imc_attestation_state_t *this, pts_comp_evidence_t *evid)
199 {
200 this->list->insert_last(this->list, evid);
201 }
202
203 METHOD(imc_attestation_state_t, next_evidence, bool,
204 private_imc_attestation_state_t *this, pts_comp_evidence_t **evid)
205 {
206 return this->list->remove_first(this->list, (void**)evid) == SUCCESS;
207 }
208
209 /**
210 * Described in header.
211 */
212 imc_state_t *imc_attestation_state_create(TNC_ConnectionID connection_id)
213 {
214 private_imc_attestation_state_t *this;
215 char *platform_info;
216
217 INIT(this,
218 .public = {
219 .interface = {
220 .get_connection_id = _get_connection_id,
221 .has_long = _has_long,
222 .has_excl = _has_excl,
223 .set_flags = _set_flags,
224 .set_max_msg_len = _set_max_msg_len,
225 .get_max_msg_len = _get_max_msg_len,
226 .change_state = _change_state,
227 .set_result = _set_result,
228 .get_result = _get_result,
229 .destroy = _destroy,
230 },
231 .get_pts = _get_pts,
232 .create_component = _create_component,
233 .add_evidence = _add_evidence,
234 .next_evidence = _next_evidence,
235 },
236 .connection_id = connection_id,
237 .state = TNC_CONNECTION_STATE_CREATE,
238 .result = TNC_IMV_EVALUATION_RESULT_DONT_KNOW,
239 .pts = pts_create(TRUE),
240 .components = linked_list_create(),
241 .list = linked_list_create(),
242 );
243
244 platform_info = lib->settings->get_str(lib->settings,
245 "libimcv.plugins.imc-attestation.platform_info", NULL);
246 if (platform_info)
247 {
248 this->pts->set_platform_info(this->pts, platform_info);
249 }
250
251 return &this->public.interface;
252 }
253
254