- implemented and tested cert_payload_t
[strongswan.git] / Source / charon / encoding / payloads / encodings.h
1 /**
2 * @file encodings.h
3 *
4 * @brief Encoding types of fields in a IKEv2 payload.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #ifndef ENCODINGS_H_
24 #define ENCODINGS_H_
25
26 #include <types.h>
27 #include <definitions.h>
28
29
30 typedef enum encoding_type_t encoding_type_t;
31
32 /**
33 * @brief All different kinds of encoding types.
34 *
35 * Each field of an IKEv2-Message (in header or payload)
36 * which has to be parsed or generated differently has its own
37 * type defined here.
38 *
39 * Header is parsed like a payload and gets its one payload_id
40 * from PRIVATE USE space. Also the substructures
41 * of specific payload types get their own payload_id
42 * from PRIVATE_USE space. See IKEv2-Draft for more informations.
43 *
44 * @ingroup payloads
45 */
46 enum encoding_type_t{
47 /**
48 * Representing a 4 Bit unsigned int value.
49 *
50 *
51 * When generating it must be changed from host to network order.
52 * The value is read from the associated data struct.
53 * The current write position is moved 4 bit forward afterwards.
54 *
55 * When parsing it must be changed from network to host order.
56 * The value is written to the associated data struct.
57 * The current read pointer is moved 4 bit forward afterwards.
58 */
59 U_INT_4,
60 /**
61 * Representing a 8 Bit unsigned int value.
62 *
63 *
64 * When generating it must be changed from host to network order.
65 * The value is read from the associated data struct.
66 * The current write position is moved 8 bit forward afterwards.
67 *
68 * When parsing it must be changed from network to host order.
69 * The value is written to the associated data struct.
70 * The current read pointer is moved 8 bit forward afterwards.
71 */
72 U_INT_8,
73 /**
74 * Representing a 16 Bit unsigned int value.
75 *
76 *
77 * When generating it must be changed from host to network order.
78 * The value is read from the associated data struct.
79 * The current write position is moved 16 bit forward afterwards.
80 *
81 * When parsing it must be changed from network to host order.
82 * The value is written to the associated data struct.
83 * The current read pointer is moved 16 bit forward afterwards.
84 */
85 U_INT_16,
86 /**
87 * Representing a 32 Bit unsigned int value.
88 *
89 * When generating it must be changed from host to network order.
90 * The value is read from the associated data struct.
91 * The current write position is moved 32 bit forward afterwards.
92 *
93 * When parsing it must be changed from network to host order.
94 * The value is written to the associated data struct.
95 * The current read pointer is moved 32 bit forward afterwards.
96 */
97
98 U_INT_32,
99 /**
100 * Representing a 64 Bit unsigned int value.
101 *
102 * When generating it must be changed from host to network order.
103 * The value is read from the associated data struct.
104 * The current write position is moved 64 bit forward afterwards.
105 *
106 * When parsing it must be changed from network to host order.
107 * The value is written to the associated data struct.
108 * The current read pointer is moved 64 bit forward afterwards.
109 */
110 U_INT_64,
111 /**
112 * @brief represents a RESERVED_BIT used in FLAG-Bytes.
113 *
114 * When generating, the next bit is set to zero and the current write
115 * position is moved one bit forward.
116 * No value is read from the associated data struct.
117 * The current write position is moved 1 bit forward afterwards.
118 *
119 * When parsing, the current read pointer is moved one bit forward.
120 * No value is written to the associated data struct.
121 * The current read pointer is moved 1 bit forward afterwards.
122 */
123 RESERVED_BIT,
124 /**
125 * @brief represents a RESERVED_BYTE.
126 *
127 * When generating, the next byte is set to zero and the current write
128 * position is moved one byte forward.
129 * No value is read from the associated data struct.
130 * The current write position is moved 1 byte forward afterwards.
131 *
132 * When parsing, the current read pointer is moved one byte forward.
133 * No value is written to the associated data struct.
134 * The current read pointer is moved 1 byte forward afterwards.
135 */
136 RESERVED_BYTE,
137 /**
138 * Representing a 1 Bit flag.
139 *
140 * When generation, the next bit is set to 1 if the associated value
141 * in the data struct is TRUE, 0 otherwise. The current write position
142 * is moved 1 bit forward afterwards.
143 *
144 * When parsing, the next bit is read and stored in the associated data
145 * struct. 0 means FALSE, 1 means TRUE, The current read pointer
146 * is moved 1 bit forward afterwards
147 */
148 FLAG,
149 /**
150 * Representating a length field of a payload.
151 *
152 * When generating it must be changed from host to network order.
153 * The value is read from the associated data struct.
154 * The current write position is moved 16 bit forward afterwards.
155 *
156 * When parsing it must be changed from network to host order.
157 * The value is written to the associated data struct.
158 * The current read pointer is moved 16 bit forward afterwards.
159 */
160 PAYLOAD_LENGTH,
161 /**
162 * Representating a length field of a header.
163 *
164 * When generating it must be changed from host to network order.
165 * The value is read from the associated data struct.
166 * The current write position is moved 32 bit forward afterwards.
167 *
168 * When parsing it must be changed from network to host order.
169 * The value is written to the associated data struct.
170 * The current read pointer is moved 32 bit forward afterwards.
171 */
172 HEADER_LENGTH,
173 /**
174 * Representating a spi size field.
175 *
176 * When generating it must be changed from host to network order.
177 * The value is read from the associated data struct.
178 * The current write position is moved 8 bit forward afterwards.
179 *
180 * When parsing it must be changed from network to host order.
181 * The value is written to the associated data struct.
182 * The current read pointer is moved 8 bit forward afterwards.
183 */
184 SPI_SIZE,
185 /**
186 * Representating a spi field.
187 *
188 * When generating the content of the chunkt pointing to
189 * is written.
190 *
191 * When parsing SPI_SIZE bytes are read and written into the chunk pointing to.
192 */
193 SPI,
194 /**
195 * Representating a Key Exchange Data field.
196 *
197 * When generating the content of the chunkt pointing to
198 * is written.
199 *
200 * When parsing (Payload Length - 8) bytes are read and written into the chunk pointing to.
201 */
202 KEY_EXCHANGE_DATA,
203 /**
204 * Representating a Notification field.
205 *
206 * When generating the content of the chunkt pointing to
207 * is written.
208 *
209 * When parsing (Payload Length - spi size - 8) bytes are read and written into the chunk pointing to.
210 */
211 NOTIFICATION_DATA,
212 /**
213 * Representating one or more proposal substructures.
214 *
215 * The offset points to a linked_list_t pointer.
216 *
217 * When generating the proposal_substructure_t objects are stored
218 * in the pointed linked_list.
219 *
220 * When parsing the parsed proposal_substructure_t objects have
221 * to be stored in the pointed linked_list.
222 */
223 PROPOSALS,
224 /**
225 * Representating one or more transform substructures.
226 *
227 * The offset points to a linked_list_t pointer.
228 *
229 * When generating the transform_substructure_t objects are stored
230 * in the pointed linked_list.
231 *
232 * When parsing the parsed transform_substructure_t objects have
233 * to be stored in the pointed linked_list.
234 */
235 TRANSFORMS,
236 /**
237 * Representating one or more Attributes of a transform substructure.
238 *
239 * The offset points to a linked_list_t pointer.
240 *
241 * When generating the transform_attribute_t objects are stored
242 * in the pointed linked_list.
243 *
244 * When parsing the parsed transform_attribute_t objects have
245 * to be stored in the pointed linked_list.
246 */
247 TRANSFORM_ATTRIBUTES,
248 /**
249 * Representing a 1 Bit flag specifying the format of a transform attribute.
250 *
251 * When generation, the next bit is set to 1 if the associated value
252 * in the data struct is TRUE, 0 otherwise. The current write position
253 * is moved 1 bit forward afterwards.
254 *
255 * When parsing, the next bit is read and stored in the associated data
256 * struct. 0 means FALSE, 1 means TRUE, The current read pointer
257 * is moved 1 bit forward afterwards.
258 */
259 ATTRIBUTE_FORMAT,
260 /**
261 * Representing a 15 Bit unsigned int value used as attribute type
262 * in an attribute transform.
263 *
264 *
265 * When generating it must be changed from host to network order.
266 * The value is read from the associated data struct.
267 * The current write position is moved 15 bit forward afterwards.
268 *
269 * When parsing it must be changed from network to host order.
270 * The value is written to the associated data struct.
271 * The current read pointer is moved 15 bit forward afterwards.
272 */
273 ATTRIBUTE_TYPE,
274
275 /**
276 * Depending on the field of type ATTRIBUTE_FORMAT
277 * this field contains the length or the value of an transform attribute.
278 * Its stored in a 16 unsigned integer field.
279 *
280 * When generating it must be changed from host to network order.
281 * The value is read from the associated data struct.
282 * The current write position is moved 16 bit forward afterwards.
283 *
284 * When parsing it must be changed from network to host order.
285 * The value is written to the associated data struct.
286 * The current read pointer is moved 16 bit forward afterwards.
287 */
288 ATTRIBUTE_LENGTH_OR_VALUE,
289
290 /**
291 * Depending on the field of type ATTRIBUTE_FORMAT
292 * this field is available or missing and so parsed/generated
293 * or not parsed/not generated.
294 *
295 * When generating the content of the chunkt pointing to
296 * is written.
297 *
298 * When parsing SPI_SIZE bytes are read and written into the chunk pointing to.
299 */
300 ATTRIBUTE_VALUE,
301
302 /**
303 * Representating one or more Traffic selectors of a TS payload.
304 *
305 * The offset points to a linked_list_t pointer.
306 *
307 * When generating the traffic_selector_substructure_t objects are stored
308 * in the pointed linked_list.
309 *
310 * When parsing the parsed traffic_selector_substructure_t objects have
311 * to be stored in the pointed linked_list.
312 */
313 TRAFFIC_SELECTORS,
314
315 /**
316 * Representating a Traffic selector type field.
317 *
318 * When generating it must be changed from host to network order.
319 * The value is read from the associated data struct.
320 * The current write position is moved 16 bit forward afterwards.
321 *
322 * When parsing it must be changed from network to host order.
323 * The value is written to the associated data struct.
324 * The current read pointer is moved 16 bit forward afterwards.
325 */
326 TS_TYPE,
327
328 /**
329 * Representating an address field in a traffic selector.
330 *
331 * Depending on the last field of type TS_TYPE
332 * this field is either 4 or 16 byte long.
333 *
334 * When generating the content of the chunkt pointing to
335 * is written.
336 *
337 * When parsing 4 or 16 bytes are read and written into the chunk pointing to.
338 */
339 ADDRESS,
340
341 /**
342 * Representating a Nonce Data field.
343 *
344 * When generating the content of the chunkt pointing to
345 * is written.
346 *
347 * When parsing (Payload Length - 4) bytes are read and written into the chunk pointing to.
348 */
349 NONCE_DATA,
350
351 /**
352 * Representating a ID Data field.
353 *
354 * When generating the content of the chunkt pointing to
355 * is written.
356 *
357 * When parsing (Payload Length - 8) bytes are read and written into the chunk pointing to.
358 */
359 ID_DATA,
360
361 /**
362 * Representating a AUTH Data field.
363 *
364 * When generating the content of the chunkt pointing to
365 * is written.
366 *
367 * When parsing (Payload Length - 8) bytes are read and written into the chunk pointing to.
368 */
369 AUTH_DATA,
370
371 /**
372 * Representating a CERT Data field.
373 *
374 * When generating the content of the chunkt pointing to
375 * is written.
376 *
377 * When parsing (Payload Length - 5) bytes are read and written into the chunk pointing to.
378 */
379 CERT_DATA,
380
381 /**
382 * Representating a CERTREQ Data field.
383 *
384 * When generating the content of the chunkt pointing to
385 * is written.
386 *
387 * When parsing (Payload Length - 5) bytes are read and written into the chunk pointing to.
388 */
389 CERTREQ_DATA,
390
391 /**
392 * Representating an IKE_SPI field in an IKEv2 Header.
393 *
394 * When generating the value of the u_int64_t pointing to
395 * is written (host and networ order is not changed).
396 *
397 * When parsing 8 bytes are read and written into the u_int64_t pointing to.
398 */
399 IKE_SPI,
400
401 /**
402 * Representing the encrypted data body of a encryption payload.
403 */
404 ENCRYPTED_DATA,
405
406 };
407
408 /**
409 * mappings to map encoding_type_t's to strings
410 */
411 extern mapping_t encoding_type_m[];
412
413 typedef struct encoding_rule_t encoding_rule_t;
414
415 /**
416 * An encoding rule is a mapping of a specific encoding type to
417 * a location in the data struct where the current field is stored to
418 * or read from.
419 *
420 * For examples see files in this directory.
421 *
422 * This rules are used by parser and generator.
423 *
424 * @ingroup payloads
425 */
426 struct encoding_rule_t {
427 /**
428 * Encoding type.
429 */
430 encoding_type_t type;
431
432 /**
433 * Offset in the data struct.
434 *
435 * When parsing, data are written to this offset of the
436 * data struct.
437 *
438 * When generating, data are read from this offset in the
439 * data struct.
440 */
441 u_int32_t offset;
442 };
443
444 #endif /*ENCODINGS_H_*/