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