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