Mercurial > hg > freeDiameter
annotate extensions/app_radgw/rgwx_auth.c @ 271:411314907b43
Added translation of Accounting messages
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Tue, 20 Apr 2010 19:34:59 +0900 |
parents | a3b2cde34f7b |
children | bce8e5b7bf78 |
rev | line source |
---|---|
256 | 1 /********************************************************************************************************* |
2 * Software License Agreement (BSD License) * | |
3 * Author: Sebastien Decugis <sdecugis@nict.go.jp> * | |
4 * * | |
258
5df55136361b
Updated copyright information
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
256
diff
changeset
|
5 * Copyright (c) 2010, WIDE Project and NICT * |
256 | 6 * All rights reserved. * |
7 * * | |
8 * Redistribution and use of this software in source and binary forms, with or without modification, are * | |
9 * permitted provided that the following conditions are met: * | |
10 * * | |
11 * * Redistributions of source code must retain the above * | |
12 * copyright notice, this list of conditions and the * | |
13 * following disclaimer. * | |
14 * * | |
15 * * Redistributions in binary form must reproduce the above * | |
16 * copyright notice, this list of conditions and the * | |
17 * following disclaimer in the documentation and/or other * | |
18 * materials provided with the distribution. * | |
19 * * | |
20 * * Neither the name of the WIDE Project or NICT nor the * | |
21 * names of its contributors may be used to endorse or * | |
22 * promote products derived from this software without * | |
23 * specific prior written permission of WIDE Project and * | |
24 * NICT. * | |
25 * * | |
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * | |
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * | |
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * | |
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * | |
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * | |
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * | |
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * | |
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * | |
34 *********************************************************************************************************/ | |
35 | |
36 /* RADIUS Access-Request messages translation plugin */ | |
37 | |
38 #include "rgw_common.h" | |
39 | |
40 /* Attributes missing from radius.h */ | |
41 #define RADIUS_ATTR_CHAP_PASSWORD 3 | |
42 #define RADIUS_ATTR_ARAP_PASSWORD 70 | |
43 | |
44 /* Other constants we use */ | |
45 #define AI_NASREQ 1 /* Diameter NASREQ */ | |
46 #define AI_EAP 5 /* Diameter EAP application */ | |
47 #define CC_AA 265 /* AAR */ | |
48 #define CC_DIAMETER_EAP 268 /* DER */ | |
49 #define ACV_ART_AUTHORIZE_AUTHENTICATE 3 /* AUTHORIZE_AUTHENTICATE */ | |
50 #define ACV_OAP_RADIUS 1 /* RADIUS */ | |
51 #define ACV_ASS_STATE_MAINTAINED 0 /* STATE_MAINTAINED */ | |
52 #define ER_DIAMETER_MULTI_ROUND_AUTH 1001 | |
53 #define ER_DIAMETER_LIMITED_SUCCESS 2002 | |
54 | |
55 /* The state we keep for this plugin */ | |
56 struct rgwp_config { | |
57 struct { | |
58 struct dict_object * ARAP_Password; /* ARAP-Password */ | |
59 struct dict_object * ARAP_Security; /* ARAP-Security */ | |
60 struct dict_object * ARAP_Security_Data; /* ARAP-Security-Data */ | |
61 struct dict_object * Auth_Application_Id; /* Auth-Application-Id */ | |
62 struct dict_object * Auth_Request_Type; /* Auth-Request-Type */ | |
63 struct dict_object * Authorization_Lifetime; /* Authorization-Lifetime */ | |
64 struct dict_object * Callback_Number; /* Callback-Number */ | |
65 struct dict_object * Called_Station_Id; /* Called-Station-Id */ | |
66 struct dict_object * Calling_Station_Id; /* Calling-Station-Id */ | |
67 struct dict_object * CHAP_Algorithm; /* CHAP-Algorithm */ | |
68 struct dict_object * CHAP_Auth; /* CHAP-Auth */ | |
69 struct dict_object * CHAP_Challenge; /* CHAP-Challenge */ | |
70 struct dict_object * CHAP_Ident; /* CHAP-Ident */ | |
71 struct dict_object * CHAP_Response; /* CHAP-Response */ | |
72 struct dict_object * Connect_Info; /* Connect-Info */ | |
73 struct dict_object * EAP_Payload; /* EAP-Payload */ | |
74 struct dict_object * Error_Message; /* Error-Message */ | |
75 struct dict_object * Error_Reporting_Host; /* Error-Reporting-Host */ | |
76 struct dict_object * Failed_AVP; /* Failed-AVP */ | |
77 struct dict_object * Framed_Compression; /* Framed-Compression */ | |
78 struct dict_object * Framed_IP_Address; /* Framed-IP-Address */ | |
79 struct dict_object * Framed_IP_Netmask; /* Framed-IP-Netmask */ | |
80 struct dict_object * Framed_Interface_Id; /* Framed-Interface-Id */ | |
81 struct dict_object * Framed_IPv6_Prefix; /* Framed-IPv6-Prefix */ | |
82 struct dict_object * Framed_MTU; /* Framed-MTU */ | |
83 struct dict_object * Framed_Protocol; /* Framed-Protocol */ | |
84 struct dict_object * Login_IP_Host; /* Login-IP-Host */ | |
85 struct dict_object * Login_IPv6_Host; /* Login-IPv6-Host */ | |
86 struct dict_object * Login_LAT_Group; /* Login-LAT-Group */ | |
87 struct dict_object * Login_LAT_Node; /* Login-LAT-Node */ | |
88 struct dict_object * Login_LAT_Port; /* Login-LAT-Port */ | |
89 struct dict_object * Login_LAT_Service; /* Login-LAT-Service */ | |
90 struct dict_object * NAS_Identifier; /* NAS-Identifier */ | |
91 struct dict_object * NAS_IP_Address; /* NAS-IP-Address */ | |
92 struct dict_object * NAS_IPv6_Address; /* NAS-IPv6-Address */ | |
93 struct dict_object * NAS_Port; /* NAS-Port */ | |
94 struct dict_object * NAS_Port_Id; /* NAS-Port-Id */ | |
95 struct dict_object * NAS_Port_Type; /* NAS-Port-Type */ | |
96 struct dict_object * Origin_AAA_Protocol; /* Origin-AAA-Protocol */ | |
97 struct dict_object * Origin_Host; /* Origin-Host */ | |
98 struct dict_object * Origin_Realm; /* Origin-Realm */ | |
99 struct dict_object * Originating_Line_Info; /* Originating-Line-Info */ | |
100 struct dict_object * Port_Limit; /* Port-Limit */ | |
101 struct dict_object * Re_Auth_Request_Type; /* Re-Auth-Request-Type */ | |
102 struct dict_object * Result_Code; /* Result-Code */ | |
103 struct dict_object * Service_Type; /* Service-Type */ | |
104 struct dict_object * Session_Id; /* Session-Id */ | |
105 struct dict_object * Session_Timeout; /* Session-Timeout */ | |
106 struct dict_object * State; /* State */ | |
107 struct dict_object * Tunneling; /* Tunneling */ | |
108 struct dict_object * Tunnel_Type; /* Tunnel-Type */ | |
109 struct dict_object * Tunnel_Medium_Type; /* Tunnel-Medium-Type */ | |
110 struct dict_object * Tunnel_Client_Endpoint; /* Tunnel-Client-Endpoint */ | |
111 struct dict_object * Tunnel_Server_Endpoint; /* Tunnel-Server-Endpoint */ | |
112 struct dict_object * Tunnel_Private_Group_Id; /* Tunnel-Private-Group-Id */ | |
113 struct dict_object * Tunnel_Preference; /* Tunnel-Preference */ | |
114 struct dict_object * Tunnel_Client_Auth_Id; /* Tunnel-Client-Auth-Id */ | |
115 struct dict_object * Tunnel_Server_Auth_Id; /* Tunnel-Server-Auth-Id */ | |
116 struct dict_object * User_Name; /* User-Name */ | |
117 struct dict_object * User_Password; /* User-Password */ | |
118 | |
119 } dict; /* cache of the dictionary objects we use */ | |
271
411314907b43
Added translation of Accounting messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
264
diff
changeset
|
120 struct session_handler * sess_hdl; /* We store RADIUS request authenticator information in the session */ |
256 | 121 char * confstr; |
122 }; | |
123 | |
124 /* Initialize the plugin */ | |
125 static int auth_conf_parse(char * conffile, struct rgwp_config ** state) | |
126 { | |
127 struct rgwp_config * new; | |
264
a3b2cde34f7b
Advertize support for translated applications
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
262
diff
changeset
|
128 struct dict_object * app; |
256 | 129 |
130 TRACE_ENTRY("%p %p", conffile, state); | |
131 CHECK_PARAMS( state ); | |
132 | |
133 CHECK_MALLOC( new = malloc(sizeof(struct rgwp_config)) ); | |
134 memset(new, 0, sizeof(struct rgwp_config)); | |
135 | |
136 CHECK_FCT( fd_sess_handler_create( &new->sess_hdl, free ) ); | |
137 new->confstr = conffile; | |
138 | |
139 /* Resolve all dictionary objects we use */ | |
140 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "ARAP-Password", &new->dict.ARAP_Password, ENOENT) ); | |
141 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "ARAP-Security", &new->dict.ARAP_Security, ENOENT) ); | |
142 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "ARAP-Security-Data", &new->dict.ARAP_Security_Data, ENOENT) ); | |
143 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Auth-Application-Id", &new->dict.Auth_Application_Id, ENOENT) ); | |
144 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Auth-Request-Type", &new->dict.Auth_Request_Type, ENOENT) ); | |
145 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Authorization-Lifetime", &new->dict.Authorization_Lifetime, ENOENT) ); | |
146 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Callback-Number", &new->dict.Callback_Number, ENOENT) ); | |
147 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Called-Station-Id", &new->dict.Called_Station_Id, ENOENT) ); | |
148 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Calling-Station-Id", &new->dict.Calling_Station_Id, ENOENT) ); | |
149 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "CHAP-Algorithm", &new->dict.CHAP_Algorithm, ENOENT) ); | |
150 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "CHAP-Auth", &new->dict.CHAP_Auth, ENOENT) ); | |
151 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "CHAP-Challenge", &new->dict.CHAP_Challenge, ENOENT) ); | |
152 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "CHAP-Ident", &new->dict.CHAP_Ident, ENOENT) ); | |
153 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "CHAP-Response", &new->dict.CHAP_Response, ENOENT) ); | |
154 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Connect-Info", &new->dict.Connect_Info, ENOENT) ); | |
155 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "EAP-Payload", &new->dict.EAP_Payload, ENOENT) ); | |
156 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Error-Message", &new->dict.Error_Message, ENOENT) ); | |
157 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Error-Reporting-Host", &new->dict.Error_Reporting_Host, ENOENT) ); | |
158 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Failed-AVP", &new->dict.Failed_AVP, ENOENT) ); | |
159 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Framed-Compression", &new->dict.Framed_Compression, ENOENT) ); | |
160 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Framed-IP-Address", &new->dict.Framed_IP_Address, ENOENT) ); | |
161 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Framed-IP-Netmask", &new->dict.Framed_IP_Netmask, ENOENT) ); | |
162 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Framed-Interface-Id", &new->dict.Framed_Interface_Id, ENOENT) ); | |
163 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Framed-IPv6-Prefix", &new->dict.Framed_IPv6_Prefix, ENOENT) ); | |
164 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Framed-MTU", &new->dict.Framed_MTU, ENOENT) ); | |
165 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Framed-Protocol", &new->dict.Framed_Protocol, ENOENT) ); | |
166 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Login-IP-Host", &new->dict.Login_IP_Host, ENOENT) ); | |
167 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Login-IPv6-Host", &new->dict.Login_IPv6_Host, ENOENT) ); | |
168 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Login-LAT-Group", &new->dict.Login_LAT_Group, ENOENT) ); | |
169 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Login-LAT-Node", &new->dict.Login_LAT_Node, ENOENT) ); | |
170 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Login-LAT-Port", &new->dict.Login_LAT_Port, ENOENT) ); | |
171 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Login-LAT-Service", &new->dict.Login_LAT_Service, ENOENT) ); | |
172 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "NAS-Identifier", &new->dict.NAS_Identifier, ENOENT) ); | |
173 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "NAS-IP-Address", &new->dict.NAS_IP_Address, ENOENT) ); | |
174 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "NAS-IPv6-Address", &new->dict.NAS_IPv6_Address, ENOENT) ); | |
175 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "NAS-Port", &new->dict.NAS_Port, ENOENT) ); | |
176 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "NAS-Port-Id", &new->dict.NAS_Port_Id, ENOENT) ); | |
177 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "NAS-Port-Type", &new->dict.NAS_Port_Type, ENOENT) ); | |
178 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Origin-AAA-Protocol", &new->dict.Origin_AAA_Protocol, ENOENT) ); | |
179 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Origin-Host", &new->dict.Origin_Host, ENOENT) ); | |
180 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Origin-Realm", &new->dict.Origin_Realm, ENOENT) ); | |
181 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Originating-Line-Info", &new->dict.Originating_Line_Info, ENOENT) ); | |
182 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Port-Limit", &new->dict.Port_Limit, ENOENT) ); | |
183 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Re-Auth-Request-Type", &new->dict.Re_Auth_Request_Type, ENOENT) ); | |
184 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Result-Code", &new->dict.Result_Code, ENOENT) ); | |
185 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Service-Type", &new->dict.Service_Type, ENOENT) ); | |
186 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Session-Id", &new->dict.Session_Id, ENOENT) ); | |
187 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Session-Timeout", &new->dict.Session_Timeout, ENOENT) ); | |
188 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "State", &new->dict.State, ENOENT) ); | |
189 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Tunneling", &new->dict.Tunneling, ENOENT) ); | |
190 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Tunnel-Type", &new->dict.Tunnel_Type, ENOENT) ); | |
191 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Tunnel-Medium-Type", &new->dict.Tunnel_Medium_Type, ENOENT) ); | |
192 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Tunnel-Client-Endpoint", &new->dict.Tunnel_Client_Endpoint, ENOENT) ); | |
193 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Tunnel-Server-Endpoint", &new->dict.Tunnel_Server_Endpoint, ENOENT) ); | |
194 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Tunnel-Private-Group-Id", &new->dict.Tunnel_Private_Group_Id, ENOENT) ); | |
195 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Tunnel-Preference", &new->dict.Tunnel_Preference, ENOENT) ); | |
196 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Tunnel-Client-Auth-Id", &new->dict.Tunnel_Client_Auth_Id, ENOENT) ); | |
197 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Tunnel-Server-Auth-Id", &new->dict.Tunnel_Server_Auth_Id, ENOENT) ); | |
198 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "User-Name", &new->dict.User_Name, ENOENT) ); | |
199 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "User-Password", &new->dict.User_Password, ENOENT) ); | |
200 | |
264
a3b2cde34f7b
Advertize support for translated applications
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
262
diff
changeset
|
201 /* This plugin provides the following Diameter authentication applications support: */ |
a3b2cde34f7b
Advertize support for translated applications
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
262
diff
changeset
|
202 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_APPLICATION, APPLICATION_BY_NAME, "Diameter Network Access Server Application", &app, ENOENT) ); |
a3b2cde34f7b
Advertize support for translated applications
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
262
diff
changeset
|
203 CHECK_FCT( fd_disp_app_support ( app, NULL, 1, 0 ) ); |
a3b2cde34f7b
Advertize support for translated applications
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
262
diff
changeset
|
204 |
a3b2cde34f7b
Advertize support for translated applications
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
262
diff
changeset
|
205 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_APPLICATION, APPLICATION_BY_NAME, "Diameter Extensible Authentication Protocol (EAP) Application", &app, ENOENT) ); |
a3b2cde34f7b
Advertize support for translated applications
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
262
diff
changeset
|
206 CHECK_FCT( fd_disp_app_support ( app, NULL, 1, 0 ) ); |
a3b2cde34f7b
Advertize support for translated applications
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
262
diff
changeset
|
207 |
262
cc2c568ef319
Missing affectation
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
208 *state = new; |
256 | 209 return 0; |
210 } | |
211 | |
212 /* deinitialize */ | |
213 static void auth_conf_free(struct rgwp_config * state) | |
214 { | |
215 TRACE_ENTRY("%p", state); | |
216 CHECK_PARAMS_DO( state, return ); | |
217 CHECK_FCT_DO( fd_sess_handler_destroy( &state->sess_hdl ), ); | |
218 free(state); | |
219 return; | |
220 } | |
221 | |
222 /* Handle an incoming RADIUS request */ | |
223 static int auth_rad_req( struct rgwp_config * cs, struct session * session, struct radius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli ) | |
224 { | |
225 int idx; | |
226 int got_id = 0; | |
227 int got_mac = 0; | |
228 int got_passwd = 0; | |
229 int got_eap = 0; | |
230 int got_empty_eap = 0; | |
231 uint32_t status_type; | |
232 size_t nattr_used = 0; | |
233 struct avp ** avp_tun = NULL, *avp = NULL; | |
234 union avp_value value; | |
235 | |
236 TRACE_ENTRY("%p %p %p %p %p %p", cs, session, rad_req, rad_ans, diam_fw, cli); | |
237 CHECK_PARAMS(rad_req && (rad_req->hdr->code == RADIUS_CODE_ACCESS_REQUEST) && rad_ans && diam_fw && *diam_fw); | |
238 | |
239 /* | |
240 Guidelines: | |
241 http://tools.ietf.org/html/rfc4005#section-9.1 | |
242 http://tools.ietf.org/html/rfc4072#section-6.1 | |
243 | |
244 When a Translation Agent receives a RADIUS message, the following | |
245 steps should be taken: | |
246 | |
247 - If a Message-Authenticator attribute is present, the value MUST | |
248 be checked but not included in the Diameter message. If it is | |
249 incorrect, the RADIUS message should be silently discarded. | |
250 The gateway system SHOULD generate and include a Message- | |
251 Authenticator in returned RADIUS responses. | |
252 -> done in rgw_msg_auth_check | |
253 | |
254 - The transport address of the sender MUST be checked against the | |
255 NAS identifying attributes. See the description of NAS- | |
256 Identifier and NAS-IP-Address below. | |
257 -> done in rgw_clients_check_origin | |
258 | |
259 - The Translation Agent must maintain transaction state | |
260 information relevant to the RADIUS request, such as the | |
261 Identifier field in the RADIUS header, any existing RADIUS | |
262 Proxy-State attribute, and the source IP address and port | |
263 number of the UDP packet. These may be maintained locally in a | |
264 state table or saved in a Proxy-Info AVP group. A Diameter | |
265 Session-Id AVP value must be created using a session state | |
266 mapping mechanism. | |
267 -> Identifier, source and port are saved along with the request, | |
268 and associated with the session state. | |
269 -> sub_echo_drop should handle the Proxy-State attribute (conf issue) | |
270 | |
271 - If the RADIUS request contained a State attribute and the | |
272 prefix of the data is "Diameter/", the data following the | |
273 prefix contains the Diameter Origin-Host/Origin-Realm/Session- | |
274 Id. If no such attributes are present and the RADIUS command | |
275 is an Access-Request, a new Session-Id is created. The | |
276 Session-Id is included in the Session-Id AVP. | |
277 -> done in rgw_msg_create_base. | |
278 | |
279 - The Diameter Origin-Host and Origin-Realm AVPs MUST be created | |
280 and added by using the information from an FQDN corresponding | |
281 to the NAS-IP-Address attribute (preferred if available), | |
282 and/or to the NAS-Identifier attribute. (Note that the RADIUS | |
283 NAS-Identifier is not required to be an FQDN.) | |
284 -> done in rgw_msg_create_base. | |
285 | |
286 - The response MUST have an Origin-AAA-Protocol AVP added, | |
287 indicating the protocol of origin of the message. | |
288 -> what "response" ??? Added to the AAR / DER in this function. | |
289 | |
290 - The Proxy-Info group SHOULD be added, with the local server's | |
291 identity specified in the Proxy-Host AVP. This should ensure | |
292 that the response is returned to this system. | |
293 -> We don't need this, answer is always routed here anyway. | |
294 | |
295 For EAP: | |
296 | |
297 o RADIUS EAP-Message attribute(s) are translated to a Diameter | |
298 EAP-Payload AVP. If multiple RADIUS EAP-Message attributes are | |
299 present, they are concatenated and translated to a single Diameter | |
300 EAP-Payload AVP. | |
301 -> concatenation done by radius_msg_get_eap | |
302 | |
303 -> the remaining is specific conversion rules | |
304 */ | |
305 | |
306 /* Check basic information is there */ | |
307 for (idx = 0; idx < rad_req->attr_used; idx++) { | |
308 struct radius_attr_hdr * attr = (struct radius_attr_hdr *)(rad_req->buf + rad_req->attr_pos[idx]); | |
309 switch (attr->type) { | |
310 case RADIUS_ATTR_NAS_IP_ADDRESS: | |
311 case RADIUS_ATTR_NAS_IDENTIFIER: | |
312 case RADIUS_ATTR_NAS_IPV6_ADDRESS: | |
313 got_id = 1; | |
314 break; | |
315 case RADIUS_ATTR_MESSAGE_AUTHENTICATOR: | |
316 got_mac = 1; | |
317 break; | |
318 case RADIUS_ATTR_EAP_MESSAGE: | |
319 got_eap = 1; | |
320 if (attr->length == 2) | |
321 got_empty_eap = 1; | |
322 break; | |
323 case RADIUS_ATTR_USER_PASSWORD: | |
324 case RADIUS_ATTR_CHAP_PASSWORD: | |
325 case RADIUS_ATTR_ARAP_PASSWORD: | |
326 got_passwd += 1; | |
327 break; | |
328 } | |
329 } | |
330 if (!got_id) { | |
331 TRACE_DEBUG(INFO, "RADIUS Access-Request did not contain a NAS IP or Identifier attribute, reject."); | |
332 return EINVAL; | |
333 } | |
334 /* [Note 1] An Access-Request that contains either a User-Password or | |
335 CHAP-Password or ARAP-Password or one or more EAP-Message attributes | |
336 MUST NOT contain more than one type of those four attributes. If it | |
337 does not contain any of those four attributes, it SHOULD contain a | |
338 Message-Authenticator. If any packet type contains an EAP-Message | |
339 attribute it MUST also contain a Message-Authenticator. A RADIUS | |
340 server receiving an Access-Request not containing any of those four | |
341 attributes and also not containing a Message-Authenticator attribute | |
342 SHOULD silently discard it. */ | |
343 if (((got_eap + got_passwd) > 1) || (got_eap && !got_mac) || (!got_eap && !got_passwd && !got_mac)) { | |
344 TRACE_DEBUG(INFO, "RADIUS Access-Request not conform to RFC3579 sec 3.3 note 1, discard."); | |
345 return EINVAL; | |
346 } | |
347 | |
348 /* Add the appropriate command code & Auth-Application-Id */ | |
349 { | |
350 struct msg_hdr * header = NULL; | |
351 CHECK_FCT( fd_msg_hdr ( *diam_fw, &header ) ); | |
352 header->msg_flags = CMD_FLAG_REQUEST | CMD_FLAG_PROXIABLE; | |
353 if (got_eap) { | |
354 header->msg_code = CC_DIAMETER_EAP; | |
355 header->msg_appl = AI_EAP; | |
356 } else { | |
357 header->msg_code = CC_AA; | |
358 header->msg_appl = AI_NASREQ; | |
359 } | |
360 | |
361 /* Add the Auth-Application-Id */ | |
362 { | |
363 CHECK_FCT( fd_msg_avp_new ( cs->dict.Auth_Application_Id, 0, &avp ) ); | |
364 value.i32 = header->msg_appl; | |
365 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); | |
366 CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_LAST_CHILD, avp) ); | |
367 } | |
368 } | |
369 | |
370 /* The type of request is identified through the Auth-Request-Type AVP | |
371 [BASE]. The recommended value for most RADIUS interoperabily | |
372 situations is AUTHORIZE_AUTHENTICATE. */ | |
373 | |
374 /* Add Auth-Request-Type AVP */ | |
375 { | |
376 CHECK_FCT( fd_msg_avp_new ( cs->dict.Auth_Request_Type, 0, &avp ) ); | |
377 value.i32 = ACV_ART_AUTHORIZE_AUTHENTICATE; | |
378 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); | |
379 CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_LAST_CHILD, avp) ); | |
380 } | |
381 | |
382 /* Add Origin-AAA-Protocol AVP */ | |
383 { | |
384 CHECK_FCT( fd_msg_avp_new ( cs->dict.Origin_AAA_Protocol, 0, &avp ) ); | |
385 value.i32 = ACV_OAP_RADIUS; | |
386 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); | |
387 CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_LAST_CHILD, avp) ); | |
388 } | |
389 | |
390 /* Convert the EAP payload (concat RADIUS attributes) */ | |
391 if (got_eap) { | |
392 CHECK_FCT( fd_msg_avp_new ( cs->dict.EAP_Payload, 0, &avp ) ); | |
393 | |
394 /* o An empty RADIUS EAP-Message attribute (with length 2) signifies | |
395 EAP-Start, and it is translated to an empty EAP-Payload AVP. */ | |
396 if (got_empty_eap) { | |
397 value.os.len = 0; | |
398 value.os.data = ""; | |
399 } else { | |
400 CHECK_MALLOC( value.os.data = radius_msg_get_eap(rad_req, &value.os.len) ); | |
401 } | |
402 | |
403 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); | |
404 CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_LAST_CHILD, avp) ); | |
405 } | |
406 | |
407 /* Tunnel AVPs need some preparation */ | |
408 /* Convert the attributes one by one */ | |
409 for (idx = 0; idx < rad_req->attr_used; idx++) { | |
410 struct radius_attr_hdr * attr = (struct radius_attr_hdr *)(rad_req->buf + rad_req->attr_pos[idx]); | |
411 | |
412 switch (attr->type) { | |
413 | |
414 /* This macro converts a RADIUS attribute to a Diameter AVP of type OctetString */ | |
415 #define CONV2DIAM_STR( _dictobj_ ) \ | |
416 CHECK_PARAMS( attr->length >= 2 ); \ | |
417 /* Create the AVP with the specified dictionary model */ \ | |
418 CHECK_FCT( fd_msg_avp_new ( cs->dict._dictobj_, 0, &avp ) ); \ | |
419 value.os.len = attr->length - 2; \ | |
420 value.os.data = (unsigned char *)(attr + 1); \ | |
421 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); \ | |
422 /* Add the AVP in the Diameter message. */ \ | |
423 CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_LAST_CHILD, avp) ); \ | |
424 | |
425 /* Same thing, for scalar AVPs of 32 bits */ | |
426 #define CONV2DIAM_32B( _dictobj_ ) \ | |
427 CHECK_PARAMS( attr->length == 6 ); \ | |
428 CHECK_FCT( fd_msg_avp_new ( cs->dict._dictobj_, 0, &avp ) ); \ | |
429 { \ | |
430 uint8_t * v = (uint8_t *)(attr + 1); \ | |
431 value.u32 = (v[0] << 24) \ | |
432 | (v[1] << 16) \ | |
433 | (v[2] << 8) \ | |
434 | v[3] ; \ | |
435 } \ | |
436 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); \ | |
437 CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_LAST_CHILD, avp) ); \ | |
438 | |
439 /* And the 64b version */ | |
440 #define CONV2DIAM_64B( _dictobj_ ) \ | |
441 CHECK_PARAMS( attr->length == 10); \ | |
442 CHECK_FCT( fd_msg_avp_new ( cs->dict._dictobj_, 0, &avp ) ); \ | |
443 { \ | |
444 uint8_t * v = (uint8_t *)(attr + 1); \ | |
445 value.u64 = ((uint64_t)(v[0]) << 56) \ | |
446 | ((uint64_t)(v[1]) << 48) \ | |
447 | ((uint64_t)(v[2]) << 40) \ | |
448 | ((uint64_t)(v[3]) << 32) \ | |
449 | ((uint64_t)(v[4]) << 24) \ | |
450 | ((uint64_t)(v[5]) << 16) \ | |
451 | ((uint64_t)(v[6]) << 8) \ | |
452 | (uint64_t)(v[7]) ; \ | |
453 } \ | |
454 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); \ | |
455 CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_LAST_CHILD, avp) ); \ | |
456 | |
457 /* RFC 2865 */ | |
458 /* | |
459 - The Destination-Realm AVP is created from the information found | |
460 in the RADIUS User-Name attribute. | |
461 -> done in rgw_msg_create_base | |
462 */ | |
463 case RADIUS_ATTR_USER_NAME: | |
464 CONV2DIAM_STR( User_Name ); | |
465 break; | |
466 | |
467 /* | |
468 - If the RADIUS User-Password attribute is present, the password | |
469 must be unencrypted by using the link's RADIUS shared secret. | |
470 The unencrypted value must be forwarded in a User-Password AVP | |
471 using Diameter security. | |
472 */ | |
473 case RADIUS_ATTR_USER_PASSWORD: | |
474 if ((attr->length - 2) % 16) { | |
475 TRACE_DEBUG(INFO, "Invalid length of User-Password attribute: %hhd", attr->length); | |
476 return EINVAL; | |
477 } | |
478 { | |
479 /* Decipher following this logic (refers to rfc2865#section-5.2 ) | |
480 b1 = MD5(S + RA) p1 = c(1) xor b1 | |
481 b2 = MD5(S + c(1)) p2 = c(2) xor b2 | |
482 ... | |
483 */ | |
484 | |
485 uint8_t *ciph = (uint8_t *)(attr+1); /* c(i) */ | |
486 size_t ciph_len = attr->length - 2; | |
487 uint8_t deciph[128]; /* pi */ | |
488 size_t deciph_len = 0; | |
489 uint8_t * secret; /* S */ | |
490 size_t secret_len; | |
491 uint8_t hash[16]; /* b(i) */ | |
492 const uint8_t *addr[2]; | |
493 size_t len[2]; | |
494 | |
495 /* Retrieve the shared secret */ | |
496 CHECK_FCT(rgw_clients_getkey(cli, &secret, &secret_len)); | |
497 | |
498 /* Initial b1 = MD5(S + RA) */ | |
499 addr[0] = secret; | |
500 len[0] = secret_len; | |
501 addr[1] = rad_req->hdr->authenticator; | |
502 len[1] = 16; | |
503 md5_vector(2, addr, len, hash); | |
504 | |
505 /* loop */ | |
506 while (deciph_len < ciph_len) { | |
507 int i; | |
508 /* pi = c(i) xor bi */ | |
509 for (i = 0; i < 16; i++) | |
510 deciph[deciph_len + i] = ciph[deciph_len + i] ^ hash[i]; | |
511 /* do we have to remove the padding '\0's ? */ | |
512 | |
513 /* b(i+1) = MD5(S + c(i) */ | |
514 addr[1] = ciph + deciph_len; | |
515 md5_vector(2, addr, len, hash); | |
516 | |
517 deciph_len += 16; | |
518 } | |
519 | |
520 /* Now save this value in the AVP */ | |
521 CHECK_FCT( fd_msg_avp_new ( cs->dict.User_Password, 0, &avp ) ); | |
522 value.os.data = &deciph[0]; | |
523 value.os.len = deciph_len; | |
524 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); | |
525 CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_LAST_CHILD, avp) ); | |
526 } | |
527 break; | |
528 | |
529 | |
530 /* | |
531 - If the RADIUS CHAP-Password attribute is present, the Ident and | |
532 Data portion of the attribute are used to create the CHAP-Auth | |
533 grouped AVP. | |
534 */ | |
535 case RADIUS_ATTR_CHAP_PASSWORD: | |
536 CHECK_PARAMS( attr->length == 19 /* RFC 2865 */); | |
537 { | |
538 uint8_t * c = (uint8_t *)(attr + 1); | |
539 struct avp * chap_auth; | |
540 CHECK_FCT( fd_msg_avp_new ( cs->dict.CHAP_Auth, 0, &chap_auth ) ); | |
541 CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_LAST_CHILD, chap_auth) ); | |
542 | |
543 CHECK_FCT( fd_msg_avp_new ( cs->dict.CHAP_Algorithm, 0, &avp ) ); | |
544 value.u32 = 5; /* The only value defined currently... */ | |
545 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); | |
546 CHECK_FCT( fd_msg_avp_add ( chap_auth, MSG_BRW_LAST_CHILD, avp) ); | |
547 | |
548 CHECK_FCT( fd_msg_avp_new ( cs->dict.CHAP_Ident, 0, &avp ) ); | |
549 value.os.data = c; | |
550 value.os.len = 1; | |
551 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); | |
552 CHECK_FCT( fd_msg_avp_add ( chap_auth, MSG_BRW_LAST_CHILD, avp) ); | |
553 | |
554 c++; | |
555 | |
556 CHECK_FCT( fd_msg_avp_new ( cs->dict.CHAP_Response, 0, &avp ) ); | |
557 value.os.data = c; | |
558 value.os.len = attr->length - 3; | |
559 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); | |
560 CHECK_FCT( fd_msg_avp_add ( chap_auth, MSG_BRW_LAST_CHILD, avp) ); | |
561 } | |
562 break; | |
563 | |
564 case RADIUS_ATTR_NAS_IP_ADDRESS: | |
565 CONV2DIAM_STR( NAS_IP_Address ); | |
566 break; | |
567 | |
568 case RADIUS_ATTR_NAS_PORT: | |
569 CONV2DIAM_32B( NAS_Port ); | |
570 break; | |
571 | |
572 case RADIUS_ATTR_SERVICE_TYPE: | |
573 CONV2DIAM_32B( Service_Type ); | |
574 break; | |
575 | |
576 case RADIUS_ATTR_FRAMED_PROTOCOL: | |
577 CONV2DIAM_32B( Framed_Protocol ); | |
578 break; | |
579 | |
580 case RADIUS_ATTR_FRAMED_IP_ADDRESS: | |
581 CONV2DIAM_STR( Framed_IP_Address ); | |
582 break; | |
583 | |
584 case RADIUS_ATTR_FRAMED_IP_NETMASK: | |
585 CONV2DIAM_STR( Framed_IP_Netmask ); | |
586 break; | |
587 | |
588 /* Framed-Routing never present in an Access-Request */ | |
589 /* Filter-Id never present in an Access-Request */ | |
590 | |
591 case RADIUS_ATTR_FRAMED_MTU: | |
592 CONV2DIAM_32B( Framed_MTU ); | |
593 break; | |
594 | |
595 case RADIUS_ATTR_FRAMED_COMPRESSION: | |
596 CONV2DIAM_32B( Framed_Compression ); | |
597 break; | |
598 | |
599 case RADIUS_ATTR_LOGIN_IP_HOST: | |
600 CONV2DIAM_STR( Login_IP_Host ); | |
601 break; | |
602 | |
603 /* Login-Service never present in an Access-Request */ | |
604 /* Login-TCP-Port never present in an Access-Request */ | |
605 /* Reply-Message never present in an Access-Request */ | |
606 | |
607 case RADIUS_ATTR_CALLBACK_NUMBER: | |
608 CONV2DIAM_STR( Callback_Number ); | |
609 break; | |
610 | |
611 /* Callback-Id never present in an Access-Request */ | |
612 /* Framed-Route never present in an Access-Request */ | |
613 /* Framed-IPX-Network never present in an Access-Request */ | |
614 | |
615 case RADIUS_ATTR_STATE: | |
616 CONV2DIAM_STR( State ); | |
617 break; | |
618 | |
619 /* Class never present in an Access-Request */ | |
620 | |
621 case RADIUS_ATTR_VENDOR_SPECIFIC: | |
622 /* RFC 4005, Section 9.6 : | |
623 Systems that don't have vendor format knowledge MAY discard such | |
624 attributes without knowing a suitable translation. | |
625 | |
626 [conversion rule in 9.6.2] | |
627 */ | |
628 if (attr->length >= 6) { | |
629 uint32_t vendor_id; | |
630 uint8_t * c = (uint8_t *)(attr + 1); | |
631 | |
632 vendor_id = c[0] << 24 | c[1] << 16 | c[2] << 8 | c[3]; | |
633 c += 4; | |
634 | |
635 switch (vendor_id) { | |
636 | |
637 /* For the vendors we KNOW they follow the VSA recommended format, we convert following the rules of RFC4005 (9.6.2) */ | |
638 case RADIUS_VENDOR_ID_MICROSOFT : /* RFC 2548 */ | |
639 /* other vendors ? */ | |
640 { | |
641 size_t left; | |
642 struct radius_attr_vendor *vtlv; | |
643 | |
644 left = attr->length - 6; | |
645 vtlv = (struct radius_attr_vendor *)c; | |
646 | |
647 while ((left >= 2) && (vtlv->vendor_length <= left)) { | |
648 /* Search our dictionary for corresponding Vendor's AVP */ | |
649 struct dict_avp_request req; | |
650 struct dict_object * avp_model = NULL; | |
651 memset(&req, 0, sizeof(struct dict_avp_request)); | |
652 req.avp_vendor = vendor_id; | |
653 req.avp_code = vtlv->vendor_type; | |
654 | |
655 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_CODE_AND_VENDOR, &req, &avp_model, 0) ); | |
656 if (!avp_model) { | |
657 TRACE_DEBUG(FULL, "Unknown attribute (vendor 0x%x, code 0x%x) ignored.", req.avp_vendor, req.avp_code); | |
658 } else { | |
659 CHECK_FCT( fd_msg_avp_new ( avp_model, 0, &avp ) ); | |
660 value.os.len = vtlv->vendor_length - 2; | |
661 value.os.data = (unsigned char *)(vtlv + 1); | |
662 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); | |
663 CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_LAST_CHILD, avp) ); | |
664 } | |
665 c += vtlv->vendor_length; | |
666 left -= vtlv->vendor_length; | |
667 vtlv = (struct radius_attr_vendor *)c; | |
668 } | |
669 } | |
670 break; | |
671 | |
672 /* Other vendors we KNOw how to convert the attributes would be added here... */ | |
673 /* case RADIUS_VENDOR_ID_CISCO : | |
674 break; */ | |
675 /* case RADIUS_VENDOR_ID_IETF : (extended RADIUS attributes) | |
676 break; */ | |
677 | |
678 /* When we don't know, just discard the attribute... VSA are optional with regards to RADIUS anyway */ | |
679 default: | |
680 /* do nothing */ | |
681 TRACE_DEBUG(FULL, "VSA attribute from vendor %d discarded", vendor_id); | |
682 | |
683 } | |
684 } | |
685 break; | |
686 | |
687 /* Session-Timeout never present in an Access-Request */ | |
688 /* Idle-Timeout never present in an Access-Request */ | |
689 /* Termination-Action never present in an Access-Request */ | |
690 | |
691 case RADIUS_ATTR_CALLED_STATION_ID: | |
692 CONV2DIAM_STR( Called_Station_Id ); | |
693 break; | |
694 | |
695 case RADIUS_ATTR_CALLING_STATION_ID: | |
696 CONV2DIAM_STR( Calling_Station_Id ); | |
697 break; | |
698 | |
699 case RADIUS_ATTR_NAS_IDENTIFIER: | |
700 CONV2DIAM_STR( NAS_Identifier ); | |
701 break; | |
702 | |
703 /* Proxy-State is handled by echo_drop.rgwx plugin, we ignore it here */ | |
704 | |
705 case RADIUS_ATTR_LOGIN_LAT_SERVICE: | |
706 CONV2DIAM_STR( Login_LAT_Service ); | |
707 break; | |
708 | |
709 case RADIUS_ATTR_LOGIN_LAT_NODE: | |
710 CONV2DIAM_STR( Login_LAT_Node ); | |
711 break; | |
712 | |
713 case RADIUS_ATTR_LOGIN_LAT_GROUP: | |
714 CONV2DIAM_STR( Login_LAT_Group ); | |
715 break; | |
716 | |
717 /* Framed-AppleTalk-Link never present in an Access-Request */ | |
718 /* Framed-AppleTalk-Network never present in an Access-Request */ | |
719 /* Framed-AppleTalk-Zone never present in an Access-Request */ | |
720 | |
721 case RADIUS_ATTR_CHAP_CHALLENGE: | |
722 CONV2DIAM_STR( CHAP_Challenge ); | |
723 break; | |
724 | |
725 case RADIUS_ATTR_NAS_PORT_TYPE: | |
726 CONV2DIAM_32B( NAS_Port_Type ); | |
727 break; | |
728 | |
729 case RADIUS_ATTR_PORT_LIMIT: | |
730 CONV2DIAM_32B( Port_Limit ); | |
731 break; | |
732 | |
733 case RADIUS_ATTR_LOGIN_LAT_PORT: | |
734 CONV2DIAM_STR( Login_LAT_Port ); | |
735 break; | |
736 | |
737 | |
738 /* RFC 3162 */ | |
739 case RADIUS_ATTR_NAS_IPV6_ADDRESS: | |
740 CONV2DIAM_STR( NAS_IPv6_Address ); | |
741 break; | |
742 | |
743 case RADIUS_ATTR_FRAMED_INTERFACE_ID: | |
744 CONV2DIAM_64B( Framed_Interface_Id ); | |
745 break; | |
746 | |
747 case RADIUS_ATTR_FRAMED_IPV6_PREFIX: | |
748 CONV2DIAM_STR( Framed_IPv6_Prefix ); | |
749 break; | |
750 | |
751 case RADIUS_ATTR_LOGIN_IPV6_HOST: | |
752 CONV2DIAM_STR( Login_IPv6_Host ); | |
753 break; | |
754 | |
755 /* Framed-IPv6-Route never present in an Access-Request */ | |
756 /* Framed-IPv6-Pool never present in an Access-Request */ | |
757 | |
758 | |
759 /* RFC 2868 */ | |
760 /* Prepare the top-level Tunneling AVP for each tag values, as needed, and add to the Diameter message. | |
761 This macro is called when an AVP is added inside the group, so we will not have empty grouped AVPs */ | |
762 #define AVP_TUN_PREPARE() { \ | |
763 if (avp_tun == NULL) { \ | |
764 CHECK_MALLOC( avp_tun = calloc(sizeof(struct avp *), 32 ) ); \ | |
765 } \ | |
766 tag = *(uint8_t *)(attr + 1); \ | |
767 if (tag > 0x1F) tag = 0; \ | |
768 if (avp_tun[tag] == NULL) { \ | |
271
411314907b43
Added translation of Accounting messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
264
diff
changeset
|
769 CHECK_FCT( fd_msg_avp_new ( cs->dict.Tunneling, 0, &avp_tun[tag] ) ); \ |
256 | 770 CHECK_FCT( fd_msg_avp_add (*diam_fw, MSG_BRW_LAST_CHILD, avp_tun[tag]));\ |
771 } \ | |
772 } | |
773 | |
774 /* Convert an attribute to an OctetString AVP and add inside the Tunneling AVP corresponding to the tag */ | |
271
411314907b43
Added translation of Accounting messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
264
diff
changeset
|
775 #define CONV2DIAM_TUN_STR( _dictobj_ ) { \ |
256 | 776 uint8_t tag; \ |
777 CHECK_PARAMS( attr->length >= 3); \ | |
778 AVP_TUN_PREPARE(); \ | |
779 CHECK_FCT( fd_msg_avp_new ( cs->dict._dictobj_, 0, &avp ) ); \ | |
780 value.os.len = attr->length - (tag ? 3 : 2); \ | |
781 value.os.data = ((unsigned char *)(attr + 1)) + (tag ? 1 : 0); \ | |
782 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); \ | |
783 CHECK_FCT( fd_msg_avp_add ( avp_tun[tag], MSG_BRW_LAST_CHILD, avp) ); \ | |
784 } | |
785 | |
786 /* Convert an attribute to a scalar AVP and add inside the Tunneling AVP corresponding to the tag */ | |
271
411314907b43
Added translation of Accounting messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
264
diff
changeset
|
787 #define CONV2DIAM_TUN_24B( _dictobj_ ) { \ |
256 | 788 uint8_t tag; \ |
789 CHECK_PARAMS( attr->length == 6); \ | |
790 AVP_TUN_PREPARE(); \ | |
791 CHECK_FCT( fd_msg_avp_new ( cs->dict._dictobj_, 0, &avp ) ); \ | |
792 { \ | |
793 uint8_t * v = (uint8_t *)(attr + 1); \ | |
794 value.u32 = (v[1] << 16) | (v[2] <<8) | v[3] ; \ | |
795 } \ | |
796 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); \ | |
797 CHECK_FCT( fd_msg_avp_add ( avp_tun[tag], MSG_BRW_LAST_CHILD, avp) ); \ | |
798 } | |
799 | |
800 /* | |
801 - If the RADIUS message contains Tunnel information [RADTunnels], | |
802 the attributes or tagged groups should each be converted to a | |
803 Diameter Tunneling Grouped AVP set. If the tunnel information | |
804 contains a Tunnel-Password attribute, the RADIUS encryption | |
805 must be resolved, and the password forwarded, by using Diameter | |
806 security methods. | |
807 -> If the RADIUS message does not use properly the Tag info, result is unpredictable here.. | |
808 */ | |
809 case RADIUS_ATTR_TUNNEL_TYPE: | |
810 CONV2DIAM_TUN_24B( Tunnel_Type ); | |
811 break; | |
812 | |
813 case RADIUS_ATTR_TUNNEL_MEDIUM_TYPE: | |
814 CONV2DIAM_TUN_24B( Tunnel_Medium_Type ); | |
815 break; | |
816 | |
817 case RADIUS_ATTR_TUNNEL_CLIENT_ENDPOINT: | |
818 CONV2DIAM_TUN_STR( Tunnel_Client_Endpoint ); | |
819 break; | |
820 | |
821 case RADIUS_ATTR_TUNNEL_SERVER_ENDPOINT: | |
822 CONV2DIAM_TUN_STR( Tunnel_Server_Endpoint ); | |
823 break; | |
824 | |
825 /* Tunnel-Password never present in an Access-Request */ | |
826 | |
827 case RADIUS_ATTR_TUNNEL_PRIVATE_GROUP_ID: | |
828 CONV2DIAM_TUN_STR( Tunnel_Private_Group_Id ); | |
829 break; | |
830 | |
831 /* Tunnel-Assignment-ID never present in an Access-Request */ | |
832 | |
833 case RADIUS_ATTR_TUNNEL_PREFERENCE: | |
834 CONV2DIAM_TUN_24B( Tunnel_Preference ); | |
835 break; | |
836 | |
837 case RADIUS_ATTR_TUNNEL_CLIENT_AUTH_ID: | |
838 CONV2DIAM_TUN_STR( Tunnel_Client_Auth_Id ); | |
839 break; | |
840 | |
841 case RADIUS_ATTR_TUNNEL_SERVER_AUTH_ID: | |
842 CONV2DIAM_TUN_STR( Tunnel_Server_Auth_Id ); | |
843 break; | |
844 | |
845 | |
846 /* RFC 2869 */ | |
847 case RADIUS_ATTR_ARAP_PASSWORD: | |
848 CONV2DIAM_STR( ARAP_Password ); | |
849 break; | |
850 | |
851 /* ARAP-Features never present in an Access-Request */ | |
852 /* ARAP-Zone-Access never present in an Access-Request */ | |
853 | |
854 case RADIUS_ATTR_ARAP_SECURITY: | |
855 CONV2DIAM_32B( ARAP_Security ); | |
856 break; | |
857 | |
858 case RADIUS_ATTR_ARAP_SECURITY_DATA: | |
859 CONV2DIAM_STR( ARAP_Security_Data ); | |
860 break; | |
861 | |
862 /* Password-Retry never present in an Access-Request */ | |
863 /* Prompt never present in an Access-Request */ | |
864 | |
865 case RADIUS_ATTR_CONNECT_INFO: | |
866 CONV2DIAM_STR( Connect_Info ); | |
867 break; | |
868 | |
869 /* Configuration-Token never present in an Access-Request */ | |
870 /* ARAP-Challenge-Response never present in an Access-Request */ | |
871 /* Acct-Interim-Interval never present in an Access-Request */ | |
872 | |
873 case RADIUS_ATTR_NAS_PORT_ID: | |
874 CONV2DIAM_STR( NAS_Port_Id ); | |
875 break; | |
876 | |
877 /* Framed-Pool never present in an Access-Request */ | |
878 | |
879 | |
880 /* RFC 2869 / 3579 */ | |
881 case RADIUS_ATTR_ORIGINATING_LINE_INFO: | |
882 CONV2DIAM_STR( Originating_Line_Info ); | |
883 break; | |
884 | |
885 case RADIUS_ATTR_MESSAGE_AUTHENTICATOR: | |
886 case RADIUS_ATTR_EAP_MESSAGE: | |
887 /* It was already handled, just remove the attribute */ | |
888 break; | |
889 | |
890 /* Default */ | |
891 default: /* unknown attribute */ | |
892 /* We just keep the attribute in the RADIUS message */ | |
893 rad_req->attr_pos[nattr_used++] = rad_req->attr_pos[idx]; | |
894 } | |
895 } | |
896 | |
897 /* Destroy tunnel pointers (if we used it) */ | |
898 free(avp_tun); | |
899 | |
900 /* Update the radius message to remove all handled attributes */ | |
901 rad_req->attr_used = nattr_used; | |
902 | |
903 /* Store the request identifier in the session (if provided) */ | |
904 if (session) { | |
905 unsigned char * req_auth; | |
906 CHECK_MALLOC(req_auth = malloc(16)); | |
907 memcpy(req_auth, &rad_req->hdr->authenticator[0], 16); | |
908 | |
909 CHECK_FCT( fd_sess_state_store( cs->sess_hdl, session, &req_auth ) ); | |
910 } | |
911 | |
912 return 0; | |
913 } | |
914 | |
915 static int auth_diam_ans( struct rgwp_config * cs, struct session * session, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli ) | |
916 { | |
917 struct avp *avp, *next, *avp_x, *avp_y, *asid, *aoh; | |
918 struct avp_hdr *ahdr, *sid, *oh; | |
919 char buf[254]; /* to store some attributes values (with final '\0') */ | |
920 int ta_set = 0; | |
921 uint8_t tuntag = 0; | |
922 unsigned char * req_auth = NULL; | |
923 | |
924 TRACE_ENTRY("%p %p %p %p %p", cs, session, diam_ans, rad_fw, cli); | |
925 CHECK_PARAMS(cs && session && diam_ans && *diam_ans && rad_fw && *rad_fw); | |
926 | |
927 /* Retrieve the request identified which was stored in the session */ | |
928 if (session) { | |
929 CHECK_FCT( fd_sess_state_retrieve( cs->sess_hdl, session, &req_auth ) ); | |
930 } | |
931 | |
932 /* | |
933 - If the Diameter Command-Code is set to AA-Answer and the | |
934 Result-Code AVP is set to DIAMETER_MULTI_ROUND_AUTH, the | |
935 gateway must send a RADIUS Access-Challenge. This must have | |
936 the Origin-Host, Origin-Realm, and Diameter Session-Id AVPs | |
937 encapsulated in the RADIUS State attribute, with the prefix | |
938 "Diameter/", concatenated in the above order separated with "/" | |
939 characters, in UTF-8 [UTF-8]. This is necessary to ensure that | |
940 the Translation Agent receiving the subsequent RADIUS Access- | |
941 Request will have access to the Session Identifier and be able | |
942 to set the Destination-Host to the correct value. | |
943 -> done here bellow | |
944 | |
945 - If the Command-Code is set to AA-Answer, the Diameter Session- | |
946 Id AVP is saved in a new RADIUS Class attribute whose format | |
947 consists of the string "Diameter/" followed by the Diameter | |
948 Session Identifier. This will ensure that the subsequent | |
949 Accounting messages, which could be received by any Translation | |
950 Agent, would have access to the original Diameter Session | |
951 Identifier. | |
952 -> done here but only for Access-Accept messages (Result-Code = success) | |
953 */ | |
954 | |
955 /* MACROS to help in the process: convert AVP data to RADIUS attributes. */ | |
956 /* Control large attributes: _trunc_ = 0 => error; _trunc_ = 1 => truncate; _trunc = 2 => create several attributes */ | |
957 #define CONV2RAD_STR( _attr_, _data_, _len_, _trunc_) { \ | |
958 size_t __l = (size_t)(_len_); \ | |
959 size_t __off = 0; \ | |
960 TRACE_DEBUG(FULL, "Converting AVP to "#_attr_); \ | |
961 if ((_trunc_) == 0) { \ | |
962 CHECK_PARAMS( __l <= 253 ); \ | |
963 } \ | |
964 if ((__l > 253) && (_trunc_ == 1)) { \ | |
965 TRACE_DEBUG(INFO, "[auth.rgwx] AVP truncated in "#_attr_); \ | |
966 __l = 253; \ | |
967 } \ | |
968 do { \ | |
969 size_t __w = (__l > 253) ? 253 : __l; \ | |
970 CHECK_MALLOC(radius_msg_add_attr(*rad_fw, (_attr_), (_data_) + __off, __w)); \ | |
971 __off += __w; \ | |
972 __l -= __w; \ | |
973 } while (__l); \ | |
974 } | |
975 | |
976 #define CONV2RAD_32B( _attr_, _data_) { \ | |
977 uint32_t __v = htonl((uint32_t)(_data_)); \ | |
978 TRACE_DEBUG(FULL, "Converting AVP to "#_attr_); \ | |
979 CHECK_MALLOC(radius_msg_add_attr(*rad_fw, (_attr_), (uint8_t *)&__v, sizeof(__v))); \ | |
980 } | |
981 | |
982 #define CONV2RAD_64B( _attr_, _data_) { \ | |
983 uint64_t __v = htonll((uint64_t)(_data_)); \ | |
984 TRACE_DEBUG(FULL, "Converting AVP to "#_attr_); \ | |
985 CHECK_MALLOC(radius_msg_add_attr(*rad_fw, (_attr_), (uint8_t *)&__v, sizeof(__v))); \ | |
986 } | |
987 | |
988 /* Search the different AVPs we handle here */ | |
989 CHECK_FCT( fd_msg_search_avp (*diam_ans, cs->dict.Session_Id, &asid) ); | |
990 CHECK_FCT( fd_msg_avp_hdr ( asid, &sid ) ); | |
991 CHECK_FCT( fd_msg_search_avp (*diam_ans, cs->dict.Origin_Host, &aoh) ); | |
992 CHECK_FCT( fd_msg_avp_hdr ( aoh, &oh ) ); | |
993 | |
994 /* Check the Diameter error code */ | |
995 CHECK_FCT( fd_msg_search_avp (*diam_ans, cs->dict.Result_Code, &avp) ); | |
996 ASSERT( avp ); /* otherwise the message should have been discarded a lot earlier because of ABNF */ | |
997 CHECK_FCT( fd_msg_avp_hdr ( avp, &ahdr ) ); | |
998 switch (ahdr->avp_value->u32) { | |
999 case ER_DIAMETER_MULTI_ROUND_AUTH: | |
1000 (*rad_fw)->hdr->code = RADIUS_CODE_ACCESS_CHALLENGE; | |
1001 break; | |
1002 case ER_DIAMETER_SUCCESS: | |
1003 case ER_DIAMETER_LIMITED_SUCCESS: | |
1004 (*rad_fw)->hdr->code = RADIUS_CODE_ACCESS_ACCEPT; | |
1005 break; | |
1006 | |
1007 default: | |
1008 (*rad_fw)->hdr->code = RADIUS_CODE_ACCESS_REJECT; | |
1009 fd_log_debug("[auth.rgwx] Received Diameter answer with error code '%d' from server '%.*s', session %.*s, translating into Access-Reject\n", | |
1010 ahdr->avp_value->u32, | |
1011 oh->avp_value->os.len, oh->avp_value->os.data, | |
1012 sid->avp_value->os.len, sid->avp_value->os.data); | |
1013 CHECK_FCT( fd_msg_search_avp (*diam_ans, cs->dict.Error_Message, &avp) ); | |
1014 if (avp) { | |
1015 CHECK_FCT( fd_msg_avp_hdr ( avp, &ahdr ) ); | |
1016 fd_log_debug("[auth.rgwx] Error-Message content: '%.*s'\n", | |
1017 ahdr->avp_value->os.len, ahdr->avp_value->os.data); | |
1018 } | |
1019 CHECK_FCT( fd_msg_search_avp (*diam_ans, cs->dict.Error_Reporting_Host, &avp) ); | |
1020 if (avp) { | |
1021 CHECK_FCT( fd_msg_avp_hdr ( avp, &ahdr ) ); | |
1022 fd_log_debug("[auth.rgwx] Error-Reporting-Host: '%.*s'\n", | |
1023 ahdr->avp_value->os.len, ahdr->avp_value->os.data); | |
1024 } | |
1025 CHECK_FCT( fd_msg_search_avp (*diam_ans, cs->dict.Failed_AVP, &avp) ); | |
1026 if (avp) { | |
1027 fd_log_debug("[auth.rgwx] Failed-AVP was included in the message.\n"); | |
1028 /* Dump its content ? */ | |
1029 } | |
1030 return 0; | |
1031 } | |
1032 /* Remove this Result-Code avp */ | |
1033 CHECK_FCT( fd_msg_free( avp ) ); | |
1034 | |
1035 /* Creation of the State or Class attribute with session information */ | |
1036 CHECK_FCT( fd_msg_search_avp (*diam_ans, cs->dict.Origin_Realm, &avp) ); | |
1037 CHECK_FCT( fd_msg_avp_hdr ( avp, &ahdr ) ); | |
1038 | |
1039 /* Now, save the session-id and eventually server info in a STATE or CLASS attribute */ | |
1040 if ((*rad_fw)->hdr->code == RADIUS_CODE_ACCESS_CHALLENGE) { | |
1041 if (sizeof(buf) < snprintf(buf, sizeof(buf), "Diameter/%.*s/%.*s/%.*s", | |
1042 oh->avp_value->os.len, oh->avp_value->os.data, | |
1043 ahdr->avp_value->os.len, ahdr->avp_value->os.data, | |
1044 sid->avp_value->os.len, sid->avp_value->os.data)) { | |
1045 TRACE_DEBUG(INFO, "Data truncated in State attribute: %s", buf); | |
1046 } | |
1047 CONV2RAD_STR(RADIUS_ATTR_STATE, buf, strlen(buf), 0); | |
1048 } | |
1049 /* The RFC text says that this should always be the case, but it seems odd... */ | |
1050 if ((*rad_fw)->hdr->code == RADIUS_CODE_ACCESS_ACCEPT) { | |
1051 if (sizeof(buf) < snprintf(buf, sizeof(buf), "Diameter/%.*s", | |
1052 sid->avp_value->os.len, sid->avp_value->os.data)) { | |
1053 TRACE_DEBUG(INFO, "Data truncated in Class attribute: %s", buf); | |
1054 } | |
1055 CONV2RAD_STR(RADIUS_ATTR_CLASS, buf, strlen(buf), 0); | |
1056 } | |
1057 | |
1058 /* Unlink the Origin-Realm now; the others are unlinked at the end of this function */ | |
1059 CHECK_FCT( fd_msg_free( avp ) ); | |
1060 | |
1061 CHECK_FCT( fd_msg_search_avp (*diam_ans, cs->dict.Session_Timeout, &avp) ); | |
1062 CHECK_FCT( fd_msg_search_avp (*diam_ans, cs->dict.Authorization_Lifetime, &avp_x) ); | |
1063 CHECK_FCT( fd_msg_search_avp (*diam_ans, cs->dict.Re_Auth_Request_Type, &avp_y) ); | |
1064 /* | |
1065 When translating a Diameter AA-Answer (with successful result code) | |
1066 to RADIUS Access-Accept that contains a Session-Timeout or | |
1067 Authorization-Lifetime AVP, take the following steps: | |
1068 | |
1069 - If the Diameter message contains a Session-Timeout AVP but no | |
1070 Authorization-Lifetime AVP, translate it to a Session-Timeout | |
1071 attribute (not a Termination-Action). | |
1072 */ | |
1073 if ((avp != NULL) && (avp_x == NULL)) { | |
1074 CHECK_FCT( fd_msg_avp_hdr ( avp, &ahdr ) ); | |
1075 CONV2RAD_32B( RADIUS_ATTR_SESSION_TIMEOUT, ahdr->avp_value->u32 ); | |
1076 } | |
1077 | |
1078 /* | |
1079 - If the Diameter message contains an Authorization-Lifetime AVP | |
1080 but no Session-Timeout AVP, translate it to a Session-Timeout | |
1081 attribute and a Termination-Action set to AA-REQUEST. (Remove | |
1082 Authorization-Lifetime and Re-Auth-Request-Type.) | |
1083 */ | |
1084 if ((avp == NULL) && (avp_x != NULL)) { | |
1085 CHECK_FCT( fd_msg_avp_hdr ( avp_x, &ahdr ) ); | |
1086 CONV2RAD_32B( RADIUS_ATTR_SESSION_TIMEOUT, ahdr->avp_value->u32 ); | |
1087 CONV2RAD_32B( RADIUS_ATTR_TERMINATION_ACTION, RADIUS_TERMINATION_ACTION_RADIUS_REQUEST ); | |
1088 ta_set = 1; | |
1089 } | |
1090 | |
1091 /* | |
1092 - If the Diameter message has both, the Session-Timeout must be | |
1093 greater than or equal to the Authorization-Lifetime (required | |
1094 by [BASE]). Translate it to a Session-Timeout value (with | |
1095 value from Authorization-Lifetime AVP, the smaller one) and | |
1096 with the Termination-Action set to AA-REQUEST. (Remove the | |
1097 Authorization-Lifetime and Re-Auth-Request-Type.) | |
1098 */ | |
1099 if ((avp != NULL) && (avp_x != NULL)) { | |
1100 CHECK_FCT( fd_msg_avp_hdr ( avp_x, &ahdr ) ); | |
1101 CONV2RAD_32B( RADIUS_ATTR_SESSION_TIMEOUT, ahdr->avp_value->u32 ); | |
1102 CONV2RAD_32B( RADIUS_ATTR_TERMINATION_ACTION, RADIUS_TERMINATION_ACTION_RADIUS_REQUEST ); | |
1103 ta_set = 1; | |
1104 } | |
1105 | |
1106 /* -> Not too sure about Auth-Grace-Period... we'll just discard it for now */ | |
1107 | |
1108 if (avp) { | |
1109 CHECK_FCT( fd_msg_free( avp ) ); | |
1110 } | |
1111 if (avp_x) { | |
1112 CHECK_FCT( fd_msg_free( avp_x ) ); | |
1113 } | |
1114 if (avp_y) { | |
1115 CHECK_FCT( fd_msg_free( avp_y ) ); | |
1116 } | |
1117 | |
1118 | |
1119 /* | |
1120 - If a Proxy-State attribute was present in the RADIUS request, | |
1121 the same attribute is added in the response. This information | |
1122 may be found in the Proxy-Info AVP group, or in a local state | |
1123 table. | |
1124 -> handled by sub_echo_drop | |
1125 | |
1126 - If state information regarding the RADIUS request was saved in | |
1127 a Proxy-Info AVP or local state table, the RADIUS Identifier | |
1128 and UDP IP Address and port number are extracted and used in | |
1129 issuing the RADIUS reply. | |
1130 -> was saved with the full request | |
1131 */ | |
1132 | |
1133 | |
1134 /* Now loop in the list of AVPs and convert those that we know how */ | |
1135 CHECK_FCT( fd_msg_browse(*diam_ans, MSG_BRW_FIRST_CHILD, &next, NULL) ); | |
1136 | |
1137 while (next) { | |
1138 int handled = 1; | |
1139 avp = next; | |
1140 CHECK_FCT( fd_msg_browse(avp, MSG_BRW_NEXT, &next, NULL) ); | |
1141 | |
1142 CHECK_FCT( fd_msg_avp_hdr ( avp, &ahdr ) ); | |
1143 | |
1144 if (!(ahdr->avp_flags & AVP_FLAG_VENDOR)) { | |
1145 switch (ahdr->avp_code) { | |
1146 | |
1147 /* RFC 4005 (AVP in the order of the AA-Request/Answer AVP Table) */ | |
1148 case DIAM_ATTR_ACCT_INTERIM_INTERVAL: | |
1149 CONV2RAD_32B(RADIUS_ATTR_ACCT_INTERIM_INTERVAL, ahdr->avp_value->u32); | |
1150 break; | |
1151 | |
1152 case DIAM_ATTR_ARAP_CHALLENGE_RESPONSE: | |
1153 CONV2RAD_STR(RADIUS_ATTR_ARAP_CHALLENGE_RESPONSE, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 0); | |
1154 break; | |
1155 | |
1156 case DIAM_ATTR_ARAP_FEATURES: | |
1157 CONV2RAD_STR(RADIUS_ATTR_ARAP_FEATURES, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 0); | |
1158 break; | |
1159 | |
1160 /* ARAP-Password is not present in answers */ | |
1161 | |
1162 case DIAM_ATTR_ARAP_SECURITY: | |
1163 CONV2RAD_32B(RADIUS_ATTR_ARAP_SECURITY, ahdr->avp_value->u32); | |
1164 break; | |
1165 | |
1166 case DIAM_ATTR_ARAP_SECURITY_DATA: | |
1167 CONV2RAD_STR(RADIUS_ATTR_ARAP_SECURITY_DATA, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 2); | |
1168 break; | |
1169 | |
1170 case DIAM_ATTR_ARAP_ZONE_ACCESS: | |
1171 CONV2RAD_32B(RADIUS_ATTR_ARAP_ZONE_ACCESS, ahdr->avp_value->u32); | |
1172 break; | |
1173 | |
1174 case DIAM_ATTR_AUTH_APPLICATION_ID: | |
1175 /* We just remove this AVP */ | |
1176 break; | |
1177 | |
1178 case DIAM_ATTR_AUTH_GRACE_PERIOD: | |
1179 /* We just remove this AVP (?) */ | |
1180 break; | |
1181 | |
1182 case DIAM_ATTR_AUTH_REQUEST_TYPE: | |
1183 /* We only check the value */ | |
1184 if (ahdr->avp_value->u32 != 3) { | |
1185 fd_log_debug("[auth.rgwx] Received Diameter answer with Auth-Request-Type set to %d (%s) from server %.*s, session %.*s.\n" | |
1186 " This may cause interoperability problems with RADIUS.\n", | |
1187 ahdr->avp_value->u32, | |
1188 (ahdr->avp_value->u32 == 1) ? "AUTHENTICATE_ONLY" : | |
1189 ((ahdr->avp_value->u32 == 2) ? "AUTHORIZE_ONLY" : "???"), | |
1190 oh->avp_value->os.len, oh->avp_value->os.data, | |
1191 sid->avp_value->os.len, sid->avp_value->os.len); | |
1192 } | |
1193 break; | |
1194 | |
1195 case DIAM_ATTR_AUTH_SESSION_STATE: | |
1196 if ((!ta_set) && (ahdr->avp_value->u32 == ACV_ASS_STATE_MAINTAINED)) { | |
1197 CONV2RAD_32B( RADIUS_ATTR_TERMINATION_ACTION, RADIUS_TERMINATION_ACTION_RADIUS_REQUEST ); | |
1198 } | |
1199 break; | |
1200 | |
1201 /* Authorization-Lifetime already handled */ | |
1202 | |
1203 case DIAM_ATTR_CALLBACK_ID: | |
1204 CONV2RAD_STR(RADIUS_ATTR_CALLBACK_ID, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 1); | |
1205 break; | |
1206 | |
1207 case DIAM_ATTR_CALLBACK_NUMBER: | |
1208 CONV2RAD_STR(RADIUS_ATTR_CALLBACK_NUMBER, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 1); | |
1209 break; | |
1210 | |
1211 /* Called-Station-Id is not present in answers */ | |
1212 /* Calling-Station-Id is not present in answers */ | |
1213 /* CHAP-Auth is not present in answers */ | |
1214 /* CHAP-Challenge is not present in answers */ | |
1215 | |
1216 case DIAM_ATTR_CLASS: | |
1217 CONV2RAD_STR(RADIUS_ATTR_CLASS, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 2); | |
1218 break; | |
1219 | |
1220 case DIAM_ATTR_CONFIGURATION_TOKEN: | |
1221 /* We might as well remove it since it's not supposed to be sent to the NAS... */ | |
1222 CONV2RAD_STR(RADIUS_ATTR_CONFIGURATION_TOKEN, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 2); | |
1223 break; | |
1224 | |
1225 /* Connect-Info is not present in answers */ | |
1226 | |
1227 case DIAM_ATTR_FILTER_ID: | |
1228 CONV2RAD_STR(RADIUS_ATTR_FILTER_ID, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 2); | |
1229 break; | |
1230 | |
1231 case DIAM_ATTR_FRAMED_APPLETALK_LINK: | |
1232 CONV2RAD_32B(RADIUS_ATTR_FRAMED_APPLETALK_LINK, ahdr->avp_value->u32); | |
1233 break; | |
1234 | |
1235 case DIAM_ATTR_FRAMED_APPLETALK_NETWORK: | |
1236 CONV2RAD_32B(RADIUS_ATTR_FRAMED_APPLETALK_NETWORK, ahdr->avp_value->u32); | |
1237 break; | |
1238 | |
1239 case DIAM_ATTR_FRAMED_APPLETALK_ZONE: | |
1240 CONV2RAD_STR(RADIUS_ATTR_FRAMED_APPLETALK_ZONE, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 1); | |
1241 break; | |
1242 | |
1243 case DIAM_ATTR_FRAMED_COMPRESSION: | |
1244 CONV2RAD_32B(RADIUS_ATTR_FRAMED_COMPRESSION, ahdr->avp_value->u32); | |
1245 break; | |
1246 | |
1247 case DIAM_ATTR_FRAMED_INTERFACE_ID: | |
1248 CONV2RAD_64B(RADIUS_ATTR_FRAMED_INTERFACE_ID, ahdr->avp_value->u64); | |
1249 break; | |
1250 | |
1251 case DIAM_ATTR_FRAMED_IP_ADDRESS: | |
1252 CONV2RAD_STR(RADIUS_ATTR_FRAMED_IP_ADDRESS, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 0); | |
1253 break; | |
1254 | |
1255 case DIAM_ATTR_FRAMED_IP_NETMASK: | |
1256 CONV2RAD_STR(RADIUS_ATTR_FRAMED_IP_NETMASK, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 0); | |
1257 break; | |
1258 | |
1259 case DIAM_ATTR_FRAMED_IPV6_PREFIX: | |
1260 CONV2RAD_STR(RADIUS_ATTR_FRAMED_IPV6_PREFIX, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 0); | |
1261 break; | |
1262 | |
1263 case DIAM_ATTR_FRAMED_IPV6_POOL: | |
1264 CONV2RAD_STR(RADIUS_ATTR_FRAMED_IPV6_POOL, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 1); | |
1265 break; | |
1266 | |
1267 case DIAM_ATTR_FRAMED_IPV6_ROUTE: | |
1268 CONV2RAD_STR(RADIUS_ATTR_FRAMED_IPV6_ROUTE, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 1); | |
1269 break; | |
1270 | |
1271 case DIAM_ATTR_FRAMED_IPX_NETWORK: | |
1272 CONV2RAD_32B(RADIUS_ATTR_FRAMED_IPX_NETWORK, ahdr->avp_value->u32); | |
1273 break; | |
1274 | |
1275 case DIAM_ATTR_FRAMED_MTU: | |
1276 CONV2RAD_32B(RADIUS_ATTR_FRAMED_MTU, ahdr->avp_value->u32); | |
1277 break; | |
1278 | |
1279 case DIAM_ATTR_FRAMED_POOL: | |
1280 CONV2RAD_STR(RADIUS_ATTR_FRAMED_POOL, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 1); | |
1281 break; | |
1282 | |
1283 case DIAM_ATTR_FRAMED_PROTOCOL: | |
1284 CONV2RAD_32B(RADIUS_ATTR_FRAMED_PROTOCOL, ahdr->avp_value->u32); | |
1285 break; | |
1286 | |
1287 case DIAM_ATTR_FRAMED_ROUTE: | |
1288 CONV2RAD_STR(RADIUS_ATTR_FRAMED_ROUTE, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 1); | |
1289 break; | |
1290 | |
1291 case DIAM_ATTR_FRAMED_ROUTING: | |
1292 CONV2RAD_32B(RADIUS_ATTR_FRAMED_ROUTING, ahdr->avp_value->u32); | |
1293 break; | |
1294 | |
1295 case DIAM_ATTR_IDLE_TIMEOUT: | |
1296 CONV2RAD_32B(RADIUS_ATTR_IDLE_TIMEOUT, ahdr->avp_value->u32); | |
1297 break; | |
1298 | |
1299 case DIAM_ATTR_LOGIN_IP_HOST: | |
1300 CONV2RAD_STR(RADIUS_ATTR_LOGIN_IP_HOST, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 0); | |
1301 break; | |
1302 | |
1303 case DIAM_ATTR_LOGIN_IPV6_HOST: | |
1304 CONV2RAD_STR(RADIUS_ATTR_LOGIN_IPV6_HOST, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 0); | |
1305 break; | |
1306 | |
1307 case DIAM_ATTR_LOGIN_LAT_GROUP: | |
1308 CONV2RAD_STR(RADIUS_ATTR_LOGIN_LAT_GROUP, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 1); | |
1309 break; | |
1310 | |
1311 case DIAM_ATTR_LOGIN_LAT_NODE: | |
1312 CONV2RAD_STR(RADIUS_ATTR_LOGIN_LAT_NODE, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 1); | |
1313 break; | |
1314 | |
1315 case DIAM_ATTR_LOGIN_LAT_PORT: | |
1316 CONV2RAD_STR(RADIUS_ATTR_LOGIN_LAT_PORT, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 1); | |
1317 break; | |
1318 | |
1319 case DIAM_ATTR_LOGIN_LAT_SERVICE: | |
1320 CONV2RAD_STR(RADIUS_ATTR_LOGIN_LAT_SERVICE, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 1); | |
1321 break; | |
1322 | |
1323 case DIAM_ATTR_LOGIN_SERVICE: | |
1324 CONV2RAD_32B(RADIUS_ATTR_LOGIN_SERVICE, ahdr->avp_value->u32); | |
1325 break; | |
1326 | |
1327 case DIAM_ATTR_LOGIN_TCP_PORT: | |
1328 CONV2RAD_32B(RADIUS_ATTR_LOGIN_TCP_PORT, ahdr->avp_value->u32); | |
1329 break; | |
1330 | |
1331 /* | |
1332 - If the | |
1333 Multi-Round-Time-Out AVP is present, the value of the AVP MUST | |
1334 be inserted in the RADIUS Session-Timeout AVP. | |
1335 | |
1336 o As described in [NASREQ], if the Result-Code AVP set to | |
1337 DIAMETER_MULTI_ROUND_AUTH and the Multi-Round-Time-Out AVP is | |
1338 present, it is translated to the RADIUS Session-Timeout attribute. | |
1339 */ | |
1340 case DIAM_ATTR_MULTI_ROUND_TIMEOUT: | |
1341 CONV2RAD_32B(RADIUS_ATTR_SESSION_TIMEOUT, ahdr->avp_value->u32); | |
1342 break; | |
1343 | |
1344 case DIAM_ATTR_NAS_FILTER_RULE: | |
1345 /* This is not translatable to RADIUS */ | |
1346 fd_log_debug("[auth.rgwx] Received Diameter answer with non-translatable NAS-Filter-Rule AVP from '%.*s' (session: '%.*s'), ignoring.\n", | |
1347 oh->avp_value->os.len, oh->avp_value->os.data, | |
1348 sid->avp_value->os.len, sid->avp_value->os.data); | |
1349 handled = 0; | |
1350 break; | |
1351 | |
1352 /* NAS-Identifier is not present in answers */ | |
1353 /* NAS-IP-Address is not present in answers */ | |
1354 /* NAS-IPv6-Address is not present in answers */ | |
1355 /* NAS-Port is not present in answers */ | |
1356 /* NAS-Port-Id is not present in answers */ | |
1357 /* NAS-Port-Type is not present in answers */ | |
1358 | |
1359 case DIAM_ATTR_ORIGIN_AAA_PROTOCOL: | |
1360 /* We just remove this AVP */ | |
1361 break; | |
1362 | |
1363 /* Originating-Line-Info is not present in answers */ | |
1364 | |
1365 case DIAM_ATTR_PASSWORD_RETRY: | |
1366 CONV2RAD_32B(RADIUS_ATTR_PASSWORD_RETRY, ahdr->avp_value->u32); | |
1367 break; | |
1368 | |
1369 case DIAM_ATTR_PORT_LIMIT: | |
1370 CONV2RAD_32B(RADIUS_ATTR_PORT_LIMIT, ahdr->avp_value->u32); | |
1371 break; | |
1372 | |
1373 case DIAM_ATTR_PROMPT: | |
1374 CONV2RAD_32B(RADIUS_ATTR_PROMPT, ahdr->avp_value->u32); | |
1375 break; | |
1376 | |
1377 case DIAM_ATTR_QOS_FILTER_RULE: | |
1378 /* This is not translatable to RADIUS */ | |
1379 fd_log_debug("[auth.rgwx] Received Diameter answer with non-translatable QoS-Filter-Rule AVP from '%.*s' (session: '%.*s'), ignoring.\n", | |
1380 oh->avp_value->os.len, oh->avp_value->os.data, | |
1381 sid->avp_value->os.len, sid->avp_value->os.data); | |
1382 handled = 0; | |
1383 break; | |
1384 | |
1385 /* Re-Auth-Request-Type already handled */ | |
1386 | |
1387 case DIAM_ATTR_REPLY_MESSAGE: | |
1388 CONV2RAD_STR(RADIUS_ATTR_REPLY_MESSAGE, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 2); | |
1389 break; | |
1390 | |
1391 case DIAM_ATTR_SERVICE_TYPE: | |
1392 CONV2RAD_32B(RADIUS_ATTR_SERVICE_TYPE, ahdr->avp_value->u32); | |
1393 break; | |
1394 | |
1395 case DIAM_ATTR_STATE: | |
1396 CONV2RAD_STR(RADIUS_ATTR_STATE, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 2); | |
1397 break; | |
1398 | |
1399 case DIAM_ATTR_TUNNELING: | |
1400 { | |
1401 #define CONV2RAD_TUN_STR( _attr_, _data_, _len_, _trunc_) { \ | |
1402 size_t __l = (size_t)(_len_); \ | |
1403 size_t __w = (__l > 252) ? 252 : __l; \ | |
1404 size_t __off = 0; \ | |
1405 if ((_trunc_) == 0) { \ | |
1406 CHECK_PARAMS( __l <= 252 ); \ | |
1407 } \ | |
1408 if ((__l > 252) && (_trunc_ == 1)) { \ | |
1409 TRACE_DEBUG(FULL, "Attribute truncated!"); \ | |
1410 __l = 252; \ | |
1411 } \ | |
1412 buf[0] = tuntag; \ | |
1413 memcpy(&buf[1], (_data_), __w); \ | |
1414 CHECK_MALLOC(radius_msg_add_attr(*rad_fw, (_attr_), &buf[0], __w + 1)); \ | |
1415 while (__l -= __w) { \ | |
1416 __off += __w; \ | |
1417 __w = (__l > 253) ? 253 : __l; \ | |
1418 CHECK_MALLOC(radius_msg_add_attr(*rad_fw, (_attr_), (_data_) + __off, __w)); \ | |
1419 } \ | |
1420 } | |
1421 | |
1422 #define CONV2RAD_TUN_32B( _attr_, _data_) { \ | |
1423 uint32_t __v = htonl((uint32_t)(_data_) | (tuntag << 24)); \ | |
1424 CHECK_MALLOC(radius_msg_add_attr(*rad_fw, (_attr_), (uint8_t *)&__v, sizeof(__v))); \ | |
1425 } | |
1426 struct avp *inavp, *innext; | |
1427 tuntag++; | |
1428 CHECK_FCT( fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &innext, NULL) ); | |
1429 while (innext) { | |
1430 inavp = innext; | |
1431 CHECK_FCT( fd_msg_browse(inavp, MSG_BRW_NEXT, &innext, NULL) ); | |
1432 CHECK_FCT( fd_msg_avp_hdr ( inavp, &ahdr ) ); | |
1433 | |
1434 if (ahdr->avp_flags & AVP_FLAG_VENDOR == 0) { | |
1435 switch (ahdr->avp_code) { | |
1436 case DIAM_ATTR_TUNNEL_TYPE: | |
1437 CONV2RAD_TUN_32B( RADIUS_ATTR_TUNNEL_TYPE, ahdr->avp_value->u32); | |
1438 break; | |
1439 | |
1440 case DIAM_ATTR_TUNNEL_MEDIUM_TYPE: | |
1441 CONV2RAD_TUN_32B( RADIUS_ATTR_TUNNEL_MEDIUM_TYPE, ahdr->avp_value->u32); | |
1442 break; | |
1443 | |
1444 case DIAM_ATTR_TUNNEL_CLIENT_ENDPOINT: | |
1445 CONV2RAD_TUN_STR(RADIUS_ATTR_TUNNEL_CLIENT_ENDPOINT, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 1); | |
1446 break; | |
1447 | |
1448 case DIAM_ATTR_TUNNEL_SERVER_ENDPOINT: | |
1449 CONV2RAD_TUN_STR(RADIUS_ATTR_TUNNEL_SERVER_ENDPOINT, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 1); | |
1450 break; | |
1451 | |
1452 case DIAM_ATTR_TUNNEL_PREFERENCE: | |
1453 CONV2RAD_TUN_32B( RADIUS_ATTR_TUNNEL_PREFERENCE, ahdr->avp_value->u32); | |
1454 break; | |
1455 | |
1456 case DIAM_ATTR_TUNNEL_CLIENT_AUTH_ID: | |
1457 CONV2RAD_TUN_STR(RADIUS_ATTR_TUNNEL_CLIENT_AUTH_ID, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 1); | |
1458 break; | |
1459 | |
1460 case DIAM_ATTR_TUNNEL_SERVER_AUTH_ID: | |
1461 CONV2RAD_TUN_STR(RADIUS_ATTR_TUNNEL_SERVER_AUTH_ID, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 1); | |
1462 break; | |
1463 | |
271
411314907b43
Added translation of Accounting messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
264
diff
changeset
|
1464 case DIAM_ATTR_TUNNEL_ASSIGNMENT_ID: |
411314907b43
Added translation of Accounting messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
264
diff
changeset
|
1465 CONV2RAD_TUN_STR(RADIUS_ATTR_TUNNEL_ASSIGNMENT_ID, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 1); |
256 | 1466 break; |
1467 | |
1468 case DIAM_ATTR_TUNNEL_PASSWORD: | |
1469 { | |
1470 /* This AVP must be encoded for RADIUS (similar to radius_msg_add_attr_user_password) | |
1471 0 1 2 3 | |
1472 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | |
1473 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
1474 | Type | Length | Tag | Salt | |
1475 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
1476 Salt (cont) | String ... | |
1477 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
1478 */ | |
1479 size_t pos; | |
1480 int i; | |
1481 size_t buflen; | |
1482 uint8_t * secret; /* S */ | |
1483 size_t secret_len; | |
1484 uint8_t hash[16]; /* b(i) */ | |
1485 const uint8_t *addr[3]; | |
1486 size_t len[3]; | |
1487 | |
1488 /* We need the request authenticator */ | |
1489 CHECK_PARAMS(req_auth); | |
1490 | |
1491 /* Retrieve the shared secret */ | |
1492 CHECK_FCT(rgw_clients_getkey(cli, &secret, &secret_len)); | |
1493 | |
1494 /* Beginning of the buffer */ | |
1495 buf[0] = tuntag; | |
1496 buf[1] = (uint8_t)(lrand48()); /* A (hi bits) */ | |
1497 buf[2] = (uint8_t)(lrand48()); /* A (low bits) */ | |
1498 | |
1499 /* The plain text string P */ | |
1500 CHECK_PARAM(ahdr->avp_value->os.len < 240); | |
1501 buf[3] = ahdr->avp_value->os.len; | |
1502 memcpy(&buf[4], ahdr->avp_value->os.data, ahdr->avp_value->os.len); | |
1503 memset(&buf[4 + ahdr->avp_value->os.len], 0, sizeof(buf) - 4 - ahdr->avp_value->os.len); | |
1504 | |
1505 /* Initial b1 = MD5(S + R + A) */ | |
1506 addr[0] = secret; | |
1507 len[0] = secret_len; | |
1508 addr[1] = req_auth; | |
1509 len[1] = 16; | |
1510 addr[2] = &buf[1]; | |
1511 len[2] = 2; | |
1512 md5_vector(3, addr, len, hash); | |
1513 | |
1514 /* Initial c(1) = p(1) xor b(1) */ | |
1515 for (i = 0; i < 16; i++) { | |
1516 buf[i + 3] ^= hash[i]; | |
1517 } | |
1518 pos = 16; | |
1519 | |
1520 /* loop */ | |
1521 while (pos < ahdr->avp_value->os.len + 1) { | |
1522 addr[0] = secret; | |
1523 len[0] = secret_len; | |
1524 addr[1] = &buf[pos - 13]; | |
1525 len[1] = 16; | |
1526 /* b(i) = MD5( S + c(i-1) */ | |
1527 md5_vector(2, addr, len, hash); | |
1528 | |
1529 /* c(i) = p(i) xor b(i) */ | |
1530 for (i = 0; i < 16; i++) | |
1531 buf[pos + i + 3] ^= hash[i]; | |
1532 | |
1533 pos += 16; | |
1534 } | |
1535 | |
1536 CONV2RAD_STR(RADIUS_ATTR_TUNNEL_PASSWORD, &buf[0], pos + 3, 0); | |
1537 } | |
1538 break; | |
1539 | |
1540 case DIAM_ATTR_TUNNEL_PRIVATE_GROUP_ID: | |
1541 CONV2RAD_TUN_STR(RADIUS_ATTR_TUNNEL_PRIVATE_GROUP_ID, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 1); | |
1542 break; | |
1543 | |
1544 default: | |
1545 TRACE_DEBUG(FULL, "Ignored unknown AVP inside Tunneling AVP (%d)", ahdr->avp_code); | |
1546 } | |
1547 } else { | |
1548 TRACE_DEBUG(FULL, "Ignored unknown Vendor AVP inside Tunneling AVP (%d, %d)", ahdr->avp_vendor, ahdr->avp_code); | |
1549 } | |
1550 } | |
1551 } | |
1552 break; | |
1553 | |
1554 case DIAM_ATTR_USER_NAME: | |
1555 CONV2RAD_STR(RADIUS_ATTR_USER_NAME, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 1); | |
1556 break; | |
1557 | |
1558 /* User-Password never present in answers */ | |
1559 | |
1560 /* RFC 4072 (AVP in the order of the EAP Command AVP Table) */ | |
1561 /* | |
1562 o Diameter Accounting-EAP-Auth-Method AVPs, if present, are | |
1563 discarded. | |
1564 */ | |
1565 case DIAM_ATTR_ACCOUNTING_EAP_AUTH_METHOD: | |
1566 break; | |
1567 | |
1568 /* | |
1569 o Diameter EAP-Master-Session-Key AVP can be translated to the | |
1570 vendor-specific RADIUS MS-MPPE-Recv-Key and MS-MPPE-Send-Key | |
1571 attributes [RFC2548]. The first up to 32 octets of the key is | |
1572 stored into MS-MPPE-Recv-Key, and the next up to 32 octets (if | |
1573 present) are stored into MS-MPPE-Send-Key. The encryption of this | |
1574 attribute is described in [RFC2548]. | |
1575 */ | |
1576 case DIAM_ATTR_EAP_MASTER_SESSION_KEY: | |
1577 { | |
1578 uint8_t * secret; /* S */ | |
1579 size_t secret_len; | |
1580 size_t recv_len, send_len; | |
1581 | |
1582 /* We need the request authenticator */ | |
1583 CHECK_PARAMS(req_auth); | |
1584 | |
1585 /* Retrieve the shared secret */ | |
1586 CHECK_FCT(rgw_clients_getkey(cli, &secret, &secret_len)); | |
1587 | |
1588 if (ahdr->avp_value->os.len != 64) { | |
1589 TRACE_DEBUG(INFO, "Received EAP-Master-Session-Key attribute with length %d != 64.\n", ahdr->avp_value->os.len) | |
1590 } | |
1591 | |
1592 CHECK_PARAMS(ahdr->avp_value->os.len <= 64); | |
1593 recv_len = ahdr->avp_value->os.len >= 32 ? 32 : ahdr->avp_value->os.len; | |
1594 send_len = ahdr->avp_value->os.len - recv_len; | |
1595 | |
1596 if ( ! radius_msg_add_mppe_keys(*rad_fw, req_auth, secret, secret_len, | |
1597 ahdr->avp_value->os.data + recv_len, send_len, | |
1598 ahdr->avp_value->os.data, recv_len) ) { | |
1599 TRACE_DEBUG(INFO, "Error while converting EAP-Master-Session-Key to RADIUS message"); | |
1600 return ENOMEM; | |
1601 } | |
1602 } | |
1603 break; | |
1604 | |
1605 case DIAM_ATTR_EAP_KEY_NAME: | |
1606 CONV2RAD_STR(RADIUS_ATTR_EAP_KEY_NAME, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 1); | |
1607 break; | |
1608 | |
1609 /* | |
1610 o Diameter EAP-Payload AVP is translated to RADIUS EAP-Message | |
1611 attribute(s). If necessary, the value is split into multiple | |
1612 RADIUS EAP-Message attributes. | |
1613 */ | |
1614 case DIAM_ATTR_EAP_PAYLOAD: | |
1615 if ( ! radius_msg_add_eap(*rad_fw, ahdr->avp_value->os.data, ahdr->avp_value->os.len) ) { | |
1616 TRACE_DEBUG(INFO, "Error while converting EAP payload to RADIUS message"); | |
1617 return ENOMEM; | |
1618 } | |
1619 break; | |
1620 | |
1621 /* | |
1622 o Diameter EAP-Reissued-Payload AVP is translated to a message that | |
1623 contains RADIUS EAP-Message attribute(s), and a RADIUS Error-Cause | |
1624 attribute [RFC3576] with value 202 (decimal), "Invalid EAP Packet | |
1625 (Ignored)" [RFC3579]. | |
1626 */ | |
1627 case DIAM_ATTR_EAP_REISSUED_PAYLOAD: | |
1628 if ( ! radius_msg_add_eap(*rad_fw, ahdr->avp_value->os.data, ahdr->avp_value->os.len) ) { | |
1629 TRACE_DEBUG(INFO, "Error while converting EAP reissued payload to RADIUS message"); | |
1630 return ENOMEM; | |
1631 } | |
1632 | |
1633 if ( ! radius_msg_add_attr_int32(*rad_fw, RADIUS_ATTR_ERROR_CAUSE, 202) ) { | |
1634 TRACE_DEBUG(INFO, "Error while adding Error-Cause attribute in RADIUS message"); | |
1635 return ENOMEM; | |
1636 } | |
1637 break; | |
1638 | |
1639 default: | |
1640 /* Leave the AVP in the message for further treatment */ | |
1641 handled = 0; | |
1642 } | |
1643 } else { | |
1644 /* Vendor-specific AVPs */ | |
1645 switch (ahdr->avp_vendor) { | |
1646 | |
1647 default: /* unknown vendor */ | |
1648 handled = 0; | |
1649 } | |
1650 } | |
1651 | |
1652 if (handled) { | |
1653 CHECK_FCT( fd_msg_free( avp ) ); | |
1654 } | |
1655 } | |
1656 | |
1657 CHECK_FCT( fd_msg_free( asid ) ); | |
1658 CHECK_FCT( fd_msg_free( aoh ) ); | |
1659 free(req_auth); | |
1660 | |
1661 return 0; | |
1662 } | |
1663 | |
1664 /* The exported symbol */ | |
1665 struct rgw_api rgwp_descriptor = { | |
1666 .rgwp_name = "auth", | |
1667 .rgwp_conf_parse = auth_conf_parse, | |
1668 .rgwp_conf_free = auth_conf_free, | |
1669 .rgwp_rad_req = auth_rad_req, | |
1670 .rgwp_diam_ans = auth_diam_ans | |
1671 }; |