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_dh_nonce_params_req.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_dh_nonce_params_req_t private_tcg_pts_attr_dh_nonce_params_req_t
;
26 * PTS DH Nonce Parameters Request
27 * see section 3.8.1 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 * | Reserved | Min. Nonce Len | D-H Group Set |
33 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 #define PTS_DH_NONCE_PARAMS_REQ_SIZE 4
38 #define PTS_DH_NONCE_PARAMS_REQ_RESERVED 0x00
41 * Private data of an tcg_pts_attr_dh_nonce_params_req_t object.
43 struct private_tcg_pts_attr_dh_nonce_params_req_t
{
46 * Public members of tcg_pts_attr_dh_nonce_params_req_t
48 tcg_pts_attr_dh_nonce_params_req_t
public;
71 * Minimum acceptable length of nonce
73 u_int8_t min_nonce_len
;
76 * Diffie Hellman group set
78 pts_dh_group_t dh_groups
;
82 METHOD(pa_tnc_attr_t
, get_vendor_id
, pen_t
,
83 private_tcg_pts_attr_dh_nonce_params_req_t
*this)
85 return this->vendor_id
;
88 METHOD(pa_tnc_attr_t
, get_type
, u_int32_t
,
89 private_tcg_pts_attr_dh_nonce_params_req_t
*this)
94 METHOD(pa_tnc_attr_t
, get_value
, chunk_t
,
95 private_tcg_pts_attr_dh_nonce_params_req_t
*this)
100 METHOD(pa_tnc_attr_t
, get_noskip_flag
, bool,
101 private_tcg_pts_attr_dh_nonce_params_req_t
*this)
103 return this->noskip_flag
;
106 METHOD(pa_tnc_attr_t
, set_noskip_flag
,void,
107 private_tcg_pts_attr_dh_nonce_params_req_t
*this, bool noskip
)
109 this->noskip_flag
= noskip
;
112 METHOD(pa_tnc_attr_t
, build
, void,
113 private_tcg_pts_attr_dh_nonce_params_req_t
*this)
115 bio_writer_t
*writer
;
117 writer
= bio_writer_create(PTS_DH_NONCE_PARAMS_REQ_SIZE
);
118 writer
->write_uint8(writer
, PTS_DH_NONCE_PARAMS_REQ_RESERVED
);
119 writer
->write_uint8(writer
, this->min_nonce_len
);
120 writer
->write_uint8(writer
, this->dh_groups
);
122 this->value
= chunk_clone(writer
->get_buf(writer
));
123 writer
->destroy(writer
);
126 METHOD(pa_tnc_attr_t
, process
, status_t
,
127 private_tcg_pts_attr_dh_nonce_params_req_t
*this, u_int32_t
*offset
)
129 bio_reader_t
*reader
;
133 if (this->value
.len
< PTS_DH_NONCE_PARAMS_REQ_SIZE
)
135 DBG1(DBG_TNC
, "insufficient data for PTS DH Nonce Parameters Request");
139 reader
= bio_reader_create(this->value
);
140 reader
->read_uint8(reader
, &reserved
);
141 reader
->read_uint8(reader
, &this->min_nonce_len
);
142 reader
->read_uint16(reader
, &dh_groups
);
143 this->dh_groups
= dh_groups
;
144 reader
->destroy(reader
);
149 METHOD(pa_tnc_attr_t
, destroy
, void,
150 private_tcg_pts_attr_dh_nonce_params_req_t
*this)
152 free(this->value
.ptr
);
156 METHOD(tcg_pts_attr_dh_nonce_params_req_t
, get_min_nonce_len
, u_int8_t
,
157 private_tcg_pts_attr_dh_nonce_params_req_t
*this)
159 return this->min_nonce_len
;
162 METHOD(tcg_pts_attr_dh_nonce_params_req_t
, get_dh_groups
, pts_dh_group_t
,
163 private_tcg_pts_attr_dh_nonce_params_req_t
*this)
165 return this->dh_groups
;
169 * Described in header.
171 pa_tnc_attr_t
*tcg_pts_attr_dh_nonce_params_req_create(u_int8_t min_nonce_len
,
172 pts_dh_group_t dh_groups
)
174 private_tcg_pts_attr_dh_nonce_params_req_t
*this;
178 .pa_tnc_attribute
= {
179 .get_vendor_id
= _get_vendor_id
,
180 .get_type
= _get_type
,
181 .get_value
= _get_value
,
182 .get_noskip_flag
= _get_noskip_flag
,
183 .set_noskip_flag
= _set_noskip_flag
,
188 .get_min_nonce_len
= _get_min_nonce_len
,
189 .get_dh_groups
= _get_dh_groups
,
191 .vendor_id
= PEN_TCG
,
192 .type
= TCG_PTS_DH_NONCE_PARAMS_REQ
,
193 .min_nonce_len
= min_nonce_len
,
194 .dh_groups
= dh_groups
,
197 return &this->public.pa_tnc_attribute
;
201 * Described in header.
203 pa_tnc_attr_t
*tcg_pts_attr_dh_nonce_params_req_create_from_data(chunk_t value
)
205 private_tcg_pts_attr_dh_nonce_params_req_t
*this;
209 .pa_tnc_attribute
= {
210 .get_vendor_id
= _get_vendor_id
,
211 .get_type
= _get_type
,
212 .get_value
= _get_value
,
213 .get_noskip_flag
= _get_noskip_flag
,
214 .set_noskip_flag
= _set_noskip_flag
,
219 .get_min_nonce_len
= _get_min_nonce_len
,
220 .get_dh_groups
= _get_dh_groups
,
222 .vendor_id
= PEN_TCG
,
223 .type
= TCG_PTS_DH_NONCE_PARAMS_REQ
,
224 .value
= chunk_clone(value
),
227 return &this->public.pa_tnc_attribute
;