aboutsummaryrefslogtreecommitdiffstats
path: root/Source/charon/encoding/message.h
blob: 68558d575ae46797b3b977f389c3039cb7abb652 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/**
 * @file message.h
 *
 * @brief Interface of message_t.
 *
 */

/*
 * Copyright (C) 2005 Jan Hutter, Martin Willi
 * Hochschule fuer Technik Rapperswil
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */

#ifndef MESSAGE_H_
#define MESSAGE_H_

#include <types.h>
#include <sa/ike_sa_id.h>
#include <network/packet.h>
#include <encoding/payloads/ike_header.h>
#include <utils/linked_list.h>
#include <transforms/crypters/crypter.h>
#include <transforms/signers/signer.h>


typedef struct message_t message_t;

/**
 * @brief This class is used to represent an IKEv2-Message.
 *
 * An IKEv2-Message is either a request or response.
 *
 * @ingroup encoding
 */
struct message_t {

	/**
	 * @brief Sets the IKE major version of the message.
	 *
	 * @param this 			message_t object
	 * @param major_version	major version to set
	 */
	void (*set_major_version) (message_t *this,u_int8_t major_version);

	/**
	 * @brief Gets the IKE major version of the message.
	 *
	 * @param this 			message_t object
	 * @return				major version of the message
	 */
	u_int8_t (*get_major_version) (message_t *this);
	
	/**
	 * @brief Sets the IKE minor version of the message.
	 *
	 * @param this 			message_t object
	 * @param minor_version	minor version to set
	 */
	void (*set_minor_version) (message_t *this,u_int8_t minor_version);

	/**
	 * @brief Gets the IKE minor version of the message.
	 *
	 * @param this 			message_t object
	 * @return				minor version of the message
	 */
	u_int8_t (*get_minor_version) (message_t *this);

	/**
	 * @brief Sets the Message ID of the message.
	 *
	 * @param this 			message_t object
	 * @param message_id		message_id to set
	 */
	void (*set_message_id) (message_t *this,u_int32_t message_id);

	/**
	 * @brief Gets the Message ID of the message.
	 *
	 * @param this 			message_t object
	 * @return				message_id type of the message
	 */
	u_int32_t (*get_message_id) (message_t *this);
	
	/**
	 * @brief Gets the responder SPI of the message.
	 *
	 * @param this 			message_t object
	 * @return				responder spi of the message
	 */
	u_int64_t (*get_responder_spi) (message_t *this);

	/**
	 * @brief Sets the IKE_SA ID of the message.
	 * 
	 * @warning ike_sa_id gets cloned  internaly and 
	 * so can be destroyed afterwards.
	 *
	 * @param this 			message_t object
	 * @param ike_sa_id		ike_sa_id to set
	 */
	void (*set_ike_sa_id) (message_t *this,ike_sa_id_t * ike_sa_id);

	/**
	 * @brief Gets the IKE_SA ID of the message.
	 * 
	 * @warning The returned ike_sa_id is a clone of the internal one.
	 * So it has to be destroyed by the caller.
	 *
	 * @param this 			message_t object
	 * @param ike_sa_id		pointer to ike_sa_id pointer which will be set
	 * @return				
	 * 						- SUCCESS
	 * 						- FAILED if no ike_sa_id is set
	 */
	status_t (*get_ike_sa_id) (message_t *this,ike_sa_id_t **ike_sa_id);

	/**
	 * @brief Sets the exchange type of the message.
	 *
	 * @param this 			message_t object
	 * @param exchange_type	exchange_type to set
	 */
	void (*set_exchange_type) (message_t *this,exchange_type_t exchange_type);

	/**
	 * @brief Gets the exchange type of the message.
	 *
	 * @param this 			message_t object
	 * @return				exchange type of the message
	 */
	exchange_type_t (*get_exchange_type) (message_t *this);

	/**
	 * @brief Sets the original initiator flag.
	 *
	 * @param this 					message_t object
	 * @param original_initiator		TRUE if message is from original initiator
	 */
	void (*set_original_initiator) (message_t *this,bool original_initiator);

	/**
	 * @brief Gets original initiator flag.
	 *
	 * @param this 			message_t object
	 * @return				TRUE if message is from original initiator, FALSE otherwise
	 */
	bool (*get_original_initiator) (message_t *this);

	/**
	 * @brief Sets the request flag.
	 *
	 * @param this 					message_t object
	 * @param original_initiator		TRUE if message is a request, FALSE if it is a reply
	 */
	void (*set_request) (message_t *this,bool request);

	/**
	 * @brief Gets request flag.
	 *
	 * @param this 			message_t object
	 * @return				TRUE if message is a request, FALSE if it is a reply
	 */
	bool (*get_request) (message_t *this);

	/**
	 * @brief Append a payload to the message.
	 *
	 * @param this 			message_t object
	 * @param payload 		payload to append
	 * @return				
	 * 						- SUCCESS or
	 */	
	void (*add_payload) (message_t *this, payload_t *payload);

	/**
	 * @brief Parses header of message
	 *
	 * @param this 		message_t object
	 * @return
	 * 					- SUCCESS if header could be parsed
	 *					- PARSE_ERROR if corrupted/invalid data found
	 * 					- FAILED if consistence check of header failed
	 */
	status_t (*parse_header) (message_t *this);
	
	/**
	 * @brief Parses body of message.
	 * 
	 * The body gets not only parsed, but rather it gets verified. 
	 * All payloads are verified if they are allowed to exist in the message 
	 * of this type and if their own structure is ok.
	 *
	 * @param this 		message_t object
	 * @return
	 * 					- SUCCESS if header could be parsed
	 * 					- NOT_SUPPORTED if unsupported payload are contained in body
	 * 					- FAILED if message type is not suppported!
	 *					- PARSE_ERROR if corrupted/invalid data found
	 * 					- VERIFY_ERROR if verification of some payload failed
	 */
	status_t (*parse_body) (message_t *this, crypter_t *crypter, signer_t *signer);

	/**
	 * @brief Generates the UDP packet of specific message
	 *
	 * @param this 		message_t object
	 * @return
	 * 					- SUCCESS if packet could be generated
	 * 					- EXCHANGE_TYPE_NOT_SET if exchange type is currently not set
	 * ....
	 */	
	status_t (*generate) (message_t *this, crypter_t *crypter, signer_t *signer, packet_t **packet);
	
	status_t (*verify) (message_t *this);
	void (*get_source) (message_t *this, host_t **host);
	void (*set_source) (message_t *this, host_t *host);
	void (*get_destination) (message_t *this, host_t **host);
	void (*set_destination) (message_t *this, host_t *host);
	iterator_t * (*get_payload_iterator) (message_t *this);
	
	/**
	 * @brief Destroys a message and all including objects
	 *
	 * @param this 		message_t object
	 */
	void (*destroy) (message_t *this);
};

/**
 * Creates an message_t object from a incoming UDP Packet.
 * 
 * @warning the given packet_t object is not copied and gets 
 *			destroyed in message_t's destroy call.
 * 
 * @warning Packet is not parsed in here!
 * 
 * - exchange_type is set to NOT_SET
 * - original_initiator is set to TRUE
 * - is_request is set to TRUE
 * 
 * @param packet		packet_t object which is assigned to message					  
 * 
 * @return 			created message_t object
 * 
 * @ingroup encoding
 */
message_t * message_create_from_packet(packet_t *packet);


/**
 * Creates an empty message_t object.
 *
 * - exchange_type is set to NOT_SET
 * - original_initiator is set to TRUE
 * - is_request is set to TRUE
 * 
 * @return created message_t object
 *
 * @ingroup encoding
 */
message_t * message_create();

#endif /*MESSAGE_H_*/