Add a return value to radius_message_t.sign()
[strongswan.git] / src / libradius / radius_message.h
1 /*
2 * Copyright (C) 2009 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup libradius libradius
18 *
19 * @addtogroup libradius
20 * RADIUS protocol support library.
21 *
22 * @defgroup radius_message radius_message
23 * @{ @ingroup libradius
24 */
25
26 #ifndef RADIUS_MESSAGE_H_
27 #define RADIUS_MESSAGE_H_
28
29 #include <library.h>
30
31 #define MAX_RADIUS_ATTRIBUTE_SIZE 253
32
33 #define RADIUS_TUNNEL_TYPE_ESP 9
34
35 typedef struct radius_message_t radius_message_t;
36 typedef enum radius_message_code_t radius_message_code_t;
37 typedef enum radius_attribute_type_t radius_attribute_type_t;
38
39 /**
40 * RADIUS Message Codes.
41 */
42 enum radius_message_code_t {
43 RMC_ACCESS_REQUEST = 1,
44 RMC_ACCESS_ACCEPT = 2,
45 RMC_ACCESS_REJECT = 3,
46 RMC_ACCOUNTING_REQUEST = 4,
47 RMC_ACCOUNTING_RESPONSE = 5,
48 RMC_ACCESS_CHALLENGE = 11,
49 RMC_DISCONNECT_REQUEST = 40,
50 RMC_DISCONNECT_ACK = 41,
51 RMC_DISCONNECT_NAK = 42,
52 RMC_COA_REQUEST = 43,
53 RMC_COA_ACK = 44,
54 RMC_COA_NAK = 45,
55 };
56
57 /**
58 * Enum names for radius_attribute_type_t.
59 */
60 extern enum_name_t *radius_message_code_names;
61
62 /**
63 * RADIUS Attribute Types.
64 */
65 enum radius_attribute_type_t {
66 RAT_USER_NAME = 1,
67 RAT_USER_PASSWORD = 2,
68 RAT_CHAP_PASSWORD = 3,
69 RAT_NAS_IP_ADDRESS = 4,
70 RAT_NAS_PORT = 5,
71 RAT_SERVICE_TYPE = 6,
72 RAT_FRAMED_PROTOCOL = 7,
73 RAT_FRAMED_IP_ADDRESS = 8,
74 RAT_FRAMED_IP_NETMASK = 9,
75 RAT_FRAMED_ROUTING = 10,
76 RAT_FILTER_ID = 11,
77 RAT_FRAMED_MTU = 12,
78 RAT_FRAMED_COMPRESSION = 13,
79 RAT_LOGIN_IP_HOST = 14,
80 RAT_LOGIN_SERVICE = 15,
81 RAT_LOGIN_TCP_PORT = 16,
82 RAT_REPLY_MESSAGE = 18,
83 RAT_CALLBACK_NUMBER = 19,
84 RAT_CALLBACK_ID = 20,
85 RAT_FRAMED_ROUTE = 22,
86 RAT_FRAMED_IPX_NETWORK = 23,
87 RAT_STATE = 24,
88 RAT_CLASS = 25,
89 RAT_VENDOR_SPECIFIC = 26,
90 RAT_SESSION_TIMEOUT = 27,
91 RAT_IDLE_TIMEOUT = 28,
92 RAT_TERMINATION_ACTION = 29,
93 RAT_CALLED_STATION_ID = 30,
94 RAT_CALLING_STATION_ID = 31,
95 RAT_NAS_IDENTIFIER = 32,
96 RAT_PROXY_STATE = 33,
97 RAT_LOGIN_LAT_SERVICE = 34,
98 RAT_LOGIN_LAT_NODE = 35,
99 RAT_LOGIN_LAT_GROUP = 36,
100 RAT_FRAMED_APPLETALK_LINK = 37,
101 RAT_FRAMED_APPLETALK_NETWORK = 38,
102 RAT_FRAMED_APPLETALK_ZONE = 39,
103 RAT_ACCT_STATUS_TYPE = 40,
104 RAT_ACCT_DELAY_TIME = 41,
105 RAT_ACCT_INPUT_OCTETS = 42,
106 RAT_ACCT_OUTPUT_OCTETS = 43,
107 RAT_ACCT_SESSION_ID = 44,
108 RAT_ACCT_AUTHENTIC = 45,
109 RAT_ACCT_SESSION_TIME = 46,
110 RAT_ACCT_INPUT_PACKETS = 47,
111 RAT_ACCT_OUTPUT_PACKETS = 48,
112 RAT_ACCT_TERMINATE_CAUSE = 49,
113 RAT_ACCT_MULTI_SESSION_ID = 50,
114 RAT_ACCT_LINK_COUNT = 51,
115 RAT_ACCT_INPUT_GIGAWORDS = 52,
116 RAT_ACCT_OUTPUT_GIGAWORDS = 53,
117 RAT_EVENT_TIMESTAMP = 55,
118 RAT_EGRESS_VLANID = 56,
119 RAT_INGRESS_FILTERS = 57,
120 RAT_EGRESS_VLAN_NAME = 58,
121 RAT_USER_PRIORITY_TABLE = 59,
122 RAT_CHAP_CHALLENGE = 60,
123 RAT_NAS_PORT_TYPE = 61,
124 RAT_PORT_LIMIT = 62,
125 RAT_LOGIN_LAT_PORT = 63,
126 RAT_TUNNEL_TYPE = 64,
127 RAT_TUNNEL_MEDIUM_TYPE = 65,
128 RAT_TUNNEL_CLIENT_ENDPOINT = 66,
129 RAT_TUNNEL_SERVER_ENDPOINT = 67,
130 RAT_ACCT_TUNNEL_CONNECTION = 68,
131 RAT_TUNNEL_PASSWORD = 69,
132 RAT_ARAP_PASSWORD = 70,
133 RAT_ARAP_FEATURES = 71,
134 RAT_ARAP_ZONE_ACCESS = 72,
135 RAT_ARAP_SECURITY = 73,
136 RAT_ARAP_SECURITY_DATA = 74,
137 RAT_PASSWORD_RETRY = 75,
138 RAT_PROMPT = 76,
139 RAT_CONNECT_INFO = 77,
140 RAT_CONFIGURATION_TOKEN = 78,
141 RAT_EAP_MESSAGE = 79,
142 RAT_MESSAGE_AUTHENTICATOR = 80,
143 RAT_TUNNEL_PRIVATE_GROUP_ID = 81,
144 RAT_TUNNEL_ASSIGNMENT_ID = 82,
145 RAT_TUNNEL_PREFERENCE = 83,
146 RAT_ARAP_CHALLENGE_RESPONSE = 84,
147 RAT_ACCT_INTERIM_INTERVAL = 85,
148 RAT_ACCT_TUNNEL_PACKETS_LOST = 86,
149 RAT_NAS_PORT_ID = 87,
150 RAT_FRAMED_POOL = 88,
151 RAT_CUI = 89,
152 RAT_TUNNEL_CLIENT_AUTH_ID = 90,
153 RAT_TUNNEL_SERVER_AUTH_ID = 91,
154 RAT_NAS_FILTER_RULE = 92,
155 RAT_UNASSIGNED = 93,
156 RAT_ORIGINATING_LINE_INFO = 94,
157 RAT_NAS_IPV6_ADDRESS = 95,
158 RAT_FRAMED_INTERFACE_ID = 96,
159 RAT_FRAMED_IPV6_PREFIX = 97,
160 RAT_LOGIN_IPV6_HOST = 98,
161 RAT_FRAMED_IPV6_ROUTE = 99,
162 RAT_FRAMED_IPV6_POOL = 100,
163 RAT_ERROR_CAUSE = 101,
164 RAT_EAP_KEY_NAME = 102,
165 RAT_DIGEST_RESPONSE = 103,
166 RAT_DIGEST_REALM = 104,
167 RAT_DIGEST_NONCE = 105,
168 RAT_DIGEST_RESPONSE_AUTH = 106,
169 RAT_DIGEST_NEXTNONCE = 107,
170 RAT_DIGEST_METHOD = 108,
171 RAT_DIGEST_URI = 109,
172 RAT_DIGEST_QOP = 110,
173 RAT_DIGEST_ALGORITHM = 111,
174 RAT_DIGEST_ENTITY_BODY_HASH = 112,
175 RAT_DIGEST_CNONCE = 113,
176 RAT_DIGEST_NONCE_COUNT = 114,
177 RAT_DIGEST_USERNAME = 115,
178 RAT_DIGEST_OPAQUE = 116,
179 RAT_DIGEST_AUTH_PARAM = 117,
180 RAT_DIGEST_AKA_AUTS = 118,
181 RAT_DIGEST_DOMAIN = 119,
182 RAT_DIGEST_STALE = 120,
183 RAT_DIGEST_HA1 = 121,
184 RAT_SIP_AOR = 122,
185 RAT_DELEGATED_IPV6_PREFIX = 123,
186 RAT_MIP6_FEATURE_VECTOR = 124,
187 RAT_MIP6_HOME_LINK_PREFIX = 125,
188 };
189
190 /**
191 * Enum names for radius_attribute_type_t.
192 */
193 extern enum_name_t *radius_attribute_type_names;
194
195 /**
196 * A RADIUS message, contains attributes.
197 */
198 struct radius_message_t {
199
200 /**
201 * Create an enumerator over contained RADIUS attributes.
202 *
203 * @return enumerator over (int type, chunk_t data)
204 */
205 enumerator_t* (*create_enumerator)(radius_message_t *this);
206
207 /**
208 * Add a RADIUS attribute to the message.
209 *
210 * @param type type of attribute to add
211 * @param attribute data, gets cloned
212 */
213 void (*add)(radius_message_t *this, radius_attribute_type_t type,
214 chunk_t data);
215
216 /**
217 * Get the message type (code).
218 *
219 * @return message code
220 */
221 radius_message_code_t (*get_code)(radius_message_t *this);
222
223 /**
224 * Get the message identifier.
225 *
226 * @return message identifier
227 */
228 u_int8_t (*get_identifier)(radius_message_t *this);
229
230 /**
231 * Set the message identifier.
232 *
233 * @param identifier message identifier
234 */
235 void (*set_identifier)(radius_message_t *this, u_int8_t identifier);
236
237 /**
238 * Get the 16 byte authenticator.
239 *
240 * @return pointer to the Authenticator field
241 */
242 u_int8_t* (*get_authenticator)(radius_message_t *this);
243
244 /**
245 * Get the RADIUS message in its encoded form.
246 *
247 * @return chunk pointing to internal RADIUS message.
248 */
249 chunk_t (*get_encoding)(radius_message_t *this);
250
251 /**
252 * Calculate and add the Message-Authenticator attribute to the message.
253 *
254 * @param req_auth 16 byte Authenticator of request, or NULL
255 * @param secret shared RADIUS secret
256 * @param signer HMAC-MD5 signer with secret set
257 * @param hasher MD5 hasher
258 * @param rng RNG to create Request-Authenticator, NULL to omit
259 * @param msg_auth calculate and add Message-Authenticator
260 * @return TRUE if signed successfully
261 */
262 bool (*sign)(radius_message_t *this, u_int8_t *req_auth, chunk_t secret,
263 hasher_t *hasher, signer_t *signer, rng_t *rng, bool msg_auth);
264
265 /**
266 * Verify the integrity of a received RADIUS message.
267 *
268 * @param req_auth 16 byte Authenticator of request, or NULL
269 * @param secret shared RADIUS secret
270 * @param signer HMAC-MD5 signer with secret set
271 * @param hasher MD5 hasher
272 */
273 bool (*verify)(radius_message_t *this, u_int8_t *req_auth, chunk_t secret,
274 hasher_t *hasher, signer_t *signer);
275
276 /**
277 * Destroy the message.
278 */
279 void (*destroy)(radius_message_t *this);
280 };
281
282 /**
283 * Dummy libradius initialization function needed for integrity test
284 */
285 void libradius_init(void);
286
287 /**
288 * Create an empty RADIUS message.
289 *
290 * @param code request type
291 * @return radius_message_t object
292 */
293 radius_message_t *radius_message_create(radius_message_code_t code);
294
295 /**
296 * Parse and verify a recevied RADIUS message.
297 *
298 * @param data received message data
299 * @return radius_message_t object, NULL if length invalid
300 */
301 radius_message_t *radius_message_parse(chunk_t data);
302
303 #endif /** RADIUS_MESSAGE_H_ @}*/