Ray Milkey
Committed by Gerrit Code Review

Minor AAA refactoring

- pulled some common code out into a method
- fixed some spacing problems

Change-Id: I7c4f0cc6f236e8c05188fb94df3ec9ebe70140bf
...@@ -337,6 +337,29 @@ public class AAA { ...@@ -337,6 +337,29 @@ public class AAA {
337 } 337 }
338 } 338 }
339 339
340 + /**
341 + * Creates and initializes common fields of a RADIUS packet.
342 + *
343 + * @param identifier RADIUS identifier
344 + * @param eapPacket EAP packet
345 + * @return RADIUS packet
346 + */
347 + private RADIUS getRadiusPayload(byte identifier, EAP eapPacket) {
348 + RADIUS radiusPayload =
349 + new RADIUS(RADIUS.RADIUS_CODE_ACCESS_REQUEST,
350 + eapPacket.getIdentifier());
351 + radiusPayload.setIdentifier(identifier);
352 + radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME,
353 + eapPacket.getData());
354 +
355 + radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP,
356 + AAA.this.parsedNasIpAddress.getAddress());
357 +
358 + radiusPayload.encapsulateMessage(eapPacket);
359 + radiusPayload.addMessageAuthenticator(AAA.this.radiusSecret);
360 +
361 + return radiusPayload;
362 + }
340 363
341 /** 364 /**
342 * Handles PAE packets (supplicant). 365 * Handles PAE packets (supplicant).
...@@ -377,75 +400,46 @@ public class AAA { ...@@ -377,75 +400,46 @@ public class AAA {
377 break; 400 break;
378 case EAPOL.EAPOL_PACKET: 401 case EAPOL.EAPOL_PACKET:
379 RADIUS radiusPayload; 402 RADIUS radiusPayload;
380 - //check if this is a Response/Identify or a Response/TLS 403 + // check if this is a Response/Identify or a Response/TLS
381 EAP eapPacket = (EAP) eapol.getPayload(); 404 EAP eapPacket = (EAP) eapol.getPayload();
382 405
383 byte dataType = eapPacket.getDataType(); 406 byte dataType = eapPacket.getDataType();
384 switch (dataType) { 407 switch (dataType) {
385 408
386 case EAP.ATTR_IDENTITY: 409 case EAP.ATTR_IDENTITY:
387 - //request id access to RADIUS 410 + // request id access to RADIUS
388 stateMachine.setUsername(eapPacket.getData()); 411 stateMachine.setUsername(eapPacket.getData());
389 412
390 - radiusPayload = 413 + radiusPayload = getRadiusPayload(stateMachine.identifier(), eapPacket);
391 - new RADIUS(RADIUS.RADIUS_CODE_ACCESS_REQUEST,
392 - eapPacket.getIdentifier());
393 - radiusPayload.setIdentifier(stateMachine.identifier());
394 - radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME,
395 - eapPacket.getData());
396 -
397 - radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP,
398 - AAA.this.parsedNasIpAddress.getAddress());
399 -
400 - radiusPayload.encapsulateMessage(eapPacket);
401 414
402 // set Request Authenticator in StateMachine 415 // set Request Authenticator in StateMachine
403 stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode()); 416 stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode());
404 - radiusPayload.addMessageAuthenticator(AAA.this.radiusSecret);
405 sendRadiusMessage(radiusPayload); 417 sendRadiusMessage(radiusPayload);
406 418
407 - //change the state to "PENDING" 419 + // change the state to "PENDING"
408 stateMachine.requestAccess(); 420 stateMachine.requestAccess();
409 break; 421 break;
410 case EAP.ATTR_MD5: 422 case EAP.ATTR_MD5:
411 - //verify if the EAP identifier corresponds to the challenge identifier from the client state 423 + // verify if the EAP identifier corresponds to the
412 - //machine. 424 + // challenge identifier from the client state
425 + // machine.
413 if (eapPacket.getIdentifier() == stateMachine.challengeIdentifier()) { 426 if (eapPacket.getIdentifier() == stateMachine.challengeIdentifier()) {
414 //send the RADIUS challenge response 427 //send the RADIUS challenge response
415 - radiusPayload = new RADIUS(RADIUS.RADIUS_CODE_ACCESS_REQUEST, 428 + radiusPayload = getRadiusPayload(stateMachine.challengeIdentifier(), eapPacket);
416 - eapPacket.getIdentifier());
417 - radiusPayload.setIdentifier(stateMachine.challengeIdentifier());
418 - radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME,
419 - stateMachine.username());
420 - radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP,
421 - AAA.this.parsedNasIpAddress.getAddress());
422 -
423 - radiusPayload.encapsulateMessage(eapPacket);
424 429
425 radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE, 430 radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE,
426 stateMachine.challengeState()); 431 stateMachine.challengeState());
427 - radiusPayload.addMessageAuthenticator(AAA.this.radiusSecret);
428 sendRadiusMessage(radiusPayload); 432 sendRadiusMessage(radiusPayload);
429 } 433 }
430 break; 434 break;
431 case EAP.ATTR_TLS: 435 case EAP.ATTR_TLS:
432 - //request id access to RADIUS 436 + // request id access to RADIUS
433 - radiusPayload = new RADIUS(RADIUS.RADIUS_CODE_ACCESS_REQUEST, 437 + radiusPayload = getRadiusPayload(stateMachine.identifier(), eapPacket);
434 - eapPacket.getIdentifier());
435 - radiusPayload.setIdentifier(stateMachine.identifier());
436 - radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME,
437 - stateMachine.username());
438 - radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP,
439 - AAA.this.parsedNasIpAddress.getAddress());
440 -
441 - radiusPayload.encapsulateMessage(eapPacket);
442 438
443 radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE, 439 radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE,
444 stateMachine.challengeState()); 440 stateMachine.challengeState());
445 stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode()); 441 stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode());
446 442
447 - radiusPayload.addMessageAuthenticator(AAA.this.radiusSecret);
448 -
449 sendRadiusMessage(radiusPayload); 443 sendRadiusMessage(radiusPayload);
450 // TODO: this gets called on every fragment, should only be called at TLS-Start 444 // TODO: this gets called on every fragment, should only be called at TLS-Start
451 stateMachine.requestAccess(); 445 stateMachine.requestAccess();
......