Draft version of TCG PTS Request Function Component Evidence Attribute
[strongswan.git] / src / libimcv / tcg / tcg_pts_attr_req_funct_comp_evid.c
1 /*
2 * Copyright (C) 2011 Sansar Choinyambuu
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 "tcg_pts_attr_req_funct_comp_evid.h"
17
18 #include <pa_tnc/pa_tnc_msg.h>
19 #include <bio/bio_writer.h>
20 #include <bio/bio_reader.h>
21 #include <debug.h>
22
23 typedef struct private_tcg_pts_attr_req_funct_comp_evid_t private_tcg_pts_attr_req_funct_comp_evid_t;
24
25 /**
26 * Request Functional Component Evidence (see section 3.14.1 of PTS Protocol: Binding to TNC IF-M Specification)
27 *
28 * 1 2 3
29 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
30 *
31 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32 * | Flags | Sub-component Depth |
33 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 * | Component Functional Name |
35 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 *
37 */
38
39 /**
40 * Component Functional Name Structure (see section 5.1 of PTS Protocol: Binding to TNC IF-M Specification)
41 *
42 * 1 2 3
43 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
44 *
45 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 * | Component Functional Name Vendor ID |Fam| Qualifier |
47 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48 * | Component Functional Name |
49 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
50 *
51 */
52
53 #define PTS_REQ_FUNCT_COMP_EVID_SIZE 12
54 #define PTS_REQ_FUNCT_COMP_EVID_RESERVED 0x00
55
56 /**
57 * Private data of an tcg_pts_attr_req_funct_comp_evid_t object.
58 */
59 struct private_tcg_pts_attr_req_funct_comp_evid_t {
60
61 /**
62 * Public members of tcg_pts_attr_req_funct_comp_evid_t
63 */
64 tcg_pts_attr_req_funct_comp_evid_t public;
65
66 /**
67 * Attribute vendor ID
68 */
69 pen_t vendor_id;
70
71 /**
72 * Attribute type
73 */
74 u_int32_t type;
75
76 /**
77 * Attribute value
78 */
79 chunk_t value;
80
81 /**
82 * Noskip flag
83 */
84 bool noskip_flag;
85
86 /**
87 * Set of flags for Request Functional Component
88 */
89 pts_attr_req_funct_comp_evid_flag_t flags;
90
91 /**
92 * Sub-component Depth
93 */
94 u_int32_t depth;
95
96 /**
97 * Component Functional Name Vendor ID
98 */
99 u_int32_t comp_vendor_id;
100
101 /**
102 * Functional Name Encoding Family
103 */
104 u_int8_t family;
105
106 /**
107 * Functional Name Category Qualifier
108 */
109 u_int8_t qualifier;
110
111 /**
112 * Component Functional Name
113 */
114 u_int32_t name;
115 };
116
117 METHOD(pa_tnc_attr_t, get_vendor_id, pen_t,
118 private_tcg_pts_attr_req_funct_comp_evid_t *this)
119 {
120 return this->vendor_id;
121 }
122
123 METHOD(pa_tnc_attr_t, get_type, u_int32_t,
124 private_tcg_pts_attr_req_funct_comp_evid_t *this)
125 {
126 return this->type;
127 }
128
129 METHOD(pa_tnc_attr_t, get_value, chunk_t,
130 private_tcg_pts_attr_req_funct_comp_evid_t *this)
131 {
132 return this->value;
133 }
134
135 METHOD(pa_tnc_attr_t, get_noskip_flag, bool,
136 private_tcg_pts_attr_req_funct_comp_evid_t *this)
137 {
138 return this->noskip_flag;
139 }
140
141 METHOD(pa_tnc_attr_t, set_noskip_flag,void,
142 private_tcg_pts_attr_req_funct_comp_evid_t *this, bool noskip)
143 {
144 this->noskip_flag = noskip;
145 }
146
147 METHOD(pa_tnc_attr_t, build, void,
148 private_tcg_pts_attr_req_funct_comp_evid_t *this)
149 {
150 bio_writer_t *writer;
151 u_int8_t flags = 0;
152 u_int8_t family_and_qualifier = 0;
153
154 writer = bio_writer_create(PTS_REQ_FUNCT_COMP_EVID_SIZE);
155
156 /* Determine the flags to set*/
157 if(this->flags & PTS_REQ_FUNC_COMP_TTC) flags += 1;
158 if(this->flags & PTS_REQ_FUNC_COMP_VER) flags += 2;
159 if(this->flags & PTS_REQ_FUNC_COMP_CURR) flags += 4;
160 if(this->flags & PTS_REQ_FUNC_COMP_PCR) flags += 8;
161 writer->write_uint8(writer, flags);
162
163 writer->write_uint24 (writer, this->depth);
164 writer->write_uint24 (writer, this->comp_vendor_id);
165
166 if(this->family)
167 {
168 DBG1(DBG_TNC, "Functional Name Encoding Family must be set to 00");
169 }
170
171 writer->write_uint8 (writer, this->depth);
172 writer->write_uint24 (writer, this->depth);
173 writer->write_uint24 (writer, this->depth);
174 writer->write_uint24 (writer, this->depth);
175
176
177 this->value = chunk_clone(writer->get_buf(writer));
178 writer->destroy(writer);
179 }
180
181 METHOD(pa_tnc_attr_t, process, status_t,
182 private_tcg_pts_attr_req_funct_comp_evid_t *this, u_int32_t *offset)
183 {
184 bio_reader_t *reader;
185 u_int8_t flags;
186
187 if (this->value.len < PTS_AIK_SIZE)
188 {
189 DBG1(DBG_TNC, "insufficient data for Attestation Identity Key");
190 *offset = 0;
191 return FAILED;
192 }
193 reader = bio_reader_create(this->value);
194
195 reader->read_uint8(reader, &flags);
196 if(flags) this->naked_pub_aik = true;
197
198 reader->read_data (reader, sizeof(this->value) - 1, &this->aik);
199 this->aik = chunk_clone(this->aik);
200 reader->destroy(reader);
201
202 return SUCCESS;
203 }
204
205 METHOD(pa_tnc_attr_t, destroy, void,
206 private_tcg_pts_attr_req_funct_comp_evid_t *this)
207 {
208 free(this->value.ptr);
209 free(this);
210 }
211
212 METHOD(tcg_pts_attr_req_funct_comp_evid_t, get_flags, pts_attr_req_funct_comp_evid_flag_t,
213 private_tcg_pts_attr_req_funct_comp_evid_t *this)
214 {
215 return this->flags;
216 }
217
218 METHOD(tcg_pts_attr_req_funct_comp_evid_t, set_flags, void,
219 private_tcg_pts_attr_req_funct_comp_evid_t *this, pts_attr_req_funct_comp_evid_flag_t flags)
220 {
221 this->flags = flags;
222 }
223
224 METHOD(tcg_pts_attr_req_funct_comp_evid_t, get_sub_component_depth, u_int32_t,
225 private_tcg_pts_attr_req_funct_comp_evid_t *this)
226 {
227 return this->depth;
228 }
229
230 METHOD(tcg_pts_attr_req_funct_comp_evid_t, get_comp_funct_name_vendor_id, u_int32_t,
231 private_tcg_pts_attr_req_funct_comp_evid_t *this)
232 {
233 return this->comp_vendor_id;
234 }
235
236 METHOD(tcg_pts_attr_req_funct_comp_evid_t, get_family, u_int8_t,
237 private_tcg_pts_attr_req_funct_comp_evid_t *this)
238 {
239 return this->family;
240 }
241
242 METHOD(tcg_pts_attr_req_funct_comp_evid_t, get_qualifier, u_int8_t,
243 private_tcg_pts_attr_req_funct_comp_evid_t *this)
244 {
245 return this->qualifier;
246 }
247
248 METHOD(tcg_pts_attr_req_funct_comp_evid_t, set_fam_qual, void,
249 private_tcg_pts_attr_req_funct_comp_evid_t *this,
250 u_int8_t family, u_int8_t qualifier)
251 {
252 this->family = family;
253 this->qualifier = qualifier;
254 }
255
256 METHOD(tcg_pts_attr_req_funct_comp_evid_t, get_comp_funct_name, u_int32_t,
257 private_tcg_pts_attr_req_funct_comp_evid_t *this)
258 {
259 return this->name;
260 }
261
262 METHOD(tcg_pts_attr_req_funct_comp_evid_t, set_comp_funct_name, void,
263 private_tcg_pts_attr_req_funct_comp_evid_t *this, u_int32_t name)
264 {
265 this->name = name;
266 }
267
268 /**
269 * Described in header.
270 */
271 pa_tnc_attr_t *tcg_pts_attr_req_funct_comp_evid_create(
272 pts_attr_req_funct_comp_evid_flag_t flags,
273 u_int32_t depth,
274 u_int32_t vendor_id,
275 u_int8_t family,
276 u_int8_t qualifier,
277 u_int32_t name)
278 {
279 private_tcg_pts_attr_req_funct_comp_evid_t *this;
280
281 INIT(this,
282 .public = {
283 .pa_tnc_attribute = {
284 .get_vendor_id = _get_vendor_id,
285 .get_type = _get_type,
286 .get_value = _get_value,
287 .get_noskip_flag = _get_noskip_flag,
288 .set_noskip_flag = _set_noskip_flag,
289 .build = _build,
290 .process = _process,
291 .destroy = _destroy,
292 },
293 .get_flags= _get_flags,
294 .set_flags= _set_flags,
295 .get_sub_component_depth = _get_sub_component_depth,
296 .get_comp_funct_name_vendor_id = _get_comp_funct_name_vendor_id,
297 .get_family = _get_family,
298 .get_qualifier = _get_qualifier,
299 .set_fam_qual = _set_fam_qual,
300 .get_comp_funct_name = _get_comp_funct_name,
301 .set_comp_funct_name = _set_comp_funct_name,
302 },
303 .vendor_id = PEN_TCG,
304 .type = TCG_PTS_REQ_FUNCT_COMP_EVID,
305 .flags = flags,
306 .depth = depth,
307 .comp_vendor_id = vendor_id,
308 .family = family,
309 .qualifier = qualifier,
310 .name = name,
311 );
312
313 return &this->public.pa_tnc_attribute;
314 }
315
316
317 /**
318 * Described in header.
319 */
320 pa_tnc_attr_t *tcg_pts_attr_req_funct_comp_evid_create_from_data(chunk_t data)
321 {
322 private_tcg_pts_attr_req_funct_comp_evid_t *this;
323
324 INIT(this,
325 .public = {
326 .pa_tnc_attribute = {
327 .get_vendor_id = _get_vendor_id,
328 .get_type = _get_type,
329 .get_value = _get_value,
330 .get_noskip_flag = _get_noskip_flag,
331 .set_noskip_flag = _set_noskip_flag,
332 .build = _build,
333 .process = _process,
334 .destroy = _destroy,
335 },
336 .get_flags= _get_flags,
337 .set_flags= _set_flags,
338 .get_sub_component_depth = _get_sub_component_depth,
339 .get_comp_funct_name_vendor_id = _get_comp_funct_name_vendor_id,
340 .get_family = _get_family,
341 .get_qualifier = _get_qualifier,
342 .set_fam_qual = _set_fam_qual,
343 .get_comp_funct_name = _get_comp_funct_name,
344 .set_comp_funct_name = _set_comp_funct_name,
345 },
346 .vendor_id = PEN_TCG,
347 .type = TCG_PTS_REQ_FUNCT_COMP_EVID,
348 .value = chunk_clone(data),
349 );
350
351 return &this->public.pa_tnc_attribute;
352 }