Separated IMV session management from IMV policy database
[strongswan.git] / src / libpts / plugins / imv_swid / imv_swid_state.c
1 /*
2 * Copyright (C) 2013-2014 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 "imv_swid_state.h"
17 #include "imv/imv_lang_string.h"
18 #include "imv/imv_reason_string.h"
19 #include "imv/imv_remediation_string.h"
20
21 #include <tncif_policy.h>
22
23 #include <utils/lexparser.h>
24 #include <utils/debug.h>
25
26 typedef struct private_imv_swid_state_t private_imv_swid_state_t;
27
28 /**
29 * Private data of an imv_swid_state_t object.
30 */
31 struct private_imv_swid_state_t {
32
33 /**
34 * Public members of imv_swid_state_t
35 */
36 imv_swid_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 * Does the TNCCS connection support long message types?
50 */
51 bool has_long;
52
53 /**
54 * Does the TNCCS connection support exclusive delivery?
55 */
56 bool has_excl;
57
58 /**
59 * Maximum PA-TNC message size for this TNCCS connection
60 */
61 uint32_t max_msg_len;
62
63 /**
64 * Flags set for completed actions
65 */
66 uint32_t action_flags;
67
68 /**
69 * IMV database session associatied with TNCCS connection
70 */
71 imv_session_t *session;
72
73 /**
74 * IMV action recommendation
75 */
76 TNC_IMV_Action_Recommendation rec;
77
78 /**
79 * IMV evaluation result
80 */
81 TNC_IMV_Evaluation_Result eval;
82
83 /**
84 * IMV Scanner handshake state
85 */
86 imv_swid_handshake_state_t handshake_state;
87
88 /**
89 * TNC Reason String
90 */
91 imv_reason_string_t *reason_string;
92
93 /**
94 * IETF Remediation Instructions String
95 */
96 imv_remediation_string_t *remediation_string;
97
98 };
99
100 METHOD(imv_state_t, get_connection_id, TNC_ConnectionID,
101 private_imv_swid_state_t *this)
102 {
103 return this->connection_id;
104 }
105
106 METHOD(imv_state_t, has_long, bool,
107 private_imv_swid_state_t *this)
108 {
109 return this->has_long;
110 }
111
112 METHOD(imv_state_t, has_excl, bool,
113 private_imv_swid_state_t *this)
114 {
115 return this->has_excl;
116 }
117
118 METHOD(imv_state_t, set_flags, void,
119 private_imv_swid_state_t *this, bool has_long, bool has_excl)
120 {
121 this->has_long = has_long;
122 this->has_excl = has_excl;
123 }
124
125 METHOD(imv_state_t, set_max_msg_len, void,
126 private_imv_swid_state_t *this, uint32_t max_msg_len)
127 {
128 this->max_msg_len = max_msg_len;
129 }
130
131 METHOD(imv_state_t, get_max_msg_len, uint32_t,
132 private_imv_swid_state_t *this)
133 {
134 return this->max_msg_len;
135 }
136
137 METHOD(imv_state_t, set_action_flags, void,
138 private_imv_swid_state_t *this, uint32_t flags)
139 {
140 this->action_flags |= flags;
141 }
142
143 METHOD(imv_state_t, get_action_flags, uint32_t,
144 private_imv_swid_state_t *this)
145 {
146 return this->action_flags;
147 }
148
149 METHOD(imv_state_t, set_session, void,
150 private_imv_swid_state_t *this, imv_session_t *session)
151 {
152 this->session = session;
153 }
154
155 METHOD(imv_state_t, get_session, imv_session_t*,
156 private_imv_swid_state_t *this)
157 {
158 return this->session;
159 }
160
161 METHOD(imv_state_t, change_state, void,
162 private_imv_swid_state_t *this, TNC_ConnectionState new_state)
163 {
164 this->state = new_state;
165 }
166
167 METHOD(imv_state_t, get_recommendation, void,
168 private_imv_swid_state_t *this, TNC_IMV_Action_Recommendation *rec,
169 TNC_IMV_Evaluation_Result *eval)
170 {
171 *rec = this->rec;
172 *eval = this->eval;
173 }
174
175 METHOD(imv_state_t, set_recommendation, void,
176 private_imv_swid_state_t *this, TNC_IMV_Action_Recommendation rec,
177 TNC_IMV_Evaluation_Result eval)
178 {
179 this->rec = rec;
180 this->eval = eval;
181 }
182
183 METHOD(imv_state_t, update_recommendation, void,
184 private_imv_swid_state_t *this, TNC_IMV_Action_Recommendation rec,
185 TNC_IMV_Evaluation_Result eval)
186 {
187 this->rec = tncif_policy_update_recommendation(this->rec, rec);
188 this->eval = tncif_policy_update_evaluation(this->eval, eval);
189 }
190
191 METHOD(imv_state_t, get_reason_string, bool,
192 private_imv_swid_state_t *this, enumerator_t *language_enumerator,
193 chunk_t *reason_string, char **reason_language)
194 {
195 return FALSE;
196 }
197
198 METHOD(imv_state_t, get_remediation_instructions, bool,
199 private_imv_swid_state_t *this, enumerator_t *language_enumerator,
200 chunk_t *string, char **lang_code, char **uri)
201 {
202 return FALSE;
203 }
204
205 METHOD(imv_state_t, destroy, void,
206 private_imv_swid_state_t *this)
207 {
208 DESTROY_IF(this->session);
209 DESTROY_IF(this->reason_string);
210 DESTROY_IF(this->remediation_string);
211 free(this);
212 }
213
214 METHOD(imv_swid_state_t, set_handshake_state, void,
215 private_imv_swid_state_t *this, imv_swid_handshake_state_t new_state)
216 {
217 this->handshake_state = new_state;
218 }
219
220 METHOD(imv_swid_state_t, get_handshake_state, imv_swid_handshake_state_t,
221 private_imv_swid_state_t *this)
222 {
223 return this->handshake_state;
224 }
225
226 /**
227 * Described in header.
228 */
229 imv_state_t *imv_swid_state_create(TNC_ConnectionID connection_id)
230 {
231 private_imv_swid_state_t *this;
232
233 INIT(this,
234 .public = {
235 .interface = {
236 .get_connection_id = _get_connection_id,
237 .has_long = _has_long,
238 .has_excl = _has_excl,
239 .set_flags = _set_flags,
240 .set_max_msg_len = _set_max_msg_len,
241 .get_max_msg_len = _get_max_msg_len,
242 .set_action_flags = _set_action_flags,
243 .get_action_flags = _get_action_flags,
244 .set_session = _set_session,
245 .get_session= _get_session,
246 .change_state = _change_state,
247 .get_recommendation = _get_recommendation,
248 .set_recommendation = _set_recommendation,
249 .update_recommendation = _update_recommendation,
250 .get_reason_string = _get_reason_string,
251 .get_remediation_instructions = _get_remediation_instructions,
252 .destroy = _destroy,
253 },
254 .set_handshake_state = _set_handshake_state,
255 .get_handshake_state = _get_handshake_state,
256 },
257 .state = TNC_CONNECTION_STATE_CREATE,
258 .rec = TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION,
259 .eval = TNC_IMV_EVALUATION_RESULT_DONT_KNOW,
260 .connection_id = connection_id,
261 );
262
263 return &this->public.interface;
264 }
265
266