mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2025-02-17 03:32:36 +01:00
hotfix encryption for incoming packetstream
This commit is contained in:
parent
9e8e15e366
commit
17065a2dbb
@ -72,6 +72,7 @@ public class Rc4Obtainer {
|
||||
|
||||
if (payloadBuffer.peak().length == 0) {
|
||||
outgoingHandler.setRc4(rc4Tryout);
|
||||
incomingHandler.setRc4(rc4Tryout);
|
||||
break outerloop;
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package main.protocol.packethandler;
|
||||
|
||||
import main.protocol.HMessage;
|
||||
import main.protocol.TrafficListener;
|
||||
import main.protocol.crypto.RC4;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
@ -10,6 +11,8 @@ import java.util.List;
|
||||
|
||||
public abstract class Handler {
|
||||
|
||||
protected static final boolean DEBUG = false;
|
||||
|
||||
volatile PayloadBuffer payloadBuffer = new PayloadBuffer();
|
||||
volatile OutputStream out;
|
||||
volatile Object[] listeners = null; //get notified on packet send
|
||||
@ -17,6 +20,9 @@ public abstract class Handler {
|
||||
volatile boolean isDataStream = false;
|
||||
volatile int currentIndex = 0;
|
||||
|
||||
protected RC4 clientcipher = null;
|
||||
protected RC4 servercipher = null;
|
||||
|
||||
|
||||
public Handler(OutputStream outputStream, Object[] listeners) {
|
||||
this.listeners = listeners;
|
||||
@ -28,18 +34,11 @@ public abstract class Handler {
|
||||
isDataStream = true;
|
||||
}
|
||||
|
||||
public void act(byte[] buffer) throws IOException {
|
||||
if (isDataStream) {
|
||||
payloadBuffer.push(buffer);
|
||||
notifyBufferListeners(buffer.length);
|
||||
public abstract void act(byte[] buffer) throws IOException;
|
||||
|
||||
if (!isTempBlocked) {
|
||||
flush();
|
||||
}
|
||||
}
|
||||
else {
|
||||
out.write(buffer);
|
||||
}
|
||||
public void setRc4(RC4 rc4) {
|
||||
this.clientcipher = rc4.deepCopy();
|
||||
this.servercipher = rc4.deepCopy();
|
||||
}
|
||||
|
||||
public void block() {
|
||||
@ -73,7 +72,7 @@ public abstract class Handler {
|
||||
|
||||
public abstract void flush() throws IOException;
|
||||
|
||||
|
||||
protected abstract void printForDebugging(byte[] bytes);
|
||||
|
||||
private List<BufferListener> bufferListeners = new ArrayList<>();
|
||||
public void addBufferListener(BufferListener listener) {
|
||||
|
@ -13,13 +13,48 @@ public class IncomingHandler extends Handler {
|
||||
super(outputStream, listeners);
|
||||
}
|
||||
|
||||
|
||||
private final Object lock = new Object();
|
||||
|
||||
private Boolean isEncryptedStream = null;
|
||||
|
||||
|
||||
@Override
|
||||
public void act(byte[] buffer) throws IOException {
|
||||
if (isDataStream) {
|
||||
if (DEBUG) {
|
||||
printForDebugging(buffer);
|
||||
}
|
||||
|
||||
|
||||
if (isEncryptedStream == null || !isEncryptedStream) {
|
||||
payloadBuffer.push(buffer);
|
||||
}
|
||||
else {
|
||||
payloadBuffer.push(servercipher.rc4(buffer));
|
||||
}
|
||||
|
||||
|
||||
notifyBufferListeners(buffer.length);
|
||||
|
||||
if (!isTempBlocked) {
|
||||
flush();
|
||||
}
|
||||
}
|
||||
else {
|
||||
out.write(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendToStream(byte[] buffer) {
|
||||
synchronized (lock) {
|
||||
try {
|
||||
out.write(buffer);
|
||||
out.write(
|
||||
(isEncryptedStream == null || !isEncryptedStream)
|
||||
? buffer
|
||||
: clientcipher.rc4(buffer)
|
||||
);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -33,14 +68,29 @@ public class IncomingHandler extends Handler {
|
||||
|
||||
for (HPacket hpacket : hpackets){
|
||||
HMessage hMessage = new HMessage(hpacket, HMessage.Side.TOCLIENT, currentIndex);
|
||||
if (isDataStream) notifyListeners(hMessage);
|
||||
if (isDataStream) {
|
||||
notifyListeners(hMessage);
|
||||
}
|
||||
|
||||
if (!hMessage.isBlocked()) {
|
||||
out.write(hMessage.getPacket().toBytes());
|
||||
out.write(
|
||||
(isEncryptedStream == null || !isEncryptedStream)
|
||||
? hMessage.getPacket().toBytes()
|
||||
: clientcipher.rc4(hMessage.getPacket().toBytes())
|
||||
);
|
||||
}
|
||||
|
||||
if (isDataStream && isEncryptedStream == null && hpacket.length() == 261) {
|
||||
isEncryptedStream = hpacket.readBoolean(264);
|
||||
}
|
||||
currentIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void printForDebugging(byte[] bytes) {
|
||||
System.out.println("-- DEBUG INCOMING -- " + new HPacket(bytes).toString() + " -- DEBUG --");
|
||||
}
|
||||
}
|
||||
|
@ -14,10 +14,7 @@ public class OutgoingHandler extends Handler {
|
||||
|
||||
private final Object lock = new Object();
|
||||
|
||||
|
||||
private final static int encryptOffset = 3; //all packets with index < 3 aren't encrypted
|
||||
private RC4 clientcipher = null;
|
||||
private RC4 servercipher = null;
|
||||
private List<Byte> tempEncryptedBuffer = new ArrayList<>();
|
||||
|
||||
public OutgoingHandler(OutputStream outputStream, Object[] listeners) {
|
||||
@ -35,7 +32,6 @@ public class OutgoingHandler extends Handler {
|
||||
public void act(byte[] buffer) throws IOException {
|
||||
dataStreamCheck(buffer);
|
||||
if (isDataStream) {
|
||||
|
||||
if (currentIndex < encryptOffset) {
|
||||
payloadBuffer.push(buffer);
|
||||
}
|
||||
@ -45,7 +41,11 @@ public class OutgoingHandler extends Handler {
|
||||
}
|
||||
}
|
||||
else {
|
||||
payloadBuffer.push(clientcipher.rc4(buffer));
|
||||
byte[] tm = clientcipher.rc4(buffer);
|
||||
if (DEBUG) {
|
||||
printForDebugging(tm);
|
||||
}
|
||||
payloadBuffer.push(tm);
|
||||
}
|
||||
|
||||
notifyBufferListeners(buffer.length);
|
||||
@ -60,21 +60,9 @@ public class OutgoingHandler extends Handler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendToStream(byte[] buffer) {
|
||||
synchronized (lock) {
|
||||
try {
|
||||
out.write(servercipher.rc4(buffer));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setRc4(RC4 rc4) {
|
||||
this.clientcipher = rc4;
|
||||
this.servercipher = rc4.deepCopy();
|
||||
|
||||
super.setRc4(rc4);
|
||||
|
||||
byte[] encrbuffer = new byte[tempEncryptedBuffer.size()];
|
||||
for (int i = 0; i < tempEncryptedBuffer.size(); i++) {
|
||||
encrbuffer[i] = tempEncryptedBuffer.get(i);
|
||||
@ -87,6 +75,19 @@ public class OutgoingHandler extends Handler {
|
||||
}
|
||||
tempEncryptedBuffer = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendToStream(byte[] buffer) {
|
||||
synchronized (lock) {
|
||||
try {
|
||||
out.write(servercipher.rc4(buffer));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List<Byte> getEncryptedBuffer() {
|
||||
return tempEncryptedBuffer;
|
||||
}
|
||||
@ -109,4 +110,10 @@ public class OutgoingHandler extends Handler {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void printForDebugging(byte[] bytes) {
|
||||
System.out.println("-- DEBUG OUTGOING -- " + new HPacket(bytes).toString() + " -- DEBUG --");
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,19 @@
|
||||
package main.ui.logger.loggerdisplays;
|
||||
|
||||
import main.misc.OSValidator;
|
||||
|
||||
/**
|
||||
* Created by Jonas on 04/04/18.
|
||||
*/
|
||||
public class PacketLoggerFactory {
|
||||
|
||||
public static PacketLogger get() {
|
||||
if (System.getenv("XDG_CURRENT_DESKTOP") != null && System.getenv("XDG_CURRENT_DESKTOP").toLowerCase().contains("gnome")) {
|
||||
if (OSValidator.isUnix()) {
|
||||
return new GnomeTerminalLogger();
|
||||
}
|
||||
// if (System.getenv("XDG_CURRENT_DESKTOP") != null && System.getenv("XDG_CURRENT_DESKTOP").toLowerCase().contains("gnome")) {
|
||||
// return new GnomeTerminalLogger();
|
||||
// }
|
||||
return new SimpleTerminalLogger();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user