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_aik.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_aik_t private_tcg_pts_attr_aik_t
;
26 * Attestation Identity Key
27 * see section 3.13 of PTS Protocol: Binding to TNC IF-M Specification
30 * 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 | Attestation Identity Key (Variable Length) ~
33 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 * | Attestation Identity Key (Variable Length) ~
35 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 #define PTS_AIK_SIZE 4
41 * Private data of an tcg_pts_attr_aik_t object.
43 struct private_tcg_pts_attr_aik_t
{
46 * Public members of tcg_pts_attr_aik_t
48 tcg_pts_attr_aik_t
public;
71 * Naked Public Key flag
76 * Attestation Identity Key
81 METHOD(pa_tnc_attr_t
, get_vendor_id
, pen_t
,
82 private_tcg_pts_attr_aik_t
*this)
84 return this->vendor_id
;
87 METHOD(pa_tnc_attr_t
, get_type
, u_int32_t
,
88 private_tcg_pts_attr_aik_t
*this)
93 METHOD(pa_tnc_attr_t
, get_value
, chunk_t
,
94 private_tcg_pts_attr_aik_t
*this)
99 METHOD(pa_tnc_attr_t
, get_noskip_flag
, bool,
100 private_tcg_pts_attr_aik_t
*this)
102 return this->noskip_flag
;
105 METHOD(pa_tnc_attr_t
, set_noskip_flag
,void,
106 private_tcg_pts_attr_aik_t
*this, bool noskip
)
108 this->noskip_flag
= noskip
;
111 METHOD(pa_tnc_attr_t
, build
, void,
112 private_tcg_pts_attr_aik_t
*this)
114 bio_writer_t
*writer
;
117 writer
= bio_writer_create(PTS_AIK_SIZE
);
119 if(this->naked_pub_aik
) flags
+= 128;
120 writer
->write_uint8 (writer
, flags
);
121 writer
->write_data(writer
, this->aik
);
123 this->value
= chunk_clone(writer
->get_buf(writer
));
124 writer
->destroy(writer
);
127 METHOD(pa_tnc_attr_t
, process
, status_t
,
128 private_tcg_pts_attr_aik_t
*this, u_int32_t
*offset
)
130 bio_reader_t
*reader
;
133 if (this->value
.len
< PTS_AIK_SIZE
)
135 DBG1(DBG_TNC
, "insufficient data for Attestation Identity Key");
139 reader
= bio_reader_create(this->value
);
141 reader
->read_uint8(reader
, &flags
);
142 if((flags
>> 7 ) & 1) this->naked_pub_aik
= true;
144 reader
->read_data (reader
, this->value
.len
- 1, &this->aik
);
145 this->aik
= chunk_clone(this->aik
);
146 reader
->destroy(reader
);
151 METHOD(pa_tnc_attr_t
, destroy
, void,
152 private_tcg_pts_attr_aik_t
*this)
154 free(this->value
.ptr
);
159 METHOD(tcg_pts_attr_aik_t
, get_naked_flag
, bool,
160 private_tcg_pts_attr_aik_t
*this)
162 return this->naked_pub_aik
;
165 METHOD(tcg_pts_attr_aik_t
, set_naked_flag
, void,
166 private_tcg_pts_attr_aik_t
*this, bool naked_pub_aik
)
168 this->naked_pub_aik
= naked_pub_aik
;
171 METHOD(tcg_pts_attr_aik_t
, get_aik
, chunk_t
,
172 private_tcg_pts_attr_aik_t
*this)
177 METHOD(tcg_pts_attr_aik_t
, set_aik
, void,
178 private_tcg_pts_attr_aik_t
*this,
185 * Described in header.
187 pa_tnc_attr_t
*tcg_pts_attr_aik_create(bool naked_pub_aik
, chunk_t aik
)
189 private_tcg_pts_attr_aik_t
*this;
193 .pa_tnc_attribute
= {
194 .get_vendor_id
= _get_vendor_id
,
195 .get_type
= _get_type
,
196 .get_value
= _get_value
,
197 .get_noskip_flag
= _get_noskip_flag
,
198 .set_noskip_flag
= _set_noskip_flag
,
203 .get_naked_flag
= _get_naked_flag
,
204 .set_naked_flag
= _set_naked_flag
,
208 .vendor_id
= PEN_TCG
,
210 .naked_pub_aik
= naked_pub_aik
,
214 return &this->public.pa_tnc_attribute
;
219 * Described in header.
221 pa_tnc_attr_t
*tcg_pts_attr_aik_create_from_data(chunk_t data
)
223 private_tcg_pts_attr_aik_t
*this;
227 .pa_tnc_attribute
= {
228 .get_vendor_id
= _get_vendor_id
,
229 .get_type
= _get_type
,
230 .get_value
= _get_value
,
231 .get_noskip_flag
= _get_noskip_flag
,
232 .set_noskip_flag
= _set_noskip_flag
,
237 .get_naked_flag
= _get_naked_flag
,
238 .set_naked_flag
= _set_naked_flag
,
242 .vendor_id
= PEN_TCG
,
244 .value
= chunk_clone(data
),
247 return &this->public.pa_tnc_attribute
;