/** * Set EAP-TLS Statemachine in Start-State and send EAP-Start out. Change the State if a Identity * Frame was received. * * @author Felix Lange <*****@*****.**> */ public class EapStartState implements EapState { EapolMachine eapolMachine; EapFactory eaptlsfactory = new EapTlsFactory(); NetworkHandler nic = NetworkHandler.getInstance(); byte[] data = {}; public EapStartState(EapolMachine eapolMachine) { this.eapolMachine = eapolMachine; } @Override public void send() { EAPFrame eapstart = eaptlsfactory.createFrame("STARTEAP", 0); nic.sendFrame(eapstart.getFrame()); } @Override public void sendTLS(byte[] tlspacket) {} @Override public byte[] receive() { data = nic.receiveFrame(); int id = (int) data[19]; // Get ID // Identity Frame? if (data[22] == 0x01) { eapolMachine.setState(new IdentityState(eapolMachine, id)); } else { eapolMachine.setState(new EapStartState(eapolMachine)); } return data; } @Override public String getState() { return "EapStartState"; } @Override public int getID() { return (int) data[19]; } }
/** * State for Client Hello. Sends the Client Hello Frame. Change state if a Failure,Frag, Frag Start, * Nofrag or Frag End Frame was received. * * @author Felix Lange <*****@*****.**> */ public class HelloState implements EapState { private static final Logger LOGGER = LogManager.getLogger(HelloState.class); EapolMachine eapolMachine; int id; EapFactory eaptlsfactory = new EapTlsFactory(); NetworkHandler nic = NetworkHandler.getInstance(); byte[] data = {}; public HelloState(EapolMachine eapolMachine, int id) { this.eapolMachine = eapolMachine; this.id = id; } @Override public void send() { // TODO Auto-generated method stub } @Override public void sendTLS(byte[] tlspacket) { EAPFrame eapstart = eaptlsfactory.createFrame("EAPTLSCH", id, tlspacket); LOGGER.debug("sendTLS(): {}", eapolMachine.getState()); nic.sendFrame(eapstart.getFrame()); } @Override public byte[] receive() { data = nic.receiveFrame(); id = (int) data[19]; // Get ID LOGGER.debug("receive() TLS-FLAG: {}", Byte.toString(data[23])); if (data[23] == (byte) 0xc0) { eapolMachine.setState(new FragStartState(eapolMachine, id)); } else if (data[23] == (byte) 0x80) { eapolMachine.setState(new NoFragState(eapolMachine, id)); // Nur zum // Testen! // Muss // durch // seperaten // State // ersetzt // werden } else if (data[18] == 0x04) { eapolMachine.setState(new FailureState(eapolMachine, id)); } else { eapolMachine.setState(new FragState(eapolMachine, id)); } LOGGER.debug("change State to: {}", eapolMachine.getState()); return data; } @Override public String getState() { return "HelloState"; } @Override public int getID() { return id; } }
/** * Last state in the protocolflow, sends the last EAP-ACK and switch to Success or Failure. This * depends on the received frame. * * @author Felix Lange <*****@*****.**> */ public class FinishedState implements EapState { private static final Logger LOGGER = LogManager.getLogger(FragEndState.class); EapolMachine eapolMachine; int id; EapFactory eaptlsfactory = new EapTlsFactory(); NetworkHandler nic = NetworkHandler.getInstance(); byte[] data = {}; public FinishedState(EapolMachine eapolMachine, int id) { this.eapolMachine = eapolMachine; this.id = id; } @Override public void send() { EAPFrame eapstart = eaptlsfactory.createFrame("EAPTLSFRAGACK", id); LOGGER.debug("send(): {}", eapolMachine.getState()); nic.sendFrame(eapstart.getFrame()); } @Override public void sendTLS(byte[] tlspacket) { EAPFrame eapstart = eaptlsfactory.createFrame("EAPTLSCH", id, tlspacket); LOGGER.debug("sendTLS(): {}", eapolMachine.getState()); nic.sendFrame(eapstart.getFrame()); } @Override public byte[] receive() { data = nic.receiveFrame(); id = (int) data[19]; // Get ID if (data[18] == (byte) 0x03) { eapolMachine.setState(new SuccessState(eapolMachine, id)); } else if (data[18] == (byte) 0x04) { eapolMachine.setState(new FailureState(eapolMachine, id)); } return data; } @Override public String getState() { return "FinishedState"; } @Override public int getID() { return id; } }