2 * Copyright (C) 2013-2017 Andreas Steffen
3 * HSR Hochschule fuer Technik Rapperswil
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>.
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
16 #include "imv_swid_state.h"
18 #include <imv/imv_lang_string.h>
19 #include <imv/imv_reason_string.h>
20 #include <imv/imv_remediation_string.h>
21 #include <swid/swid_tag_id.h>
23 #include <tncif_policy.h>
25 #include <utils/lexparser.h>
26 #include <utils/debug.h>
28 typedef struct private_imv_swid_state_t private_imv_swid_state_t
;
31 * Private data of an imv_swid_state_t object.
33 struct private_imv_swid_state_t
{
36 * Public members of imv_swid_state_t
38 imv_swid_state_t
public;
43 TNC_ConnectionID connection_id
;
46 * TNCCS connection state
48 TNC_ConnectionState state
;
51 * Does the TNCCS connection support long message types?
56 * Does the TNCCS connection support exclusive delivery?
61 * Maximum PA-TNC message size for this TNCCS connection
66 * Flags set for completed actions
68 uint32_t action_flags
;
71 * IMV database session associated with TNCCS connection
73 imv_session_t
*session
;
76 * PA-TNC attribute segmentation contracts associated with TNCCS connection
78 seg_contract_manager_t
*contracts
;
81 * IMV action recommendation
83 TNC_IMV_Action_Recommendation rec
;
86 * IMV evaluation result
88 TNC_IMV_Evaluation_Result eval
;
91 * IMV Scanner handshake state
93 imv_swid_handshake_state_t handshake_state
;
98 imv_reason_string_t
*reason_string
;
101 * IETF Remediation Instructions String
103 imv_remediation_string_t
*remediation_string
;
106 * SWID Tag Request ID
111 * Number of processed SWID Tag IDs
116 * Number of processed SWID Tags
121 * Number of missing SWID Tags or Tag IDs
131 * Top level JSON object
136 * JSON array containing an inventory of SWID Tag IDs
142 METHOD(imv_state_t
, get_connection_id
, TNC_ConnectionID
,
143 private_imv_swid_state_t
*this)
145 return this->connection_id
;
148 METHOD(imv_state_t
, has_long
, bool,
149 private_imv_swid_state_t
*this)
151 return this->has_long
;
154 METHOD(imv_state_t
, has_excl
, bool,
155 private_imv_swid_state_t
*this)
157 return this->has_excl
;
160 METHOD(imv_state_t
, set_flags
, void,
161 private_imv_swid_state_t
*this, bool has_long
, bool has_excl
)
163 this->has_long
= has_long
;
164 this->has_excl
= has_excl
;
167 METHOD(imv_state_t
, set_max_msg_len
, void,
168 private_imv_swid_state_t
*this, uint32_t max_msg_len
)
170 this->max_msg_len
= max_msg_len
;
173 METHOD(imv_state_t
, get_max_msg_len
, uint32_t,
174 private_imv_swid_state_t
*this)
176 return this->max_msg_len
;
179 METHOD(imv_state_t
, set_action_flags
, void,
180 private_imv_swid_state_t
*this, uint32_t flags
)
182 this->action_flags
|= flags
;
185 METHOD(imv_state_t
, get_action_flags
, uint32_t,
186 private_imv_swid_state_t
*this)
188 return this->action_flags
;
191 METHOD(imv_state_t
, set_session
, void,
192 private_imv_swid_state_t
*this, imv_session_t
*session
)
194 this->session
= session
;
197 METHOD(imv_state_t
, get_session
, imv_session_t
*,
198 private_imv_swid_state_t
*this)
200 return this->session
;
203 METHOD(imv_state_t
, get_contracts
, seg_contract_manager_t
*,
204 private_imv_swid_state_t
*this)
206 return this->contracts
;
209 METHOD(imv_state_t
, change_state
, void,
210 private_imv_swid_state_t
*this, TNC_ConnectionState new_state
)
212 this->state
= new_state
;
215 METHOD(imv_state_t
, get_recommendation
, void,
216 private_imv_swid_state_t
*this, TNC_IMV_Action_Recommendation
*rec
,
217 TNC_IMV_Evaluation_Result
*eval
)
223 METHOD(imv_state_t
, set_recommendation
, void,
224 private_imv_swid_state_t
*this, TNC_IMV_Action_Recommendation rec
,
225 TNC_IMV_Evaluation_Result eval
)
231 METHOD(imv_state_t
, update_recommendation
, void,
232 private_imv_swid_state_t
*this, TNC_IMV_Action_Recommendation rec
,
233 TNC_IMV_Evaluation_Result eval
)
235 this->rec
= tncif_policy_update_recommendation(this->rec
, rec
);
236 this->eval
= tncif_policy_update_evaluation(this->eval
, eval
);
239 METHOD(imv_state_t
, get_reason_string
, bool,
240 private_imv_swid_state_t
*this, enumerator_t
*language_enumerator
,
241 chunk_t
*reason_string
, char **reason_language
)
246 METHOD(imv_state_t
, get_remediation_instructions
, bool,
247 private_imv_swid_state_t
*this, enumerator_t
*language_enumerator
,
248 chunk_t
*string
, char **lang_code
, char **uri
)
253 METHOD(imv_state_t
, destroy
, void,
254 private_imv_swid_state_t
*this)
256 json_object_put(this->jobj
);
257 DESTROY_IF(this->session
);
258 DESTROY_IF(this->reason_string
);
259 DESTROY_IF(this->remediation_string
);
260 this->contracts
->destroy(this->contracts
);
264 METHOD(imv_swid_state_t
, set_handshake_state
, void,
265 private_imv_swid_state_t
*this, imv_swid_handshake_state_t new_state
)
267 this->handshake_state
= new_state
;
270 METHOD(imv_swid_state_t
, get_handshake_state
, imv_swid_handshake_state_t
,
271 private_imv_swid_state_t
*this)
273 return this->handshake_state
;
276 METHOD(imv_swid_state_t
, set_request_id
, void,
277 private_imv_swid_state_t
*this, uint32_t request_id
)
279 this->request_id
= request_id
;
282 METHOD(imv_swid_state_t
, get_request_id
, uint32_t,
283 private_imv_swid_state_t
*this)
285 return this->request_id
;
288 METHOD(imv_swid_state_t
, set_swid_inventory
, void,
289 private_imv_swid_state_t
*this, swid_inventory_t
*inventory
)
291 chunk_t tag_creator
, sw_id
;
292 char software_id
[BUF_LEN
];
293 json_object
*jstring
;
294 swid_tag_id_t
*tag_id
;
295 enumerator_t
*enumerator
;
297 enumerator
= inventory
->create_enumerator(inventory
);
298 while (enumerator
->enumerate(enumerator
, &tag_id
))
300 /* Construct software ID from tag creator and unique software ID */
301 tag_creator
= tag_id
->get_tag_creator(tag_id
);
302 sw_id
= tag_id
->get_unique_sw_id(tag_id
, NULL
);
303 snprintf(software_id
, BUF_LEN
, "%.*s__%.*s",
304 (int)tag_creator
.len
, tag_creator
.ptr
,
305 (int)sw_id
.len
, sw_id
.ptr
);
306 DBG3(DBG_IMV
, " %s", software_id
);
308 /* Add software ID to JSON array */
309 jstring
= json_object_new_string(software_id
);
310 json_object_array_add(this->jarray
, jstring
);
312 enumerator
->destroy(enumerator
);
315 METHOD(imv_swid_state_t
, get_swid_inventory
, json_object
*,
316 private_imv_swid_state_t
*this)
321 METHOD(imv_swid_state_t
, set_missing
, void,
322 private_imv_swid_state_t
*this, uint32_t count
)
324 this->missing
= count
;
327 METHOD(imv_swid_state_t
, get_missing
, uint32_t,
328 private_imv_swid_state_t
*this)
330 return this->missing
;
333 METHOD(imv_swid_state_t
, set_count
, void,
334 private_imv_swid_state_t
*this, int tag_id_count
, int tag_count
,
337 this->tag_id_count
+= tag_id_count
;
338 this->tag_count
+= tag_count
;
339 this->imc_id
= imc_id
;
342 METHOD(imv_swid_state_t
, get_count
, void,
343 private_imv_swid_state_t
*this, int *tag_id_count
, int *tag_count
)
347 *tag_id_count
= this->tag_id_count
;
351 *tag_count
= this->tag_count
;
355 METHOD(imv_swid_state_t
, get_imc_id
, TNC_UInt32
,
356 private_imv_swid_state_t
*this)
362 * Described in header.
364 imv_state_t
*imv_swid_state_create(TNC_ConnectionID connection_id
)
366 private_imv_swid_state_t
*this;
371 .get_connection_id
= _get_connection_id
,
372 .has_long
= _has_long
,
373 .has_excl
= _has_excl
,
374 .set_flags
= _set_flags
,
375 .set_max_msg_len
= _set_max_msg_len
,
376 .get_max_msg_len
= _get_max_msg_len
,
377 .set_action_flags
= _set_action_flags
,
378 .get_action_flags
= _get_action_flags
,
379 .set_session
= _set_session
,
380 .get_session
= _get_session
,
381 .get_contracts
= _get_contracts
,
382 .change_state
= _change_state
,
383 .get_recommendation
= _get_recommendation
,
384 .set_recommendation
= _set_recommendation
,
385 .update_recommendation
= _update_recommendation
,
386 .get_reason_string
= _get_reason_string
,
387 .get_remediation_instructions
= _get_remediation_instructions
,
390 .set_handshake_state
= _set_handshake_state
,
391 .get_handshake_state
= _get_handshake_state
,
392 .set_request_id
= _set_request_id
,
393 .get_request_id
= _get_request_id
,
394 .set_swid_inventory
= _set_swid_inventory
,
395 .get_swid_inventory
= _get_swid_inventory
,
396 .set_missing
= _set_missing
,
397 .get_missing
= _get_missing
,
398 .set_count
= _set_count
,
399 .get_count
= _get_count
,
400 .get_imc_id
= _get_imc_id
,
402 .state
= TNC_CONNECTION_STATE_CREATE
,
403 .rec
= TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION
,
404 .eval
= TNC_IMV_EVALUATION_RESULT_DONT_KNOW
,
405 .connection_id
= connection_id
,
406 .contracts
= seg_contract_manager_create(),
407 .imc_id
= TNC_IMCID_ANY
,
408 .jobj
= json_object_new_object(),
409 .jarray
= json_object_new_array(),
412 json_object_object_add(this->jobj
, "data", this->jarray
);
414 return &this->public.interface
;