Annotation of embedaddon/strongswan/src/libtncif/tncif_identity.c, revision 1.1.1.1
1.1 misho 1: /*
2: * Copyright (C) 2013 Andreas Steffen
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 "tncif_identity.h"
17:
18: #include <bio/bio_writer.h>
19: #include <bio/bio_reader.h>
20: #include <pen/pen.h>
21: #include <utils/debug.h>
22:
23: typedef struct private_tncif_identity_t private_tncif_identity_t;
24:
25: /**
26: * TNC Identity List Attribute Format (TCG TNC IF-IMV 1.4 Draft)
27: *
28: * 1 2 3
29: * 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
30: * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
31: * | Identity Count |
32: * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33: * | RESERVED | Identity Type Vendor ID |
34: * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35: * | Identity Type |
36: * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37: * | Identity Value Length |
38: * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39: * | |
40: * ~ Identity Value ~
41: * | |
42: * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43: * | RESERVED | Subject Type Vendor ID |
44: * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45: * | Subject Type |
46: * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
47: * | RESERVED | Authentication Method Vendor ID |
48: * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
49: * | Authentication Method |
50: * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
51: */
52:
53: /**
54: * Private data of a tncif_identity_t object.
55: *
56: */
57: struct private_tncif_identity_t {
58:
59: /**
60: * Public tncif_identity_t interface.
61: */
62: tncif_identity_t public;
63:
64: /**
65: * Identity Type
66: */
67: pen_type_t identity_type;
68:
69: /**
70: * Identity Value
71: */
72: chunk_t identity_value;
73:
74: /**
75: * Subject Type
76: */
77: pen_type_t subject_type;
78:
79: /**
80: * Authentication Type
81: */
82: pen_type_t auth_type;
83: };
84:
85: METHOD(tncif_identity_t, get_identity_type, pen_type_t,
86: private_tncif_identity_t *this)
87: {
88: return this->identity_type;
89: }
90:
91: METHOD(tncif_identity_t, get_identity_value, chunk_t,
92: private_tncif_identity_t *this)
93: {
94: return this->identity_value;
95: }
96:
97: METHOD(tncif_identity_t, get_subject_type, pen_type_t,
98: private_tncif_identity_t *this)
99: {
100: return this->subject_type;
101: }
102:
103: METHOD(tncif_identity_t, get_auth_type, pen_type_t,
104: private_tncif_identity_t *this)
105: {
106: return this->auth_type;
107: }
108:
109: METHOD(tncif_identity_t, build, void,
110: private_tncif_identity_t *this, bio_writer_t *writer)
111: {
112: writer->write_uint32(writer, this->identity_type.vendor_id);
113: writer->write_uint32(writer, this->identity_type.type);
114: writer->write_data32(writer, this->identity_value);
115: writer->write_uint32(writer, this->subject_type.vendor_id);
116: writer->write_uint32(writer, this->subject_type.type);
117: writer->write_uint32(writer, this->auth_type.vendor_id);
118: writer->write_uint32(writer, this->auth_type.type);
119: }
120:
121: METHOD(tncif_identity_t, process, bool,
122: private_tncif_identity_t *this, bio_reader_t *reader)
123: {
124: uint8_t reserved;
125: uint32_t vendor_id, type;
126: chunk_t identity_value;
127:
128: if (reader->remaining(reader) < TNCIF_IDENTITY_MIN_SIZE)
129: {
130: return FALSE;
131: }
132: reader->read_uint8 (reader, &reserved);
133: reader->read_uint24(reader, &vendor_id);
134: reader->read_uint32(reader, &type);
135: this->identity_type = pen_type_create(vendor_id, type);
136:
137: if (!reader->read_data32(reader, &identity_value) ||
138: reader->remaining(reader) < 16)
139: {
140: return FALSE;
141: }
142: this->identity_value = chunk_clone(identity_value);
143:
144: reader->read_uint8 (reader, &reserved);
145: reader->read_uint24(reader, &vendor_id);
146: reader->read_uint32(reader, &type);
147: this->subject_type = pen_type_create(vendor_id, type);
148:
149: reader->read_uint8 (reader, &reserved);
150: reader->read_uint24(reader, &vendor_id);
151: reader->read_uint32(reader, &type);
152: this->auth_type = pen_type_create(vendor_id, type);
153:
154: return TRUE;
155: }
156:
157: METHOD(tncif_identity_t, destroy, void,
158: private_tncif_identity_t *this)
159: {
160: free(this->identity_value.ptr);
161: free(this);
162: }
163:
164:
165: /**
166: * See header
167: */
168: tncif_identity_t *tncif_identity_create_empty(void)
169: {
170: private_tncif_identity_t *this;
171:
172: INIT(this,
173: .public = {
174: .get_identity_type = _get_identity_type,
175: .get_identity_value = _get_identity_value,
176: .get_subject_type = _get_subject_type,
177: .get_auth_type = _get_auth_type,
178: .build = _build,
179: .process = _process,
180: .destroy = _destroy,
181: },
182: );
183:
184: return &this->public;
185: }
186:
187: /**
188: * See header
189: */
190: tncif_identity_t *tncif_identity_create(pen_type_t identity_type,
191: chunk_t identity_value,
192: pen_type_t subject_type,
193: pen_type_t auth_type)
194: {
195: private_tncif_identity_t *this;
196:
197: this = (private_tncif_identity_t*)tncif_identity_create_empty();
198: this->identity_type = identity_type;
199: this->identity_value = identity_value;
200: this->subject_type = subject_type;
201: this->auth_type = auth_type;
202:
203: return &this->public;
204: }
205:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>