From 939901a89abb169648423473056260335d3af639 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Thu, 6 Apr 2023 01:08:05 +0200 Subject: first pass on obfs4-hop pt integration --- .../pluggableTransports/HoppingObfsVpnClient.java | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 app/src/main/java/se/leap/bitmaskclient/pluggableTransports/HoppingObfsVpnClient.java (limited to 'app/src/main/java/se/leap/bitmaskclient/pluggableTransports/HoppingObfsVpnClient.java') diff --git a/app/src/main/java/se/leap/bitmaskclient/pluggableTransports/HoppingObfsVpnClient.java b/app/src/main/java/se/leap/bitmaskclient/pluggableTransports/HoppingObfsVpnClient.java new file mode 100644 index 00000000..1b19213f --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/pluggableTransports/HoppingObfsVpnClient.java @@ -0,0 +1,72 @@ +package se.leap.bitmaskclient.pluggableTransports; + +import static de.blinkt.openvpn.core.connection.Connection.TransportProtocol.KCP; + +import client.Client; +import client.HopClient; +import de.blinkt.openvpn.core.VpnStatus; +import se.leap.bitmaskclient.base.models.Constants; + +public class HoppingObfsVpnClient implements PtClientInterface { + + public static final int PORT = 8080; + public static final String IP = "127.0.0.1"; + + public final HopClient client; + + public HoppingObfsVpnClient(Obfs4Options options) throws IllegalStateException { + + //FIXME: use a different strategy here + //Basically we would want to track if the more performant transport protocol (KCP?/TCP?) usage was successful + //if so, we stick to it, otherwise we flip the flag + boolean kcp = Constants.KCP.equals(options.transport.getProtocols()[0]); + + if (options.transport.getOptions().getEndpoints() == null) { + throw new IllegalStateException("No Endpoints for hopping pt detected!"); + } + + HoppingConfig hoppingConfig = new HoppingConfig(kcp,IP+":"+PORT, options.transport, 10, 10); + try { + client = Client.newFFIHopClient(hoppingConfig.toString()); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + + @Override + public int start() { + try { + client.setEventLogger(this); + return client.start() ? PORT : 0; + } catch (Exception e) { + e.printStackTrace(); + return 0; + } + } + + @Override + public void stop() { + try { + client.stop(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + client.setEventLogger(null); + } + } + + @Override + public boolean isStarted() { + return client.isStarted(); + } + + @Override + public void error(String s) { + VpnStatus.logError("[hopping-obfs4] " + s); + } + + @Override + public void log(String state, String message) { + VpnStatus.logDebug("[hopping-obfs4] " + state + ": " + message); + } +} -- cgit v1.2.3