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