Fix protocol change from AWG to WG for Android

This commit is contained in:
Mykola Baibuz 2023-10-09 10:29:42 -04:00
parent bdfa8bfe5b
commit c08e23085e
3 changed files with 29 additions and 12 deletions

@ -1 +1 @@
Subproject commit fbb5f586b94efc3f65edeaf9559c8a5c4e752d66 Subproject commit c3ca525f92e57fecdd6047e35b4ccded8b173407

View file

@ -595,7 +595,7 @@ public final class Interface {
if (jc < 0) if (jc < 0)
throw new BadConfigException( throw new BadConfigException(
Section.INTERFACE, Location.JC, Reason.INVALID_VALUE, String.valueOf(jc)); Section.INTERFACE, Location.JC, Reason.INVALID_VALUE, String.valueOf(jc));
this.jc = jc == 0 ? Optional.empty() : Optional.of(jc); this.jc = Optional.of(jc);
return this; return this;
} }
@ -603,7 +603,7 @@ public final class Interface {
if (jmin < 0) if (jmin < 0)
throw new BadConfigException( throw new BadConfigException(
Section.INTERFACE, Location.JMIN, Reason.INVALID_VALUE, String.valueOf(jmin)); Section.INTERFACE, Location.JMIN, Reason.INVALID_VALUE, String.valueOf(jmin));
this.jmin = jmin == 0 ? Optional.empty() : Optional.of(jmin); this.jmin = Optional.of(jmin);
return this; return this;
} }
@ -611,7 +611,7 @@ public final class Interface {
if (jmax < 0) if (jmax < 0)
throw new BadConfigException( throw new BadConfigException(
Section.INTERFACE, Location.JMAX, Reason.INVALID_VALUE, String.valueOf(jmax)); Section.INTERFACE, Location.JMAX, Reason.INVALID_VALUE, String.valueOf(jmax));
this.jmax = jmax == 0 ? Optional.empty() : Optional.of(jmax); this.jmax = Optional.of(jmax);
return this; return this;
} }
@ -619,7 +619,7 @@ public final class Interface {
if (s1 < 0) if (s1 < 0)
throw new BadConfigException( throw new BadConfigException(
Section.INTERFACE, Location.S1, Reason.INVALID_VALUE, String.valueOf(s1)); Section.INTERFACE, Location.S1, Reason.INVALID_VALUE, String.valueOf(s1));
this.s1 = s1 == 0 ? Optional.empty() : Optional.of(s1); this.s1 = Optional.of(s1);
return this; return this;
} }
@ -627,7 +627,7 @@ public final class Interface {
if (s2 < 0) if (s2 < 0)
throw new BadConfigException( throw new BadConfigException(
Section.INTERFACE, Location.S2, Reason.INVALID_VALUE, String.valueOf(s2)); Section.INTERFACE, Location.S2, Reason.INVALID_VALUE, String.valueOf(s2));
this.s2 = s2 == 0 ? Optional.empty() : Optional.of(s2); this.s2 = Optional.of(s2);
return this; return this;
} }
@ -635,7 +635,7 @@ public final class Interface {
if (h1 < 0) if (h1 < 0)
throw new BadConfigException( throw new BadConfigException(
Section.INTERFACE, Location.H1, Reason.INVALID_VALUE, String.valueOf(h1)); Section.INTERFACE, Location.H1, Reason.INVALID_VALUE, String.valueOf(h1));
this.h1 = h1 == 0 ? Optional.empty() : Optional.of(h1); this.h1 = Optional.of(h1);
return this; return this;
} }
@ -643,7 +643,7 @@ public final class Interface {
if (h2 < 0) if (h2 < 0)
throw new BadConfigException( throw new BadConfigException(
Section.INTERFACE, Location.H2, Reason.INVALID_VALUE, String.valueOf(h2)); Section.INTERFACE, Location.H2, Reason.INVALID_VALUE, String.valueOf(h2));
this.h2 = h2 == 0 ? Optional.empty() : Optional.of(h2); this.h2 = Optional.of(h2);
return this; return this;
} }
@ -651,7 +651,7 @@ public final class Interface {
if (h3 < 0) if (h3 < 0)
throw new BadConfigException( throw new BadConfigException(
Section.INTERFACE, Location.H3, Reason.INVALID_VALUE, String.valueOf(h3)); Section.INTERFACE, Location.H3, Reason.INVALID_VALUE, String.valueOf(h3));
this.h3 = h3 == 0 ? Optional.empty() : Optional.of(h3); this.h3 = Optional.of(h3);
return this; return this;
} }
@ -659,7 +659,7 @@ public final class Interface {
if (h4 < 0) if (h4 < 0)
throw new BadConfigException( throw new BadConfigException(
Section.INTERFACE, Location.H4, Reason.INVALID_VALUE, String.valueOf(h4)); Section.INTERFACE, Location.H4, Reason.INVALID_VALUE, String.valueOf(h4));
this.h4 = h4 == 0 ? Optional.empty() : Optional.of(h4); this.h4 = Optional.of(h4);
return this; return this;
} }
} }

View file

@ -615,6 +615,17 @@ class VPNService : BaseVpnService(), LocalDnsService.Interface {
ifaceBuilder.parseH2(ifaceConfig["H2"]) ifaceBuilder.parseH2(ifaceConfig["H2"])
ifaceBuilder.parseH3(ifaceConfig["H3"]) ifaceBuilder.parseH3(ifaceConfig["H3"])
ifaceBuilder.parseH4(ifaceConfig["H4"]) ifaceBuilder.parseH4(ifaceConfig["H4"])
} else {
ifaceBuilder.parseJc("0")
ifaceBuilder.parseJmin("0")
ifaceBuilder.parseJmax("0")
ifaceBuilder.parseS1("0")
ifaceBuilder.parseS2("0")
ifaceBuilder.parseH1("0")
ifaceBuilder.parseH2("0")
ifaceBuilder.parseH3("0")
ifaceBuilder.parseH4("0")
} }
/*val jExcludedApplication = obj.getJSONArray("excludedApps") /*val jExcludedApplication = obj.getJSONArray("excludedApps")
(0 until jExcludedApplication.length()).toList().forEach { (0 until jExcludedApplication.length()).toList().forEach {
@ -745,9 +756,15 @@ class VPNService : BaseVpnService(), LocalDnsService.Interface {
val builder = Builder() val builder = Builder()
setupBuilder(wireguard_conf, builder) setupBuilder(wireguard_conf, builder)
builder.setSession("Amnezia") builder.setSession("Amnezia")
builder.establish().use { tun -> builder.establish().use { tun ->
if (tun == null) return if (tun == null) return
currentTunnelHandle = GoBackend.wgTurnOn("Amnezia", tun.detachFd(), wgConfig) if (type == "awg"){
currentTunnelHandle = GoBackend.wgTurnOn("awg0", tun.detachFd(), wgConfig)
} else {
currentTunnelHandle = GoBackend.wgTurnOn("amn0", tun.detachFd(), wgConfig)
}
} }
if (currentTunnelHandle < 0) { if (currentTunnelHandle < 0) {
Log.e(tag, "Activation Error Code -> $currentTunnelHandle") Log.e(tag, "Activation Error Code -> $currentTunnelHandle")