Added missing option to connect to WebServer
This commit is contained in:
@@ -7,6 +7,7 @@ import dev.unlegitdqrk.unlegitlibrary.network.utils.NetworkUtils;
|
||||
import org.openautonomousconnection.protocol.ProtocolBridge;
|
||||
import org.openautonomousconnection.protocol.packets.OACPacket;
|
||||
import org.openautonomousconnection.protocol.side.client.events.ConnectedToProtocolINSServerEvent;
|
||||
import org.openautonomousconnection.protocol.side.client.events.ConnectedToProtocolWebServerEvent;
|
||||
import org.openautonomousconnection.protocol.side.ins.ConnectedProtocolClient;
|
||||
import org.openautonomousconnection.protocol.side.ins.events.ConnectedProtocolClientEvent;
|
||||
import org.openautonomousconnection.protocol.side.web.ConnectedWebClient;
|
||||
@@ -61,7 +62,8 @@ public final class AuthPacket extends OACPacket {
|
||||
*/
|
||||
@Override
|
||||
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
|
||||
if (protocolBridge.isRunningAsINSServer()) {
|
||||
if (protocolBridge.isRunningAsWebServer()) objectOutputStream.writeObject(protocolBridge.getProtocolVersion());
|
||||
else if (protocolBridge.isRunningAsINSServer()) {
|
||||
objectOutputStream.writeObject(protocolBridge.getProtocolVersion());
|
||||
|
||||
// Read ca files
|
||||
@@ -131,42 +133,47 @@ public final class AuthPacket extends OACPacket {
|
||||
} else if (protocolBridge.isRunningAsClient()) {
|
||||
ProtocolVersion serverVersion = (ProtocolVersion) objectInputStream.readObject();
|
||||
|
||||
if (!protocolBridge.isVersionSupported(serverVersion)) {
|
||||
setResponseCode(INSResponseStatus.RESPONSE_AUTH_FAILED);
|
||||
protocolBridge.getProtocolClient().getClientINSConnection().disconnect();
|
||||
return;
|
||||
} else setResponseCode(INSResponseStatus.RESPONSE_AUTH_SUCCESS);
|
||||
|
||||
String caPrefix = objectInputStream.readUTF();
|
||||
|
||||
String caKey = objectInputStream.readUTF();
|
||||
String caPem = objectInputStream.readUTF();
|
||||
String caSrl = objectInputStream.readUTF();
|
||||
|
||||
if (caKey.equalsIgnoreCase("N/A") || caPem.equalsIgnoreCase("N/A") || caSrl.equalsIgnoreCase("N/A"))
|
||||
setResponseCode(INSResponseStatus.RESPONSE_AUTH_FAILED);
|
||||
else {
|
||||
|
||||
File caPemFile = new File(protocolBridge.getProtocolClient().getFolderStructure().publicCAFolder, caPrefix + ".pem");
|
||||
File caSrlFile = new File(protocolBridge.getProtocolClient().getFolderStructure().publicCAFolder, caPrefix + ".srl");
|
||||
File caKeyFile = new File(protocolBridge.getProtocolClient().getFolderStructure().privateCAFolder, caPrefix + ".key");
|
||||
|
||||
try {
|
||||
if (!caPemFile.exists()) caPemFile.createNewFile();
|
||||
if (!caSrlFile.exists()) caSrlFile.createNewFile();
|
||||
if (!caKeyFile.exists()) caKeyFile.createNewFile();
|
||||
|
||||
FileUtils.writeFile(caPemFile, caPem);
|
||||
FileUtils.writeFile(caSrlFile, caKey);
|
||||
FileUtils.writeFile(caKeyFile, caSrl);
|
||||
} catch (Exception exception) {
|
||||
protocolBridge.getLogger().exception("Failed to create/save ca-files", exception);
|
||||
try {
|
||||
if (!protocolBridge.isVersionSupported(serverVersion)) {
|
||||
setResponseCode(INSResponseStatus.RESPONSE_AUTH_FAILED);
|
||||
}
|
||||
}
|
||||
protocolBridge.getProtocolClient().getClientINSConnection().disconnect();
|
||||
return;
|
||||
} else setResponseCode(INSResponseStatus.RESPONSE_AUTH_SUCCESS);
|
||||
|
||||
protocolBridge.getProtocolClient().setServerVersion(serverVersion);
|
||||
protocolBridge.getProtocolSettings().eventManager.executeEvent(new ConnectedToProtocolINSServerEvent(protocolBridge.getProtocolClient()));
|
||||
String caPrefix = objectInputStream.readUTF();
|
||||
|
||||
String caKey = objectInputStream.readUTF();
|
||||
String caPem = objectInputStream.readUTF();
|
||||
String caSrl = objectInputStream.readUTF();
|
||||
|
||||
if (caKey.equalsIgnoreCase("N/A") || caPem.equalsIgnoreCase("N/A") || caSrl.equalsIgnoreCase("N/A"))
|
||||
setResponseCode(INSResponseStatus.RESPONSE_AUTH_FAILED);
|
||||
else {
|
||||
|
||||
File caPemFile = new File(protocolBridge.getProtocolClient().getFolderStructure().publicCAFolder, caPrefix + ".pem");
|
||||
File caSrlFile = new File(protocolBridge.getProtocolClient().getFolderStructure().publicCAFolder, caPrefix + ".srl");
|
||||
File caKeyFile = new File(protocolBridge.getProtocolClient().getFolderStructure().privateCAFolder, caPrefix + ".key");
|
||||
|
||||
try {
|
||||
if (!caPemFile.exists()) caPemFile.createNewFile();
|
||||
if (!caSrlFile.exists()) caSrlFile.createNewFile();
|
||||
if (!caKeyFile.exists()) caKeyFile.createNewFile();
|
||||
|
||||
FileUtils.writeFile(caPemFile, caPem);
|
||||
FileUtils.writeFile(caSrlFile, caKey);
|
||||
FileUtils.writeFile(caKeyFile, caSrl);
|
||||
} catch (Exception exception) {
|
||||
protocolBridge.getLogger().exception("Failed to create/save ca-files", exception);
|
||||
setResponseCode(INSResponseStatus.RESPONSE_AUTH_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
protocolBridge.getProtocolClient().setInsServerVersion(serverVersion);
|
||||
protocolBridge.getProtocolSettings().eventManager.executeEvent(new ConnectedToProtocolINSServerEvent(protocolBridge.getProtocolClient()));
|
||||
} catch (Exception ignored) {
|
||||
protocolBridge.getProtocolClient().setWebServerVersion(serverVersion);
|
||||
protocolBridge.getProtocolSettings().eventManager.executeEvent(new ConnectedToProtocolWebServerEvent(protocolBridge.getProtocolClient()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.openautonomousconnection.protocol.packets.v1_0_0.beta;
|
||||
|
||||
import dev.unlegitdqrk.unlegitlibrary.network.system.packets.PacketHandler;
|
||||
import lombok.Getter;
|
||||
import org.openautonomousconnection.protocol.packets.OACPacket;
|
||||
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
public final class WebStreamChunkPacket extends OACPacket {
|
||||
|
||||
@Getter
|
||||
private int seq;
|
||||
@Getter
|
||||
private byte[] data;
|
||||
|
||||
public WebStreamChunkPacket() {
|
||||
super(11, ProtocolVersion.PV_1_0_0_BETA);
|
||||
}
|
||||
|
||||
public WebStreamChunkPacket(int seq, byte[] data) {
|
||||
super(11, ProtocolVersion.PV_1_0_0_BETA);
|
||||
this.seq = seq;
|
||||
this.data = (data != null) ? data : new byte[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWrite(PacketHandler handler, ObjectOutputStream out) throws IOException {
|
||||
out.writeInt(seq);
|
||||
out.writeInt(data.length);
|
||||
out.write(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRead(PacketHandler handler, ObjectInputStream in) throws IOException {
|
||||
seq = in.readInt();
|
||||
int len = in.readInt();
|
||||
if (len < 0) throw new IOException("Negative chunk length");
|
||||
data = in.readNBytes(len);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.openautonomousconnection.protocol.packets.v1_0_0.beta;
|
||||
|
||||
import dev.unlegitdqrk.unlegitlibrary.network.system.packets.PacketHandler;
|
||||
import lombok.Getter;
|
||||
import org.openautonomousconnection.protocol.packets.OACPacket;
|
||||
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
public final class WebStreamEndPacket extends OACPacket {
|
||||
|
||||
@Getter
|
||||
private boolean ok;
|
||||
|
||||
public WebStreamEndPacket() {
|
||||
super(12, ProtocolVersion.PV_1_0_0_BETA);
|
||||
}
|
||||
|
||||
public WebStreamEndPacket(boolean ok) {
|
||||
super(12, ProtocolVersion.PV_1_0_0_BETA);
|
||||
this.ok = ok;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWrite(PacketHandler handler, ObjectOutputStream out) throws IOException {
|
||||
out.writeBoolean(ok);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRead(PacketHandler handler, ObjectInputStream in) throws IOException {
|
||||
ok = in.readBoolean();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package org.openautonomousconnection.protocol.packets.v1_0_0.beta;
|
||||
|
||||
import dev.unlegitdqrk.unlegitlibrary.network.system.packets.PacketHandler;
|
||||
import lombok.Getter;
|
||||
import org.openautonomousconnection.protocol.packets.OACPacket;
|
||||
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.Map;
|
||||
|
||||
public final class WebStreamStartPacket extends OACPacket {
|
||||
|
||||
@Getter
|
||||
private int statusCode;
|
||||
@Getter
|
||||
private String contentType;
|
||||
@Getter
|
||||
private Map<String, String> headers;
|
||||
@Getter
|
||||
private long totalLength;
|
||||
|
||||
public WebStreamStartPacket() {
|
||||
super(10, ProtocolVersion.PV_1_0_0_BETA);
|
||||
}
|
||||
|
||||
public WebStreamStartPacket(int statusCode, String contentType, Map<String, String> headers, long totalLength) {
|
||||
super(10, ProtocolVersion.PV_1_0_0_BETA);
|
||||
this.statusCode = statusCode;
|
||||
this.contentType = contentType;
|
||||
this.headers = headers;
|
||||
this.totalLength = totalLength;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWrite(PacketHandler handler, ObjectOutputStream out) throws IOException {
|
||||
out.writeInt(statusCode);
|
||||
out.writeUTF(contentType != null ? contentType : "application/octet-stream");
|
||||
out.writeObject(headers);
|
||||
out.writeLong(totalLength);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void onRead(PacketHandler handler, ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
statusCode = in.readInt();
|
||||
contentType = in.readUTF();
|
||||
headers = (Map<String, String>) in.readObject();
|
||||
totalLength = in.readLong();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user