Brian Waters | 13d9601 | 2017-12-08 16:53:31 -0600 | [diff] [blame] | 1 | /***************************************************************************************************** |
| 2 | * Software License Agreement (BSD License) |
| 3 | * Author : Souheil Ben Ayed <souheil@tera.ics.keio.ac.jp> |
| 4 | * |
| 5 | * Copyright (c) 2009-2010, Souheil Ben Ayed, Teraoka Laboratory of Keio University, and the WIDE Project |
| 6 | * All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use of this software in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions are met: |
| 10 | * |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * |
| 14 | * 2. Redistributions in binary form must reproduce the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer in the |
| 16 | * documentation and/or other materials provided with the distribution. |
| 17 | * |
| 18 | * 3. All advertising materials mentioning features or use of this software |
| 19 | * must display the following acknowledgement: |
| 20 | * This product includes software developed by Souheil Ben Ayed <souheil@tera.ics.keio.ac.jp>. |
| 21 | * |
| 22 | * 4. Neither the name of Souheil Ben Ayed, Teraoka Laboratory of Keio University or the WIDE Project nor the |
| 23 | * names of its contributors may be used to endorse or promote products |
| 24 | * derived from this software without specific prior written permission. |
| 25 | * |
| 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' AND ANY |
| 27 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 28 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY |
| 30 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 31 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 32 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 33 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | *****************************************************************************************************/ |
| 37 | |
| 38 | #include "diameap_common.h" |
| 39 | |
| 40 | static void diameap_ba_nextid(struct eap_state_machine * sm, int * id) |
| 41 | { |
| 42 | TRACE_ENTRY("%p %p",sm,id); |
| 43 | |
| 44 | if (sm->currentId < 0) |
| 45 | { |
| 46 | *id = (u8) (255 * rand() / RAND_MAX) & 0xFFU; |
| 47 | } |
| 48 | else |
| 49 | { |
| 50 | *id = (sm->currentId++) & 0xFFU; |
| 51 | } |
| 52 | if (*id == sm->lastId) |
| 53 | { |
| 54 | *id=*id+1; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | static void diameap_ba_policyupdate(struct eap_state_machine * eap_sm, |
| 59 | struct eap_packet *eapPacket) |
| 60 | { |
| 61 | TRACE_ENTRY("%p %p",eap_sm, eapPacket); |
| 62 | if ((eap_sm->respMethod == TYPE_NAK)) |
| 63 | { |
| 64 | int id; |
| 65 | eap_sm->user.pmethods = 0; |
| 66 | u32 vendor; |
| 67 | eap_type type; |
| 68 | u8 *data = (u8 *) eapPacket->data; |
| 69 | data += 5; |
| 70 | id = 5; |
| 71 | while (id < eapPacket->length) |
| 72 | { |
| 73 | vendor = VENDOR_IETF; |
| 74 | type = G8(data); |
| 75 | if (diameap_plugin_exist(vendor, type) == TRUE) |
| 76 | { |
| 77 | eap_sm->user.proposedmethods[id - 5].method = type; |
| 78 | eap_sm->user.proposedmethods[id - 5].vendor = vendor; |
| 79 | eap_sm->user.pmethods++; |
| 80 | } |
| 81 | data++; |
| 82 | id++; |
| 83 | } |
| 84 | eap_sm->user.methodId = -1; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | static int diameap_ba_policygetnextmethod(struct eap_state_machine * eap_sm, |
| 89 | eap_type * eaptype, u32 * vendor) |
| 90 | { |
| 91 | TRACE_ENTRY("%p %p %p",eap_sm,eaptype,vendor); |
| 92 | *vendor = 0; |
| 93 | *eaptype = TYPE_NONE; |
| 94 | if (eap_sm == NULL) |
| 95 | { |
| 96 | return EINVAL; |
| 97 | } |
| 98 | |
| 99 | eap_sm->selectedMethod = NULL; |
| 100 | |
| 101 | if (eap_sm->user.userid == NULL) |
| 102 | { |
| 103 | if ((eap_sm->currentMethod == TYPE_NONE)) |
| 104 | { |
| 105 | *vendor = VENDOR_IETF; |
| 106 | *eaptype = TYPE_IDENTITY; |
| 107 | if (eap_sm->selectedMethod != NULL) |
| 108 | { |
| 109 | (*eap_sm->selectedMethod->eap_method_free)(eap_sm->methodData); |
| 110 | eap_sm->methodData = NULL; |
| 111 | } |
| 112 | CHECK_FCT(diameap_plugin_get(VENDOR_IETF,TYPE_IDENTITY,&eap_sm->selectedMethod)); |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | eap_sm->selectedMethod = NULL; |
| 117 | *vendor = 0; |
| 118 | *eaptype = TYPE_NONE; |
| 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | if (eap_sm->user.methodId == -1) |
| 123 | { |
| 124 | if (eap_sm->user.proposed_eap_method >= TYPE_EAP_MD5) |
| 125 | { |
| 126 | *vendor = eap_sm->user.proposed_eap_method_vendor; |
| 127 | if (*vendor == VENDOR_IETF) |
| 128 | { |
| 129 | *eaptype = eap_sm->user.proposed_eap_method; |
| 130 | } |
| 131 | else |
| 132 | { |
| 133 | *eaptype = TYPE_EXPANDED_TYPES; |
| 134 | } |
| 135 | if (eap_sm->selectedMethod != NULL) |
| 136 | { |
| 137 | (*eap_sm->selectedMethod->eap_method_free)(eap_sm->methodData); |
| 138 | eap_sm->methodData = NULL; |
| 139 | } |
| 140 | CHECK_FCT_DO(diameap_plugin_get(*vendor,*eaptype,&eap_sm->selectedMethod), |
| 141 | { TRACE_DEBUG(INFO,"%s [EAP Protocol] Invalid EAP-TYPE %d (vendor %d)",DIAMEAP_EXTENSION,*eaptype,*vendor);return 1;}); |
| 142 | |
| 143 | } |
| 144 | eap_sm->user.proposed_eap_method = TYPE_NONE; |
| 145 | } |
| 146 | else |
| 147 | { |
| 148 | *vendor = eap_sm->user.proposedmethods[eap_sm->user.methodId].vendor; |
| 149 | if (eap_sm->user.proposedmethods[eap_sm->user.methodId].vendor |
| 150 | == VENDOR_IETF) |
| 151 | { |
| 152 | *eaptype |
| 153 | = eap_sm->user.proposedmethods[eap_sm->user.methodId].method; |
| 154 | } |
| 155 | else |
| 156 | { |
| 157 | *eaptype = TYPE_EXPANDED_TYPES; |
| 158 | } |
| 159 | if (eap_sm->selectedMethod != NULL) |
| 160 | { |
| 161 | (*eap_sm->selectedMethod->eap_method_free)(eap_sm->methodData); |
| 162 | eap_sm->methodData=NULL; |
| 163 | } |
| 164 | CHECK_FCT(diameap_plugin_get(eap_sm->user.proposedmethods[eap_sm->user.methodId].vendor,eap_sm->user.proposedmethods[eap_sm->user.methodId].method,&eap_sm->selectedMethod)); |
| 165 | |
| 166 | eap_sm->user.methodId++; |
| 167 | } |
| 168 | |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | static int diameap_ba_policygetdecision(struct eap_state_machine * eap_sm, |
| 173 | struct diameap_eap_interface * eap_i, decision * gdecision) |
| 174 | { |
| 175 | TRACE_ENTRY("%p %p %p",eap_sm,eap_i,gdecision); |
| 176 | |
| 177 | if (eap_sm->user.userid != NULL) |
| 178 | { |
| 179 | |
| 180 | if (eap_sm->methodState == EAP_M_END) |
| 181 | { |
| 182 | |
| 183 | if (eap_sm->respMethod == TYPE_IDENTITY) |
| 184 | { |
| 185 | |
| 186 | *gdecision = DECISION_CONTINUE; |
| 187 | return 0; |
| 188 | } |
| 189 | |
| 190 | if ((eap_sm->respMethod == TYPE_NAK) || ((eap_sm->respMethod |
| 191 | == TYPE_EXPANDED_TYPES) && (eap_sm->respVendor |
| 192 | == VENDOR_IETF) && (eap_sm->respVendorMethod == TYPE_NAK))) |
| 193 | { |
| 194 | goto SelectNextMethod; |
| 195 | } |
| 196 | |
| 197 | if (eap_sm->user.success == TRUE) |
| 198 | { |
| 199 | |
| 200 | *gdecision = DECISION_SUCCESS; |
| 201 | } |
| 202 | else |
| 203 | { |
| 204 | |
| 205 | *gdecision = DECISION_FAILURE; |
| 206 | } |
| 207 | |
| 208 | } |
| 209 | else |
| 210 | { |
| 211 | goto SelectNextMethod; |
| 212 | } |
| 213 | return 0; |
| 214 | |
| 215 | SelectNextMethod: if ((eap_sm->user.methodId |
| 216 | == (MAXPROPOSEDMETHODS - 1)) |
| 217 | || ((eap_sm->user.proposedmethods[eap_sm->user.methodId + 1].method |
| 218 | == TYPE_NONE) |
| 219 | && (eap_sm->user.proposedmethods[eap_sm->user.methodId |
| 220 | + 1].vendor == VENDOR_IETF))) |
| 221 | { |
| 222 | TRACE_DEBUG(FULL+1, |
| 223 | "%s [EAP protocol] None of proposed EAP Methods authenticated the user.(FAILURE)",DIAMEAP_EXTENSION); |
| 224 | *gdecision = DECISION_FAILURE; |
| 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | eap_sm->user.methodId = 0; |
| 229 | *gdecision = DECISION_CONTINUE; |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | if (eap_sm->currentMethod == TYPE_IDENTITY) |
| 234 | { |
| 235 | *gdecision = DECISION_FAILURE; |
| 236 | return 0; |
| 237 | } |
| 238 | |
| 239 | *gdecision = DECISION_CONTINUE; |
| 240 | return 0; |
| 241 | } |
| 242 | |
| 243 | static boolean diameap_ba_policydopickup(eap_type type) |
| 244 | { |
| 245 | TRACE_ENTRY("%d",type); |
| 246 | if (type == TYPE_IDENTITY) |
| 247 | { |
| 248 | return TRUE; |
| 249 | } |
| 250 | return FALSE; |
| 251 | } |
| 252 | |
| 253 | int diameap_eap_statemachine(struct eap_state_machine * eap_sm, |
| 254 | struct diameap_eap_interface * eap_i, boolean * non_fatal_error) |
| 255 | { |
| 256 | TRACE_ENTRY("%p %p %p", eap_sm, eap_i, non_fatal_error); |
| 257 | int ret; |
| 258 | |
| 259 | if ((eap_sm->eap_state == EAP_IDLE) && (eap_i->aaaEapResp == TRUE)) |
| 260 | { |
| 261 | eap_sm->eap_state = EAP_RECEIVED; |
| 262 | } |
| 263 | while (!((eap_sm->eap_state == EAP_IDLE) || (eap_sm->eap_state == EAP_END))) |
| 264 | { |
| 265 | switch (eap_sm->eap_state) |
| 266 | { |
| 267 | case EAP_INITIALIZE: |
| 268 | if (eap_sm->rxResp == TRUE) |
| 269 | { |
| 270 | eap_sm->lastId = eap_sm->currentId; |
| 271 | eap_sm->currentId = eap_sm->respId; |
| 272 | } |
| 273 | else |
| 274 | { |
| 275 | eap_sm->lastId = -1; |
| 276 | eap_sm->currentId = -1; |
| 277 | } |
| 278 | if (eap_sm->rxResp == FALSE) |
| 279 | { |
| 280 | eap_sm->eap_state = EAP_SELECT_ACTION; |
| 281 | } |
| 282 | else if ((eap_sm->respMethod == TYPE_NAK) || (eap_sm->respMethod |
| 283 | == TYPE_EXPANDED_TYPES && eap_sm->respVendor == VENDOR_IETF |
| 284 | && eap_sm->respVendorMethod == TYPE_NAK)) |
| 285 | { |
| 286 | eap_sm->eap_state = EAP_NAK; |
| 287 | } |
| 288 | else |
| 289 | { |
| 290 | eap_sm->eap_state = EAP_PICK_UP_METHOD; |
| 291 | } |
| 292 | break; |
| 293 | case EAP_PICK_UP_METHOD: |
| 294 | if (diameap_ba_policydopickup(eap_sm->respMethod) == TRUE) |
| 295 | { |
| 296 | eap_sm->currentMethod = eap_sm->respMethod; |
| 297 | |
| 298 | if (diameap_plugin_get(eap_sm->currentVendor, |
| 299 | eap_sm->currentMethod, &eap_sm->selectedMethod)) |
| 300 | { |
| 301 | TRACE_DEBUG(INFO,"%sNo EAP Method plugin available for EAP Method {Type=%d, Vendor=%d}.",DIAMEAP_EXTENSION,eap_sm->currentMethod, eap_sm->currentVendor); |
| 302 | } |
| 303 | else |
| 304 | { |
| 305 | TRACE_DEBUG(FULL,"%sCurrent EAP Method {Type=%d, Vendor=%d} (EAP Method plugin selected).",DIAMEAP_EXTENSION,eap_sm->currentMethod, eap_sm->currentVendor); |
| 306 | } |
| 307 | eap_sm->currentVendor = VENDOR_IETF; |
| 308 | if (eap_sm->selectedMethod != NULL) |
| 309 | { |
| 310 | ret = (*eap_sm->selectedMethod->eap_method_initPickUp)( |
| 311 | eap_sm); |
| 312 | if (ret) |
| 313 | { |
| 314 | TRACE_DEBUG(INFO, "%sEAP Method InitPickUp returned error.",DIAMEAP_EXTENSION); |
| 315 | eap_sm->selectedMethod = NULL; |
| 316 | eap_sm->currentMethod = TYPE_NONE; |
| 317 | } |
| 318 | } |
| 319 | } |
| 320 | if (eap_sm->currentMethod == TYPE_NONE) |
| 321 | { |
| 322 | eap_sm->eap_state = EAP_SELECT_ACTION; |
| 323 | } |
| 324 | else |
| 325 | { |
| 326 | eap_sm->eap_state = EAP_METHOD_RESPONSE; |
| 327 | } |
| 328 | break; |
| 329 | |
| 330 | case EAP_RECEIVED: |
| 331 | TRACE_DEBUG(FULL+1,"%s[EAP Protocol] New EAP Response received",DIAMEAP_EXTENSION) |
| 332 | ; |
| 333 | diameap_eap_dump(FULL + 1, &eap_i->aaaEapRespData); |
| 334 | if ((eap_sm->rxResp == TRUE) && (eap_sm->respId |
| 335 | == eap_sm->currentId) && ((eap_sm->respMethod |
| 336 | == eap_sm->currentMethod) || ((eap_sm->respMethod |
| 337 | == TYPE_EXPANDED_TYPES) && (eap_sm->respVendor |
| 338 | == VENDOR_IETF) && (eap_sm->respVendorMethod |
| 339 | == eap_sm->currentMethod)))) |
| 340 | { |
| 341 | eap_sm->eap_state = EAP_INTEGRITY_CHECK; |
| 342 | } |
| 343 | else if ((eap_sm->rxResp == TRUE) && (eap_sm->respId |
| 344 | == eap_sm->currentId) && ((eap_sm->respMethod == TYPE_NAK) |
| 345 | || (eap_sm->respMethod == TYPE_EXPANDED_TYPES |
| 346 | && eap_sm->respVendor == VENDOR_IETF |
| 347 | && eap_sm->respVendorMethod == TYPE_NAK)) |
| 348 | && (eap_sm->methodState == EAP_M_PROPOSED)) |
| 349 | { |
| 350 | eap_sm->eap_state = EAP_NAK; |
| 351 | } |
| 352 | else |
| 353 | { |
| 354 | eap_sm->eap_state = EAP_DISCARD; |
| 355 | } |
| 356 | break; |
| 357 | case EAP_DISCARD: |
| 358 | TRACE_DEBUG(INFO,"%s[EAP Protocol] Invalid EAP Packet received (Non fatal error).",DIAMEAP_EXTENSION) |
| 359 | ; |
| 360 | *non_fatal_error = TRUE; |
| 361 | eap_sm->eap_state = EAP_IDLE; |
| 362 | break; |
| 363 | |
| 364 | case EAP_SEND_REQUEST: |
| 365 | TRACE_DEBUG(FULL+1,"%s[EAP Protocol] New EAP packet request created.",DIAMEAP_EXTENSION) |
| 366 | ; |
| 367 | diameap_eap_dump(FULL, &eap_i->aaaEapReqData); |
| 368 | eap_i->aaaEapResp = FALSE; |
| 369 | eap_i->aaaEapReq = TRUE; |
| 370 | eap_sm->eap_state = EAP_IDLE; |
| 371 | break; |
| 372 | |
| 373 | case EAP_INTEGRITY_CHECK: |
| 374 | if ((*eap_sm->selectedMethod->eap_method_check)(eap_sm, |
| 375 | &eap_i->aaaEapRespData) == FALSE) |
| 376 | { |
| 377 | TRACE_DEBUG(INFO,"%s[EAP Protocol] Invalid EAP packet received {Type=%d, Vendor=%d}. Integrity check failed (non fatal error).",DIAMEAP_EXTENSION,eap_sm->currentMethod,eap_sm->currentVendor); |
| 378 | //non_fata_error |
| 379 | *non_fatal_error = TRUE; |
| 380 | eap_sm->eap_state = EAP_IDLE; |
| 381 | } |
| 382 | else |
| 383 | { |
| 384 | eap_sm->eap_state = EAP_METHOD_RESPONSE; |
| 385 | } |
| 386 | |
| 387 | break; |
| 388 | case EAP_METHOD_REQUEST: |
| 389 | eap_sm->lastId = eap_sm->currentId; |
| 390 | diameap_ba_nextid(eap_sm, &eap_sm->currentId); |
| 391 | CHECK_FCT((*eap_sm->selectedMethod->eap_method_buildReq)( |
| 392 | eap_sm, eap_sm->currentId,&eap_i->aaaEapReqData)) |
| 393 | ; |
| 394 | if (eap_sm->selectedMethod->eap_method_getTimeout) |
| 395 | { |
| 396 | if ((*eap_sm->selectedMethod->eap_method_getTimeout)(eap_sm, |
| 397 | &eap_i->aaaMethodTimeout)) |
| 398 | { |
| 399 | TRACE_DEBUG(INFO,"%s[EAP Protocol] [%s plugin] getTimeout failed.",DIAMEAP_EXTENSION,eap_sm->selectedMethod->methodname); |
| 400 | eap_i->aaaMethodTimeout = 0; |
| 401 | } |
| 402 | } |
| 403 | else |
| 404 | { |
| 405 | eap_i->aaaMethodTimeout = 0; |
| 406 | } |
| 407 | eap_sm->eap_state = EAP_SEND_REQUEST; |
| 408 | break; |
| 409 | |
| 410 | case EAP_METHOD_RESPONSE: |
| 411 | if (eap_sm->respMethod >= TYPE_EAP_MD5) |
| 412 | { |
| 413 | if (eap_sm->user.methodId < 0) |
| 414 | { |
| 415 | eap_sm->user.methodId = 0; |
| 416 | eap_sm->user.methods[eap_sm->user.methodId].vendor |
| 417 | = eap_sm->respVendor; |
| 418 | eap_sm->user.methods[eap_sm->user.methodId].method |
| 419 | = eap_sm->respMethod; |
| 420 | eap_sm->user.methodId++; |
| 421 | |
| 422 | } |
| 423 | else if (!((eap_sm->user.methods[eap_sm->user.methodId - 1].vendor |
| 424 | == eap_sm->respVendor) |
| 425 | && (eap_sm->user.methods[eap_sm->user.methodId - 1].method |
| 426 | == eap_sm->respMethod))) |
| 427 | { |
| 428 | eap_sm->user.methods[eap_sm->user.methodId].vendor |
| 429 | = eap_sm->respVendor; |
| 430 | eap_sm->user.methods[eap_sm->user.methodId].method |
| 431 | = eap_sm->respMethod; |
| 432 | eap_sm->user.methodId++; |
| 433 | } |
| 434 | } |
| 435 | if ((*eap_sm->selectedMethod->eap_method_process)(eap_sm, |
| 436 | &eap_i->aaaEapRespData)) |
| 437 | { |
| 438 | TRACE_DEBUG(INFO,"%s[EAP Protocol] [%s plugin] Authentication process failed.",DIAMEAP_EXTENSION,eap_sm->selectedMethod->methodname); |
| 439 | *non_fatal_error = TRUE; |
| 440 | eap_sm->eap_state = EAP_IDLE; |
| 441 | |
| 442 | }else{ |
| 443 | if ((*eap_sm->selectedMethod->eap_method_isDone)(eap_sm) == TRUE) |
| 444 | { |
| 445 | /*diameap_ba_PolicyUpdate();*/ |
| 446 | eap_i->aaaEapMSKLength = 0; |
| 447 | eap_i->aaaEapEMSKLength = 0; |
| 448 | if (eap_sm->selectedMethod->eap_method_getKey) |
| 449 | { |
| 450 | if ((*eap_sm->selectedMethod->eap_method_getKey)(eap_sm, |
| 451 | &eap_i->aaaEapMSKData, &eap_i->aaaEapMSKLength, |
| 452 | &eap_i->aaaEapEMSKData, &eap_i->aaaEapEMSKLength)) |
| 453 | { |
| 454 | TRACE_DEBUG(INFO,"%s[EAP Protocol] [%s plugin] Generating EAP Master Key failed.",DIAMEAP_EXTENSION,eap_sm->selectedMethod->methodname) |
| 455 | eap_i->aaaEapMSKLength = 0; |
| 456 | eap_i->aaaEapEMSKLength = 0; |
| 457 | eap_i->aaaEapKeyAvailable = FALSE; |
| 458 | } |
| 459 | else |
| 460 | { |
| 461 | eap_i->aaaEapKeyAvailable = TRUE; |
| 462 | } |
| 463 | } |
| 464 | eap_sm->methodState = EAP_M_END; |
| 465 | eap_sm->eap_state = EAP_SELECT_ACTION; |
| 466 | } |
| 467 | else |
| 468 | { |
| 469 | eap_sm->methodState = EAP_M_CONTINUE; |
| 470 | eap_sm->eap_state = EAP_METHOD_REQUEST; |
| 471 | } |
| 472 | } |
| 473 | break; |
| 474 | case EAP_PROPOSE_METHOD: |
| 475 | if (diameap_ba_policygetnextmethod(eap_sm, &eap_sm->currentMethod, |
| 476 | &eap_sm->currentVendor)) |
| 477 | { |
| 478 | TRACE_DEBUG(INFO,"%s[EAP Protocol] [%s plugin] Selecting EAP Method plugin failed.",DIAMEAP_EXTENSION,eap_sm->selectedMethod->methodname); |
| 479 | |
| 480 | *non_fatal_error = TRUE; |
| 481 | eap_sm->eap_state = EAP_END; |
| 482 | |
| 483 | } |
| 484 | TRACE_DEBUG(FULL,"%s[EAP Protocol] Selecting EAP Method plugin: %s(%d). [user: %s]",DIAMEAP_EXTENSION,eap_sm->selectedMethod->methodname,eap_sm->selectedMethod->methodtype,eap_sm->user.userid) |
| 485 | ; |
| 486 | if ((*eap_sm->selectedMethod->eap_method_init)(eap_sm)) |
| 487 | { |
| 488 | TRACE_DEBUG(INFO,"%s[EAP Protocol] [%s plugin] Initializing EAP plugin failed.",DIAMEAP_EXTENSION,eap_sm->selectedMethod->methodname); |
| 489 | } |
| 490 | |
| 491 | if ((eap_sm->currentMethod == TYPE_IDENTITY) |
| 492 | || (eap_sm->currentMethod == TYPE_NOTIFICATION)) |
| 493 | { |
| 494 | eap_sm->methodState = EAP_M_CONTINUE; |
| 495 | } |
| 496 | else |
| 497 | { |
| 498 | eap_sm->methodState = EAP_M_PROPOSED; |
| 499 | } |
| 500 | eap_sm->eap_state = EAP_METHOD_REQUEST; |
| 501 | break; |
| 502 | case EAP_NAK: |
| 503 | TRACE_DEBUG(FULL+1,"%s[EAP Protocol] EAP NAK Packet received.",DIAMEAP_EXTENSION) |
| 504 | ; |
| 505 | if (eap_sm->selectedMethod->eap_method_free) |
| 506 | { |
| 507 | (*eap_sm->selectedMethod->eap_method_free)(eap_sm->methodData); |
| 508 | eap_sm->methodData = NULL; |
| 509 | } |
| 510 | else |
| 511 | { |
| 512 | if (eap_sm->methodData) |
| 513 | { |
| 514 | free(eap_sm->methodData); |
| 515 | eap_sm->methodData = NULL; |
| 516 | } |
| 517 | } |
| 518 | diameap_ba_policyupdate(eap_sm, &eap_i->aaaEapRespData); |
| 519 | eap_sm->eap_state = EAP_SELECT_ACTION; |
| 520 | break; |
| 521 | case EAP_SELECT_ACTION: |
| 522 | CHECK_FCT(diameap_ba_policygetdecision(eap_sm, eap_i,&eap_sm->sm_decision)) |
| 523 | ; |
| 524 | switch (eap_sm->sm_decision) |
| 525 | { |
| 526 | case DECISION_CONTINUE: |
| 527 | eap_sm->eap_state = EAP_PROPOSE_METHOD; |
| 528 | break; |
| 529 | case DECISION_FAILURE: |
| 530 | TRACE_DEBUG(FULL,"%s[EAP Protocol] Authentication Failure [User: %s].",DIAMEAP_EXTENSION,eap_sm->user.userid) |
| 531 | ; |
| 532 | eap_sm->lastId = eap_sm->currentId; |
| 533 | diameap_ba_nextid(eap_sm, &eap_sm->currentId); |
| 534 | CHECK_FCT(diameap_eap_new(EAP_FAILURE, (u8) eap_sm->currentId, TYPE_NONE, NULL, 0,&eap_i->aaaEapReqData)) |
| 535 | ; |
| 536 | eap_i->aaaFail = TRUE; |
| 537 | *non_fatal_error = FALSE; |
| 538 | eap_sm->eap_state = EAP_END; |
| 539 | if (eap_sm->methodData) |
| 540 | { |
| 541 | if (eap_sm->selectedMethod->eap_method_free) |
| 542 | { |
| 543 | (*eap_sm->selectedMethod->eap_method_free)( |
| 544 | eap_sm->methodData); |
| 545 | eap_sm->methodData = NULL; |
| 546 | } |
| 547 | else |
| 548 | { |
| 549 | free(eap_sm->methodData); |
| 550 | eap_sm->methodData = NULL; |
| 551 | } |
| 552 | } |
| 553 | break; |
| 554 | case DECISION_SUCCESS: |
| 555 | TRACE_DEBUG(FULL,"%s[EAP Protocol] Authentication Success [User: %s].",DIAMEAP_EXTENSION,eap_sm->user.userid) |
| 556 | ; |
| 557 | eap_sm->lastId = eap_sm->currentId; |
| 558 | diameap_ba_nextid(eap_sm, &eap_sm->currentId); |
| 559 | CHECK_FCT(diameap_eap_new(EAP_SUCCESS, (u8) eap_sm->currentId, TYPE_NONE, NULL, 0,&eap_i->aaaEapReqData)) |
| 560 | ; |
| 561 | if (eap_i->aaaEapMSKData != NULL) |
| 562 | { |
| 563 | TRACE_DEBUG(FULL+1,"%s[EAP Protocol] EAP Key available [User: %s].",DIAMEAP_EXTENSION,eap_sm->user.userid); |
| 564 | eap_i->aaaEapKeyAvailable = TRUE; |
| 565 | } |
| 566 | else |
| 567 | { |
| 568 | TRACE_DEBUG(FULL+1,"%s[EAP Protocol] No EAP Key available [User: %s].",DIAMEAP_EXTENSION,eap_sm->user.userid); |
| 569 | } |
| 570 | eap_i->aaaSuccess = TRUE; |
| 571 | *non_fatal_error = FALSE; |
| 572 | eap_sm->eap_state = EAP_END; |
| 573 | if (eap_sm->selectedMethod->eap_method_free) |
| 574 | { |
| 575 | (*eap_sm->selectedMethod->eap_method_free)( |
| 576 | eap_sm->methodData); |
| 577 | eap_sm->methodData = NULL; |
| 578 | } |
| 579 | else |
| 580 | { |
| 581 | if (eap_sm->methodData) |
| 582 | { |
| 583 | free(eap_sm->methodData); |
| 584 | eap_sm->methodData = NULL; |
| 585 | } |
| 586 | } |
| 587 | break; |
| 588 | default: |
| 589 | TRACE_DEBUG(INFO,"%sIncorrect EAP Decision.(Please report this problem.)",DIAMEAP_EXTENSION) |
| 590 | ; |
| 591 | } |
| 592 | break; |
| 593 | |
| 594 | case EAP_END: |
| 595 | break; |
| 596 | |
| 597 | case EAP_IDLE: |
| 598 | break; |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | return 0; |
| 603 | } |
| 604 | |