- encryptino payload
[strongswan.git] / Source / charon / encoding / message.h
1 /**
2 * @file message.h
3 *
4 * @brief Class message_t. Object of this type represents an IKEv2-Message.
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 MESSAGE_H_
24 #define MESSAGE_H_
25
26 #include <types.h>
27 #include <sa/ike_sa_id.h>
28 #include <network/packet.h>
29 #include <encoding/payloads/ike_header.h>
30 #include <utils/linked_list.h>
31 #include <transforms/crypters/crypter.h>
32 #include <transforms/signers/signer.h>
33
34
35 typedef struct message_t message_t;
36
37 /**
38 * @brief This class is used to represent an IKEv2-Message.
39 *
40 * An IKEv2-Message is either a request or response.
41 */
42 struct message_t {
43
44 /**
45 * @brief Sets the IKE major version of the message.
46 *
47 * @param this message_t object
48 * @param major_version major version to set
49 * @return SUCCESS
50 */
51 status_t (*set_major_version) (message_t *this,u_int8_t major_version);
52
53 /**
54 * @brief Gets the IKE major version of the message.
55 *
56 * @param this message_t object
57 * @return major version of the message
58 */
59 u_int8_t (*get_major_version) (message_t *this);
60
61 /**
62 * @brief Sets the IKE minor version of the message.
63 *
64 * @param this message_t object
65 * @param minor_version minor version to set
66 * @return SUCCESS
67 */
68 status_t (*set_minor_version) (message_t *this,u_int8_t minor_version);
69
70 /**
71 * @brief Gets the IKE minor version of the message.
72 *
73 * @param this message_t object
74 * @return minor version of the message
75 */
76 u_int8_t (*get_minor_version) (message_t *this);
77
78 /**
79 * @brief Sets the Message ID of the message.
80 *
81 * @param this message_t object
82 * @param message_id message_id to set
83 * @return SUCCESS
84 */
85 status_t (*set_message_id) (message_t *this,u_int32_t message_id);
86
87 /**
88 * @brief Gets the Message ID of the message.
89 *
90 * @param this message_t object
91 * @return message_id type of the message
92 */
93 u_int32_t (*get_message_id) (message_t *this);
94
95 /**
96 * @brief Gets the responder SPI of the message.
97 *
98 * @param this message_t object
99 * @return responder spi of the message
100 */
101 u_int64_t (*get_responder_spi) (message_t *this);
102
103 /**
104 * @brief Sets the IKE_SA ID of the message.
105 *
106 * @warning ike_sa_id gets cloned internaly and
107 * so can be destroyed afterwards.
108 *
109 * @param this message_t object
110 * @param ike_sa_id ike_sa_id to set
111 * @return
112 * - SUCCESS
113 * - OUT_OF_RES
114 * @return SUCCESS
115 */
116 status_t (*set_ike_sa_id) (message_t *this,ike_sa_id_t * ike_sa_id);
117
118 /**
119 * @brief Gets the IKE_SA ID of the message.
120 *
121 * @warning The returned ike_sa_id is a clone of the internal one.
122 * So it has to be destroyed by the caller.
123 *
124 * @param this message_t object
125 * @param ike_sa_id pointer to ike_sa_id pointer which will be set
126 * @return
127 * - SUCCESS
128 * - OUT_OF_RES
129 * - FAILED if no ike_sa_id is set
130 */
131 status_t (*get_ike_sa_id) (message_t *this,ike_sa_id_t **ike_sa_id);
132
133 /**
134 * @brief Sets the exchange type of the message.
135 *
136 * @param this message_t object
137 * @param exchange_type exchange_type to set
138 * @return SUCCESS
139 */
140 status_t (*set_exchange_type) (message_t *this,exchange_type_t exchange_type);
141
142 /**
143 * @brief Gets the exchange type of the message.
144 *
145 * @param this message_t object
146 * @return exchange type of the message
147 */
148 exchange_type_t (*get_exchange_type) (message_t *this);
149
150 /**
151 * @brief Sets the original initiator flag.
152 *
153 * @param this message_t object
154 * @param original_initiator TRUE if message is from original initiator
155 * @return SUCCESS
156 */
157 status_t (*set_original_initiator) (message_t *this,bool original_initiator);
158
159 /**
160 * @brief Gets original initiator flag.
161 *
162 * @param this message_t object
163 * @return TRUE if message is from original initiator, FALSE otherwise
164 */
165 bool (*get_original_initiator) (message_t *this);
166
167 /**
168 * @brief Sets the request flag.
169 *
170 * @param this message_t object
171 * @param original_initiator TRUE if message is a request, FALSE if it is a reply
172 * @return SUCCESS
173 */
174 status_t (*set_request) (message_t *this,bool request);
175
176 /**
177 * @brief Gets request flag.
178 *
179 * @param this message_t object
180 * @return TRUE if message is a request, FALSE if it is a reply
181 */
182 bool (*get_request) (message_t *this);
183
184 /**
185 * @brief Append a payload to the message.
186 *
187 * @param this message_t object
188 * @param payload payload to append
189 * @return
190 * - SUCCESS or
191 * - OUT_OF_RES
192 */
193 status_t (*add_payload) (message_t *this, payload_t *payload);
194
195 /**
196 * @brief Parses header of message
197 *
198 * @param this message_t object
199 * @return
200 * - SUCCESS if header could be parsed
201 * - OUT_OF_RES if out of ressources
202 * - PARSE_ERROR if corrupted/invalid data found
203 * - FAILED if consistence check of header failed
204 */
205 status_t (*parse_header) (message_t *this);
206
207 /**
208 * @brief Parses body of message.
209 *
210 * The body gets not only parsed, but rather it gets verified.
211 * All payloads are verified if they are allowed to exist in the message
212 * of this type and if their own structure is ok.
213 *
214 * @param this message_t object
215 * @return
216 * - SUCCESS if header could be parsed
217 * - NOT_SUPPORTED if unsupported payload are contained in body
218 * - OUT_OF_RES if out of ressources
219 * - FAILED if message type is not suppported!
220 * - PARSE_ERROR if corrupted/invalid data found
221 * - VERIFY_ERROR if verification of some payload failed
222 */
223 status_t (*parse_body) (message_t *this, crypter_t *crypter, signer_t *signer);
224
225 /**
226 * @brief Generates the UDP packet of specific message
227 *
228 * @param this message_t object
229 * @return
230 * - SUCCESS if packet could be generated
231 * - EXCHANGE_TYPE_NOT_SET if exchange type is currently not set
232 * ....
233 */
234 status_t (*generate) (message_t *this, crypter_t *crypter, signer_t *signer, packet_t **packet);
235
236 status_t (*verify) (message_t *this);
237 status_t (*get_source) (message_t *this, host_t **host);
238 status_t (*set_source) (message_t *this, host_t *host);
239 status_t (*get_destination) (message_t *this, host_t **host);
240 status_t (*set_destination) (message_t *this, host_t *host);
241 status_t (*get_payload_iterator) (message_t *this, iterator_t **iterator);
242
243 /**
244 * @brief Destroys a message and all including objects
245 *
246 * @param this message_t object
247 * @return SUCCESS
248 */
249 status_t (*destroy) (message_t *this);
250 };
251
252 /**
253 * Creates an message_t object from a incoming UDP Packet.
254 *
255 * @warning the given packet_t object is not copied and gets
256 * destroyed in message_t's destroy call.
257 *
258 * @warning Packet is not parsed in here!
259 *
260 * - exchange_type is set to NOT_SET
261 * - original_initiator is set to TRUE
262 * - is_request is set to TRUE
263 *
264 * @param packet packet_t object which is assigned to message
265 *
266 * @return
267 * - created message_t object
268 * - NULL if out of ressources
269 */
270 message_t * message_create_from_packet(packet_t *packet);
271
272
273 /**
274 * Creates an empty message_t object.
275 *
276 * - exchange_type is set to NOT_SET
277 * - original_initiator is set to TRUE
278 * - is_request is set to TRUE
279 *
280 * @return
281 * - created message_t object
282 * - NULL if out of ressources
283 */
284 message_t * message_create();
285
286 #endif /*MESSAGE_H_*/