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