cosmetics
[strongswan.git] / src / libimcv / tcg / tcg_pts_attr_get_aik.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_get_aik.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_get_aik_t private_tcg_pts_attr_get_aik_t;
24
25 /**
26 * Get Attestation Identity Key
27 * see section 3.12 of PTS Protocol: Binding to TNC IF-M Specification
28 *
29 * 1 2 3
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 * | Reserved |
33 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 */
35
36 #define PTS_GET_AIK_SIZE 4
37 #define PTS_GET_AIK_RESERVED 0x00000000
38
39 /**
40 * Private data of an tcg_pts_attr_get_aik_t object.
41 */
42 struct private_tcg_pts_attr_get_aik_t {
43
44 /**
45 * Public members of tcg_pts_attr_get_aik_t
46 */
47 tcg_pts_attr_get_aik_t public;
48
49 /**
50 * Attribute vendor ID
51 */
52 pen_t vendor_id;
53
54 /**
55 * Attribute type
56 */
57 u_int32_t type;
58
59 /**
60 * Attribute value
61 */
62 chunk_t value;
63
64 /**
65 * Noskip flag
66 */
67 bool noskip_flag;
68 };
69
70 METHOD(pa_tnc_attr_t, get_vendor_id, pen_t,
71 private_tcg_pts_attr_get_aik_t *this)
72 {
73 return this->vendor_id;
74 }
75
76 METHOD(pa_tnc_attr_t, get_type, u_int32_t,
77 private_tcg_pts_attr_get_aik_t *this)
78 {
79 return this->type;
80 }
81
82 METHOD(pa_tnc_attr_t, get_value, chunk_t,
83 private_tcg_pts_attr_get_aik_t *this)
84 {
85 return this->value;
86 }
87
88 METHOD(pa_tnc_attr_t, get_noskip_flag, bool,
89 private_tcg_pts_attr_get_aik_t *this)
90 {
91 return this->noskip_flag;
92 }
93
94 METHOD(pa_tnc_attr_t, set_noskip_flag,void,
95 private_tcg_pts_attr_get_aik_t *this, bool noskip)
96 {
97 this->noskip_flag = noskip;
98 }
99
100 METHOD(pa_tnc_attr_t, build, void,
101 private_tcg_pts_attr_get_aik_t *this)
102 {
103 bio_writer_t *writer;
104
105 writer = bio_writer_create(PTS_GET_AIK_SIZE);
106 writer->write_uint32 (writer, PTS_GET_AIK_RESERVED);
107
108 this->value = chunk_clone(writer->get_buf(writer));
109 writer->destroy(writer);
110 }
111
112 METHOD(pa_tnc_attr_t, process, status_t,
113 private_tcg_pts_attr_get_aik_t *this, u_int32_t *offset)
114 {
115 bio_reader_t *reader;
116 u_int32_t reserved;
117
118 if (this->value.len < PTS_GET_AIK_SIZE)
119 {
120 DBG1(DBG_TNC, "insufficient data for Get AIK");
121 *offset = 0;
122 return FAILED;
123 }
124 reader = bio_reader_create(this->value);
125 reader->read_uint32 (reader, &reserved);
126 reader->destroy(reader);
127
128 return SUCCESS;
129 }
130
131 METHOD(pa_tnc_attr_t, destroy, void,
132 private_tcg_pts_attr_get_aik_t *this)
133 {
134 free(this->value.ptr);
135 free(this);
136 }
137
138 /**
139 * Described in header.
140 */
141 pa_tnc_attr_t *tcg_pts_attr_get_aik_create()
142 {
143 private_tcg_pts_attr_get_aik_t *this;
144
145 INIT(this,
146 .public = {
147 .pa_tnc_attribute = {
148 .get_vendor_id = _get_vendor_id,
149 .get_type = _get_type,
150 .get_value = _get_value,
151 .get_noskip_flag = _get_noskip_flag,
152 .set_noskip_flag = _set_noskip_flag,
153 .build = _build,
154 .process = _process,
155 .destroy = _destroy,
156 },
157 },
158 .vendor_id = PEN_TCG,
159 .type = TCG_PTS_GET_AIK,
160 );
161
162 return &this->public.pa_tnc_attribute;
163 }
164
165
166 /**
167 * Described in header.
168 */
169 pa_tnc_attr_t *tcg_pts_attr_get_aik_create_from_data(chunk_t data)
170 {
171 private_tcg_pts_attr_get_aik_t *this;
172
173 INIT(this,
174 .public = {
175 .pa_tnc_attribute = {
176 .get_vendor_id = _get_vendor_id,
177 .get_type = _get_type,
178 .get_value = _get_value,
179 .get_noskip_flag = _get_noskip_flag,
180 .set_noskip_flag = _set_noskip_flag,
181 .build = _build,
182 .process = _process,
183 .destroy = _destroy,
184 },
185 },
186 .vendor_id = PEN_TCG,
187 .type = TCG_PTS_GET_AIK,
188 .value = chunk_clone(data),
189 );
190
191 return &this->public.pa_tnc_attribute;
192 }