@Override public void fromBytes(final ByteBuf stream) { // Read the id short id = stream.readShort(); if (id == -1) { // Invalid packet ThELog.warning("Unknown packet detected"); return; } // Get the class for that id Class epClass = NetworkHandler.getPacketClassFromID(id); if (epClass == null) { return; } // Construct the class try { this.embeddedPacket = (ThEBasePacket) epClass.newInstance(); // Pass to packet this.embeddedPacket.fromBytes(stream); } catch (Exception e) { // Packet did not have default constructor ThELog.warning("Unable to construct packet %s", epClass.getCanonicalName()); } }
@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 void sendTLS(byte[] tlspacket) { EAPFrame eapstart = eaptlsfactory.createFrame("EAPTLSCH", id, tlspacket); LOGGER.debug("sendTLS(): {}", eapolMachine.getState()); nic.sendFrame(eapstart.getFrame()); }
@Override public void send() { EAPFrame eapstart = eaptlsfactory.createFrame("EAPTLSFRAGACK", id); LOGGER.debug("send(): {}", eapolMachine.getState()); nic.sendFrame(eapstart.getFrame()); }
@Override public void handleServerSide(PacketHackingEntityStart message, EntityPlayer player) { Entity entity = player.worldObj.getEntityByID(message.entityId); if (entity != null) { CommonHUDHandler.getHandlerForPlayer(player).setHackedEntity(entity); NetworkHandler.sendToAllAround( message, new NetworkRegistry.TargetPoint( entity.worldObj.provider.dimensionId, entity.posX, entity.posY, entity.posZ, 64)); } }
/** * 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]; } }
@Override public void toBytes(final ByteBuf stream) { if (this.embeddedPacket != null) { // Write the id short id = NetworkHandler.getPacketID(this.embeddedPacket); stream.writeShort(id); // Call embedded this.embeddedPacket.toBytes(stream); } else { // Write -1 stream.writeShort(-1); } }
@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 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 void send() { EAPFrame eapstart = eaptlsfactory.createFrame("STARTEAP", 0); nic.sendFrame(eapstart.getFrame()); }
/** * 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; } }