4 * @brief Interface of message_t.
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
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>.
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
27 #include <sa/ike_sa_id.h>
28 #include <network/packet.h>
29 #include <encoding/payloads/ike_header.h>
30 #include <encoding/payloads/notify_payload.h>
31 #include <utils/linked_list.h>
32 #include <crypto/crypters/crypter.h>
33 #include <crypto/signers/signer.h>
36 typedef struct message_t message_t
;
39 * @brief This class is used to represent an IKEv2-Message.
41 * The message handles parsing and generation of payloads
42 * via parser_t/generator_t. Encryption is done transparently
43 * via the encryption_payload_t. A set of rules for messages
44 * and payloads does check parsed messages.
48 * - message_create_from_packet()
49 * - message_create_notify_reply()
56 * @brief Sets the IKE major version of the message.
58 * @param this message_t object
59 * @param major_version major version to set
61 void (*set_major_version
) (message_t
*this,u_int8_t major_version
);
64 * @brief Gets the IKE major version of the message.
66 * @param this message_t object
67 * @return major version of the message
69 u_int8_t (*get_major_version
) (message_t
*this);
72 * @brief Sets the IKE minor version of the message.
74 * @param this message_t object
75 * @param minor_version minor version to set
77 void (*set_minor_version
) (message_t
*this,u_int8_t minor_version
);
80 * @brief Gets the IKE minor version of the message.
82 * @param this message_t object
83 * @return minor version of the message
85 u_int8_t (*get_minor_version
) (message_t
*this);
88 * @brief Sets the Message ID of the message.
90 * @param this message_t object
91 * @param message_id message_id to set
93 void (*set_message_id
) (message_t
*this,u_int32_t message_id
);
96 * @brief Gets the Message ID of the message.
98 * @param this message_t object
99 * @return message_id type of the message
101 u_int32_t (*get_message_id
) (message_t
*this);
104 * @brief Gets the responder SPI of the message.
106 * @param this message_t object
107 * @return responder spi of the message
109 u_int64_t (*get_responder_spi
) (message_t
*this);
112 * @brief Sets the IKE_SA ID of the message.
114 * @warning ike_sa_id gets cloned internaly and
115 * so can be destroyed afterwards.
117 * @param this message_t object
118 * @param ike_sa_id ike_sa_id to set
120 void (*set_ike_sa_id
) (message_t
*this,ike_sa_id_t
* ike_sa_id
);
123 * @brief Gets the IKE_SA ID of the message.
125 * @warning The returned ike_sa_id is a clone of the internal one.
126 * So it has to be destroyed by the caller.
128 * @param this message_t object
129 * @param ike_sa_id pointer to ike_sa_id pointer which will be set
132 * - FAILED if no ike_sa_id is set
134 status_t (*get_ike_sa_id
) (message_t
*this,ike_sa_id_t
**ike_sa_id
);
137 * @brief Sets the exchange type of the message.
139 * @param this message_t object
140 * @param exchange_type exchange_type to set
142 void (*set_exchange_type
) (message_t
*this,exchange_type_t exchange_type
);
145 * @brief Gets the exchange type of the message.
147 * @param this message_t object
148 * @return exchange type of the message
150 exchange_type_t (*get_exchange_type
) (message_t
*this);
153 * @brief Sets the request flag.
155 * @param this message_t object
156 * @param original_initiator TRUE if message is a request, FALSE if it is a reply
158 void (*set_request
) (message_t
*this,bool request
);
161 * @brief Gets request flag.
163 * @param this message_t object
164 * @return TRUE if message is a request, FALSE if it is a reply
166 bool (*get_request
) (message_t
*this);
169 * @brief Append a payload to the message.
171 * If the payload must be encrypted is not specified here. Encryption
172 * of payloads is evaluated via internal rules for the messages and
173 * is done before generation. The order of payloads may change, since
174 * all payloads to encrypt are added to the encryption payload, which is
175 * always the last one.
177 * @param this message_t object
178 * @param payload payload to append
180 void (*add_payload
) (message_t
*this, payload_t
*payload
);
183 * @brief Parses header of message.
185 * Begins parisng of a message created via message_create_from_packet().
186 * The parsing context is stored, so a subsequent call to parse_body()
187 * will continue the parsing process.
189 * @param this message_t object
191 * - SUCCESS if header could be parsed
192 * - PARSE_ERROR if corrupted/invalid data found
193 * - FAILED if consistence check of header failed
195 status_t (*parse_header
) (message_t
*this);
198 * @brief Parses body of message.
200 * The body gets not only parsed, but rather it gets verified.
201 * All payloads are verified if they are allowed to exist in the message
202 * of this type and if their own structure is ok.
203 * If there are encrypted payloads, they get decrypted via the supplied
204 * crypter. Also the message integrity gets verified with the supplied
206 * Crypter/signer can be omitted (by passing NULL) when no encryption
207 * payload is expected.
209 * @param this message_t object
210 * @param crypter crypter to decrypt encryption payloads
211 * @param signer signer to verifiy a message with an encryption payload
213 * - SUCCESS if header could be parsed
214 * - NOT_SUPPORTED if ciritcal unknown payloads found
215 * - FAILED if message type is not suppported!
216 * - PARSE_ERROR if corrupted/invalid data found
217 * - VERIFY_ERROR if verification of some payload failed
218 * - INVALID_STATE if crypter/signer not supplied, but needed
220 status_t (*parse_body
) (message_t
*this, crypter_t
*crypter
, signer_t
*signer
);
223 * @brief Generates the UDP packet of specific message.
225 * Payloads which must be encrypted are generated first and added to
226 * an encryption payload. This encryption payload will get encrypted via
227 * the supplied crypter. Then all other payloads and the header get generated.
228 * After that, the checksum is added to the encryption payload over the full
230 * Crypter/signer can be omitted (by passing NULL) when no encryption
231 * payload is expected.
233 * @param this message_t object
234 * @param crypter crypter to use when a payload must be encrypted
235 * @param signer signer to build a mac
237 * - SUCCESS if packet could be generated
238 * - INVALID_STATE if exchange type is currently not set
239 * - NOT_FOUND if no rules found for message generation
240 * - INVALID_STATE if crypter/signer not supplied but needed.
242 status_t (*generate
) (message_t
*this, crypter_t
*crypter
, signer_t
*signer
, packet_t
**packet
);
245 * @brief Gets the source host informations.
247 * @warning Returned host_t object is not getting cloned,
248 * do not destroy nor modify.
250 * @param this message_t object
251 * @return host_t object representing source host
253 host_t
* (*get_source
) (message_t
*this);
256 * @brief Sets the source host informations.
258 * @warning host_t object is not getting cloned and gets destroyed by
259 * message_t.destroy or next call of message_t.set_source.
261 * @param this message_t object
262 * @param host host_t object representing source host
264 void (*set_source
) (message_t
*this, host_t
*host
);
267 * @brief Gets the destination host informations.
269 * @warning Returned host_t object is not getting cloned,
270 * do not destroy nor modify.
272 * @param this message_t object
273 * @return host_t object representing destination host
275 host_t
* (*get_destination
) (message_t
*this);
278 * @brief Sets the destination host informations.
280 * @warning host_t object is not getting cloned and gets destroyed by
281 * message_t.destroy or next call of message_t.set_destination.
283 * @param this message_t object
284 * @param host host_t object representing destination host
286 void (*set_destination
) (message_t
*this, host_t
*host
);
289 * @brief Returns an iterator on all stored payloads.
291 * @warning Don't insert payloads over this iterator.
292 * Use add_payload() instead.
294 * @param this message_t object
295 * @return iterator_t object which has to get destroyd by the caller
297 iterator_t
* (*get_payload_iterator
) (message_t
*this);
300 * Returns a clone of the internal stored packet_t object.
302 * @param this message_t object
303 * @return packet_t object as clone of internal one
305 packet_t
* (*get_packet
) (message_t
*this);
308 * Returns a clone of the internal stored packet_t data.
310 * @param this message_t object
311 * @return clone of the internal stored packet_t data.
313 chunk_t (*get_packet_data
) (message_t
*this);
317 * @brief Destroys a message and all including objects.
319 * @param this message_t object
321 void (*destroy
) (message_t
*this);
325 * @brief Creates an message_t object from a incoming UDP Packet.
327 * @warning the given packet_t object is not copied and gets
328 * destroyed in message_t's destroy call.
330 * @warning Packet is not parsed in here!
332 * - exchange_type is set to NOT_SET
333 * - original_initiator is set to TRUE
334 * - is_request is set to TRUE
335 * Call message_t.parse_header afterwards.
337 * @param packet packet_t object which is assigned to message
338 * @return message_t object
342 message_t
* message_create_from_packet(packet_t
*packet
);
346 * @brief Creates an empty message_t object.
348 * - exchange_type is set to NOT_SET
349 * - original_initiator is set to TRUE
350 * - is_request is set to TRUE
352 * @return message_t object
356 message_t
* message_create(void);
359 * @brief Creates an message_t object of type reply containing a notify payload.
361 * @return message_t object
365 message_t
*message_create_notify_reply(host_t
*source
, host_t
*destination
, exchange_type_t exchange_type
, bool original_initiator
,ike_sa_id_t
*ike_sa_id
,notify_message_type_t notify_type
);
367 #endif /*MESSAGE_H_*/