]> git.ipfire.org Git - thirdparty/strongswan.git/blame - src/libpts/tcg/tcg_pts_attr_gen_attest_evid.c
Moved debug.[ch] to utils folder
[thirdparty/strongswan.git] / src / libpts / tcg / tcg_pts_attr_gen_attest_evid.c
CommitLineData
cbb79252 1/*
dbb7859f 2 * Copyright (C) 2011-2012 Sansar Choinyambuu, Andreas Steffen
cbb79252
SC
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_gen_attest_evid.h"
17
18#include <pa_tnc/pa_tnc_msg.h>
19#include <bio/bio_writer.h>
20#include <bio/bio_reader.h>
f05b4272 21#include <utils/debug.h>
cbb79252 22
b8017b5e
SC
23typedef struct private_tcg_pts_attr_gen_attest_evid_t
24 private_tcg_pts_attr_gen_attest_evid_t;
cbb79252
SC
25
26/**
13e708b0
AS
27 * Generate Attestation Evidence
28 * see section 3.14.2 of PTS Protocol: Binding to TNC IF-M Specification
cbb79252 29 *
05a1b347 30 * 1 2 3
cbb79252
SC
31 * 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
32 *
33 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
05a1b347 34 * | Reserved |
cbb79252 35 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
f05b4272 36 *
cbb79252
SC
37 */
38
39#define PTS_GEN_ATTEST_EVID_SIZE 4
13e708b0 40#define PTS_GEN_ATTEST_EVID_RESERVED 0x00
cbb79252
SC
41
42/**
43 * Private data of an tcg_pts_attr_gen_attest_evid_t object.
44 */
45struct private_tcg_pts_attr_gen_attest_evid_t {
46
47 /**
48 * Public members of tcg_pts_attr_gen_attest_evid_t
49 */
50 tcg_pts_attr_gen_attest_evid_t public;
51
52 /**
dbb7859f 53 * Vendor-specific attribute type
cbb79252 54 */
dbb7859f 55 pen_type_t type;
cbb79252
SC
56
57 /**
58 * Attribute value
59 */
60 chunk_t value;
61
62 /**
63 * Noskip flag
64 */
65 bool noskip_flag;
8982b702
AS
66
67 /**
68 * Reference count
69 */
70 refcount_t ref;
cbb79252
SC
71};
72
dbb7859f 73METHOD(pa_tnc_attr_t, get_type, pen_type_t,
cbb79252
SC
74 private_tcg_pts_attr_gen_attest_evid_t *this)
75{
76 return this->type;
77}
78
79METHOD(pa_tnc_attr_t, get_value, chunk_t,
80 private_tcg_pts_attr_gen_attest_evid_t *this)
81{
82 return this->value;
83}
84
85METHOD(pa_tnc_attr_t, get_noskip_flag, bool,
86 private_tcg_pts_attr_gen_attest_evid_t *this)
87{
88 return this->noskip_flag;
89}
90
91METHOD(pa_tnc_attr_t, set_noskip_flag,void,
92 private_tcg_pts_attr_gen_attest_evid_t *this, bool noskip)
93{
94 this->noskip_flag = noskip;
95}
96
97METHOD(pa_tnc_attr_t, build, void,
98 private_tcg_pts_attr_gen_attest_evid_t *this)
99{
100 bio_writer_t *writer;
101
ea67a75b
AS
102 if (this->value.ptr)
103 {
104 return;
105 }
cbb79252
SC
106 writer = bio_writer_create(PTS_GEN_ATTEST_EVID_SIZE);
107 writer->write_uint32 (writer, PTS_GEN_ATTEST_EVID_RESERVED);
108
109 this->value = chunk_clone(writer->get_buf(writer));
110 writer->destroy(writer);
111}
112
113METHOD(pa_tnc_attr_t, process, status_t,
114 private_tcg_pts_attr_gen_attest_evid_t *this, u_int32_t *offset)
115{
116 bio_reader_t *reader;
117 u_int32_t reserved;
f05b4272 118
cbb79252
SC
119 if (this->value.len < PTS_GEN_ATTEST_EVID_SIZE)
120 {
121 DBG1(DBG_TNC, "insufficient data for Generate Attestation Evidence");
122 *offset = 0;
123 return FAILED;
124 }
125 reader = bio_reader_create(this->value);
126 reader->read_uint32 (reader, &reserved);
127 reader->destroy(reader);
128
05a1b347 129 return SUCCESS;
cbb79252
SC
130}
131
8982b702
AS
132METHOD(pa_tnc_attr_t, get_ref, pa_tnc_attr_t*,
133 private_tcg_pts_attr_gen_attest_evid_t *this)
134{
135 ref_get(&this->ref);
136 return &this->public.pa_tnc_attribute;
137}
138
cbb79252
SC
139METHOD(pa_tnc_attr_t, destroy, void,
140 private_tcg_pts_attr_gen_attest_evid_t *this)
141{
8982b702
AS
142 if (ref_put(&this->ref))
143 {
144 free(this->value.ptr);
145 free(this);
146 }
cbb79252
SC
147}
148
149/**
150 * Described in header.
151 */
152pa_tnc_attr_t *tcg_pts_attr_gen_attest_evid_create()
153{
154 private_tcg_pts_attr_gen_attest_evid_t *this;
155
156 INIT(this,
157 .public = {
158 .pa_tnc_attribute = {
cbb79252
SC
159 .get_type = _get_type,
160 .get_value = _get_value,
161 .get_noskip_flag = _get_noskip_flag,
162 .set_noskip_flag = _set_noskip_flag,
163 .build = _build,
164 .process = _process,
8982b702 165 .get_ref = _get_ref,
cbb79252
SC
166 .destroy = _destroy,
167 },
168 },
dbb7859f 169 .type = { PEN_TCG, TCG_PTS_GEN_ATTEST_EVID },
8982b702 170 .ref = 1,
cbb79252
SC
171 );
172
173 return &this->public.pa_tnc_attribute;
174}
175
176
177/**
178 * Described in header.
179 */
180pa_tnc_attr_t *tcg_pts_attr_gen_attest_evid_create_from_data(chunk_t data)
181{
182 private_tcg_pts_attr_gen_attest_evid_t *this;
183
184 INIT(this,
185 .public = {
186 .pa_tnc_attribute = {
cbb79252
SC
187 .get_type = _get_type,
188 .get_value = _get_value,
189 .get_noskip_flag = _get_noskip_flag,
190 .set_noskip_flag = _set_noskip_flag,
191 .build = _build,
192 .process = _process,
8982b702 193 .get_ref = _get_ref,
cbb79252
SC
194 .destroy = _destroy,
195 },
196 },
dbb7859f 197 .type = { PEN_TCG, TCG_PTS_GEN_ATTEST_EVID },
cbb79252 198 .value = chunk_clone(data),
8982b702 199 .ref = 1,
cbb79252
SC
200 );
201
202 return &this->public.pa_tnc_attribute;
203}