2 * Copyright (C) 2011 Sansar Choinyambuu
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 "tcg_pts_attr_req_funct_comp_evid.h"
18 #include <pa_tnc/pa_tnc_msg.h>
19 #include <bio/bio_writer.h>
20 #include <bio/bio_reader.h>
23 typedef struct private_tcg_pts_attr_req_funct_comp_evid_t private_tcg_pts_attr_req_funct_comp_evid_t
;
26 * Request Functional Component Evidence (see section 3.14.1 of PTS Protocol: Binding to TNC IF-M Specification)
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
31 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32 * | Flags | Sub-component Depth |
33 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 * | Component Functional Name |
35 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 * Component Functional Name Structure (see section 5.1 of PTS Protocol: Binding to TNC IF-M Specification)
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
45 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 * | Component Functional Name Vendor ID |Fam| Qualifier |
47 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48 * | Component Functional Name |
49 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
53 #define PTS_REQ_FUNCT_COMP_EVID_SIZE 12
54 #define PTS_REQ_FUNCT_COMP_EVID_RESERVED 0x00
57 * Private data of an tcg_pts_attr_req_funct_comp_evid_t object.
59 struct private_tcg_pts_attr_req_funct_comp_evid_t
{
62 * Public members of tcg_pts_attr_req_funct_comp_evid_t
64 tcg_pts_attr_req_funct_comp_evid_t
public;
87 * Set of flags for Request Functional Component
89 pts_attr_req_funct_comp_evid_flag_t flags
;
97 * Component Functional Name Vendor ID
99 u_int32_t comp_vendor_id
;
102 * Functional Name Encoding Family
107 * Functional Name Category Qualifier
112 * Component Functional Name
117 METHOD(pa_tnc_attr_t
, get_vendor_id
, pen_t
,
118 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
120 return this->vendor_id
;
123 METHOD(pa_tnc_attr_t
, get_type
, u_int32_t
,
124 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
129 METHOD(pa_tnc_attr_t
, get_value
, chunk_t
,
130 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
135 METHOD(pa_tnc_attr_t
, get_noskip_flag
, bool,
136 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
138 return this->noskip_flag
;
141 METHOD(pa_tnc_attr_t
, set_noskip_flag
,void,
142 private_tcg_pts_attr_req_funct_comp_evid_t
*this, bool noskip
)
144 this->noskip_flag
= noskip
;
147 METHOD(pa_tnc_attr_t
, build
, void,
148 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
150 bio_writer_t
*writer
;
152 u_int8_t family_and_qualifier
= 0;
154 writer
= bio_writer_create(PTS_REQ_FUNCT_COMP_EVID_SIZE
);
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
);
163 writer
->write_uint24 (writer
, this->depth
);
164 writer
->write_uint24 (writer
, this->comp_vendor_id
);
168 DBG1(DBG_TNC
, "Functional Name Encoding Family must be set to 00");
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
);
177 this->value
= chunk_clone(writer
->get_buf(writer
));
178 writer
->destroy(writer
);
181 METHOD(pa_tnc_attr_t
, process
, status_t
,
182 private_tcg_pts_attr_req_funct_comp_evid_t
*this, u_int32_t
*offset
)
184 bio_reader_t
*reader
;
187 if (this->value
.len
< PTS_AIK_SIZE
)
189 DBG1(DBG_TNC
, "insufficient data for Attestation Identity Key");
193 reader
= bio_reader_create(this->value
);
195 reader
->read_uint8(reader
, &flags
);
196 if(flags
) this->naked_pub_aik
= true;
198 reader
->read_data (reader
, sizeof(this->value
) - 1, &this->aik
);
199 this->aik
= chunk_clone(this->aik
);
200 reader
->destroy(reader
);
205 METHOD(pa_tnc_attr_t
, destroy
, void,
206 private_tcg_pts_attr_req_funct_comp_evid_t
*this)
208 free(this->value
.ptr
);
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)
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
)
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)
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)
233 return this->comp_vendor_id
;
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)
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)
245 return this->qualifier
;
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
)
252 this->family
= family
;
253 this->qualifier
= qualifier
;
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)
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
)
269 * Described in header.
271 pa_tnc_attr_t
*tcg_pts_attr_req_funct_comp_evid_create(
272 pts_attr_req_funct_comp_evid_flag_t flags
,
279 private_tcg_pts_attr_req_funct_comp_evid_t
*this;
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
,
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
,
303 .vendor_id
= PEN_TCG
,
304 .type
= TCG_PTS_REQ_FUNCT_COMP_EVID
,
307 .comp_vendor_id
= vendor_id
,
309 .qualifier
= qualifier
,
313 return &this->public.pa_tnc_attribute
;
318 * Described in header.
320 pa_tnc_attr_t
*tcg_pts_attr_req_funct_comp_evid_create_from_data(chunk_t data
)
322 private_tcg_pts_attr_req_funct_comp_evid_t
*this;
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
,
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
,
346 .vendor_id
= PEN_TCG
,
347 .type
= TCG_PTS_REQ_FUNCT_COMP_EVID
,
348 .value
= chunk_clone(data
),
351 return &this->public.pa_tnc_attribute
;