From 51d4aea9e2453d7280281b95f188bf132fffc46d Mon Sep 17 00:00:00 2001 From: albexk Date: Tue, 28 Nov 2023 20:07:39 +0300 Subject: [PATCH] Add OpenVpn module --- client/android/build.gradle.kts | 1 + client/android/openvpn/build.gradle.kts | 18 + .../net/openvpn/ovpn3/ClientAPI_Config.java | 18 +- .../ovpn3/ClientAPI_ConnectionInfo.java | 18 +- .../ovpn3/ClientAPI_DynamicChallenge.java | 18 +- .../openvpn/ovpn3/ClientAPI_EvalConfig.java | 18 +- .../net/openvpn/ovpn3/ClientAPI_Event.java | 18 +- .../ovpn3/ClientAPI_ExternalPKIBase.java | 18 +- .../ClientAPI_ExternalPKICertRequest.java | 18 +- .../ClientAPI_ExternalPKIRequestBase.java | 18 +- .../ClientAPI_ExternalPKISignRequest.java | 18 +- .../ovpn3/ClientAPI_InterfaceStats.java | 18 +- .../net/openvpn/ovpn3/ClientAPI_KeyValue.java | 18 +- .../net/openvpn/ovpn3/ClientAPI_LLVector.java | 18 +- .../net/openvpn/ovpn3/ClientAPI_LogInfo.java | 18 +- .../openvpn/ovpn3/ClientAPI_MergeConfig.java | 18 +- .../ovpn3/ClientAPI_OpenVPNClient.java | 18 +- .../ovpn3/ClientAPI_OpenVPNClientHelper.java | 18 +- .../openvpn/ovpn3/ClientAPI_ProvideCreds.java | 18 +- .../ovpn3/ClientAPI_RemoteOverride.java | 18 +- .../openvpn/ovpn3/ClientAPI_ServerEntry.java | 18 +- .../ovpn3/ClientAPI_ServerEntryVector.java | 18 +- .../openvpn/ovpn3/ClientAPI_SessionToken.java | 18 +- .../net/openvpn/ovpn3/ClientAPI_Status.java | 18 +- .../openvpn/ovpn3/ClientAPI_StringVec.java | 18 +- .../ovpn3/ClientAPI_TransportStats.java | 18 +- .../ovpn3/ClientAPI_TunBuilderBase.java | 18 +- .../openvpn/ovpn3/SWIGTYPE_p_std__string.java | 10 +- ...ectorT_openvpn__ClientAPI__KeyValue_t.java | 10 +- .../main/java}/net/openvpn/ovpn3/ovpncli.java | 6 +- .../java}/net/openvpn/ovpn3/ovpncliJNI.java | 6 +- .../amnezia/vpn/protocol/openvpn/OpenVpn.kt | 106 +++++ .../vpn/protocol/openvpn/OpenVpnClient.kt | 418 ++++++++++++++++++ .../vpn/protocol/openvpn/OpenVpnConfig.kt | 20 + client/android/settings.gradle.kts | 1 + .../src/org/amnezia/vpn/AmneziaVpnService.kt | 1 + .../src/org/amnezia/vpn/OpenVPNThreadv3.kt | 259 ----------- 37 files changed, 960 insertions(+), 346 deletions(-) create mode 100644 client/android/openvpn/build.gradle.kts rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/ClientAPI_Config.java (96%) rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/ClientAPI_ConnectionInfo.java (89%) rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/ClientAPI_DynamicChallenge.java (82%) rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/ClientAPI_EvalConfig.java (92%) rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/ClientAPI_Event.java (81%) rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/ClientAPI_ExternalPKIBase.java (72%) rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/ClientAPI_ExternalPKICertRequest.java (79%) rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/ClientAPI_ExternalPKIRequestBase.java (82%) rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/ClientAPI_ExternalPKISignRequest.java (81%) rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/ClientAPI_InterfaceStats.java (85%) rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/ClientAPI_KeyValue.java (78%) rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/ClientAPI_LLVector.java (89%) rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/ClientAPI_LogInfo.java (75%) rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/ClientAPI_MergeConfig.java (84%) rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/ClientAPI_OpenVPNClient.java (93%) rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/ClientAPI_OpenVPNClientHelper.java (84%) rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/ClientAPI_ProvideCreds.java (87%) rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/ClientAPI_RemoteOverride.java (83%) rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/ClientAPI_ServerEntry.java (77%) rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/ClientAPI_ServerEntryVector.java (90%) rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/ClientAPI_SessionToken.java (77%) rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/ClientAPI_Status.java (79%) rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/ClientAPI_StringVec.java (89%) rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/ClientAPI_TransportStats.java (83%) rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/ClientAPI_TunBuilderBase.java (92%) rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/SWIGTYPE_p_std__string.java (75%) rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/SWIGTYPE_p_std__vectorT_openvpn__ClientAPI__KeyValue_t.java (75%) rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/ovpncli.java (75%) rename client/android/{src => openvpn/src/main/java}/net/openvpn/ovpn3/ovpncliJNI.java (99%) create mode 100644 client/android/openvpn/src/main/kotlin/org/amnezia/vpn/protocol/openvpn/OpenVpn.kt create mode 100644 client/android/openvpn/src/main/kotlin/org/amnezia/vpn/protocol/openvpn/OpenVpnClient.kt create mode 100644 client/android/openvpn/src/main/kotlin/org/amnezia/vpn/protocol/openvpn/OpenVpnConfig.kt delete mode 100644 client/android/src/org/amnezia/vpn/OpenVPNThreadv3.kt diff --git a/client/android/build.gradle.kts b/client/android/build.gradle.kts index 6dbf606f..58f241af 100644 --- a/client/android/build.gradle.kts +++ b/client/android/build.gradle.kts @@ -88,6 +88,7 @@ dependencies { implementation(project(":protocolApi")) implementation(project(":wireguard")) implementation(project(":awg")) + implementation(project(":openvpn")) implementation(libs.androidx.core) implementation(libs.androidx.activity) implementation(libs.androidx.security.crypto) diff --git a/client/android/openvpn/build.gradle.kts b/client/android/openvpn/build.gradle.kts new file mode 100644 index 00000000..5949faf2 --- /dev/null +++ b/client/android/openvpn/build.gradle.kts @@ -0,0 +1,18 @@ +plugins { + id(libs.plugins.android.library.get().pluginId) + id(libs.plugins.kotlin.android.get().pluginId) +} + +kotlin { + jvmToolchain(17) +} + +android { + namespace = "org.amnezia.vpn.protocol.openvpn" +} + +dependencies { + compileOnly(project(":utils")) + compileOnly(project(":protocolApi")) + implementation(libs.kotlinx.coroutines) +} diff --git a/client/android/src/net/openvpn/ovpn3/ClientAPI_Config.java b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_Config.java similarity index 96% rename from client/android/src/net/openvpn/ovpn3/ClientAPI_Config.java rename to client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_Config.java index c4abf8b8..4c69c51e 100644 --- a/client/android/src/net/openvpn/ovpn3/ClientAPI_Config.java +++ b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_Config.java @@ -1,8 +1,8 @@ /* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.1 + * This file was automatically generated by SWIG (https://www.swig.org). + * Version 4.1.1 * - * Do not make changes to this file unless you know what you are doing--modify + * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ @@ -21,6 +21,18 @@ public class ClientAPI_Config { return (obj == null) ? 0 : obj.swigCPtr; } + protected static long swigRelease(ClientAPI_Config obj) { + long ptr = 0; + if (obj != null) { + if (!obj.swigCMemOwn) + throw new RuntimeException("Cannot release ownership as memory is not owned"); + ptr = obj.swigCPtr; + obj.swigCMemOwn = false; + obj.delete(); + } + return ptr; + } + @SuppressWarnings("deprecation") protected void finalize() { delete(); diff --git a/client/android/src/net/openvpn/ovpn3/ClientAPI_ConnectionInfo.java b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_ConnectionInfo.java similarity index 89% rename from client/android/src/net/openvpn/ovpn3/ClientAPI_ConnectionInfo.java rename to client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_ConnectionInfo.java index 26742231..17d54861 100644 --- a/client/android/src/net/openvpn/ovpn3/ClientAPI_ConnectionInfo.java +++ b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_ConnectionInfo.java @@ -1,8 +1,8 @@ /* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.1 + * This file was automatically generated by SWIG (https://www.swig.org). + * Version 4.1.1 * - * Do not make changes to this file unless you know what you are doing--modify + * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ @@ -21,6 +21,18 @@ public class ClientAPI_ConnectionInfo { return (obj == null) ? 0 : obj.swigCPtr; } + protected static long swigRelease(ClientAPI_ConnectionInfo obj) { + long ptr = 0; + if (obj != null) { + if (!obj.swigCMemOwn) + throw new RuntimeException("Cannot release ownership as memory is not owned"); + ptr = obj.swigCPtr; + obj.swigCMemOwn = false; + obj.delete(); + } + return ptr; + } + @SuppressWarnings("deprecation") protected void finalize() { delete(); diff --git a/client/android/src/net/openvpn/ovpn3/ClientAPI_DynamicChallenge.java b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_DynamicChallenge.java similarity index 82% rename from client/android/src/net/openvpn/ovpn3/ClientAPI_DynamicChallenge.java rename to client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_DynamicChallenge.java index 99d6d569..0bebb47f 100644 --- a/client/android/src/net/openvpn/ovpn3/ClientAPI_DynamicChallenge.java +++ b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_DynamicChallenge.java @@ -1,8 +1,8 @@ /* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.1 + * This file was automatically generated by SWIG (https://www.swig.org). + * Version 4.1.1 * - * Do not make changes to this file unless you know what you are doing--modify + * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ @@ -21,6 +21,18 @@ public class ClientAPI_DynamicChallenge { return (obj == null) ? 0 : obj.swigCPtr; } + protected static long swigRelease(ClientAPI_DynamicChallenge obj) { + long ptr = 0; + if (obj != null) { + if (!obj.swigCMemOwn) + throw new RuntimeException("Cannot release ownership as memory is not owned"); + ptr = obj.swigCPtr; + obj.swigCMemOwn = false; + obj.delete(); + } + return ptr; + } + @SuppressWarnings("deprecation") protected void finalize() { delete(); diff --git a/client/android/src/net/openvpn/ovpn3/ClientAPI_EvalConfig.java b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_EvalConfig.java similarity index 92% rename from client/android/src/net/openvpn/ovpn3/ClientAPI_EvalConfig.java rename to client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_EvalConfig.java index 790e85e3..be392848 100644 --- a/client/android/src/net/openvpn/ovpn3/ClientAPI_EvalConfig.java +++ b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_EvalConfig.java @@ -1,8 +1,8 @@ /* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.1 + * This file was automatically generated by SWIG (https://www.swig.org). + * Version 4.1.1 * - * Do not make changes to this file unless you know what you are doing--modify + * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ @@ -21,6 +21,18 @@ public class ClientAPI_EvalConfig { return (obj == null) ? 0 : obj.swigCPtr; } + protected static long swigRelease(ClientAPI_EvalConfig obj) { + long ptr = 0; + if (obj != null) { + if (!obj.swigCMemOwn) + throw new RuntimeException("Cannot release ownership as memory is not owned"); + ptr = obj.swigCPtr; + obj.swigCMemOwn = false; + obj.delete(); + } + return ptr; + } + @SuppressWarnings("deprecation") protected void finalize() { delete(); diff --git a/client/android/src/net/openvpn/ovpn3/ClientAPI_Event.java b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_Event.java similarity index 81% rename from client/android/src/net/openvpn/ovpn3/ClientAPI_Event.java rename to client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_Event.java index 80cfe99e..cf7f578d 100644 --- a/client/android/src/net/openvpn/ovpn3/ClientAPI_Event.java +++ b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_Event.java @@ -1,8 +1,8 @@ /* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.1 + * This file was automatically generated by SWIG (https://www.swig.org). + * Version 4.1.1 * - * Do not make changes to this file unless you know what you are doing--modify + * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ @@ -21,6 +21,18 @@ public class ClientAPI_Event { return (obj == null) ? 0 : obj.swigCPtr; } + protected static long swigRelease(ClientAPI_Event obj) { + long ptr = 0; + if (obj != null) { + if (!obj.swigCMemOwn) + throw new RuntimeException("Cannot release ownership as memory is not owned"); + ptr = obj.swigCPtr; + obj.swigCMemOwn = false; + obj.delete(); + } + return ptr; + } + @SuppressWarnings("deprecation") protected void finalize() { delete(); diff --git a/client/android/src/net/openvpn/ovpn3/ClientAPI_ExternalPKIBase.java b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_ExternalPKIBase.java similarity index 72% rename from client/android/src/net/openvpn/ovpn3/ClientAPI_ExternalPKIBase.java rename to client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_ExternalPKIBase.java index aa80ac77..ee44c1d5 100644 --- a/client/android/src/net/openvpn/ovpn3/ClientAPI_ExternalPKIBase.java +++ b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_ExternalPKIBase.java @@ -1,8 +1,8 @@ /* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.1 + * This file was automatically generated by SWIG (https://www.swig.org). + * Version 4.1.1 * - * Do not make changes to this file unless you know what you are doing--modify + * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ @@ -21,6 +21,18 @@ public class ClientAPI_ExternalPKIBase { return (obj == null) ? 0 : obj.swigCPtr; } + protected static long swigRelease(ClientAPI_ExternalPKIBase obj) { + long ptr = 0; + if (obj != null) { + if (!obj.swigCMemOwn) + throw new RuntimeException("Cannot release ownership as memory is not owned"); + ptr = obj.swigCPtr; + obj.swigCMemOwn = false; + obj.delete(); + } + return ptr; + } + @SuppressWarnings("deprecation") protected void finalize() { delete(); diff --git a/client/android/src/net/openvpn/ovpn3/ClientAPI_ExternalPKICertRequest.java b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_ExternalPKICertRequest.java similarity index 79% rename from client/android/src/net/openvpn/ovpn3/ClientAPI_ExternalPKICertRequest.java rename to client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_ExternalPKICertRequest.java index decd5baf..fe681ad8 100644 --- a/client/android/src/net/openvpn/ovpn3/ClientAPI_ExternalPKICertRequest.java +++ b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_ExternalPKICertRequest.java @@ -1,8 +1,8 @@ /* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.1 + * This file was automatically generated by SWIG (https://www.swig.org). + * Version 4.1.1 * - * Do not make changes to this file unless you know what you are doing--modify + * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ @@ -20,6 +20,18 @@ public class ClientAPI_ExternalPKICertRequest extends ClientAPI_ExternalPKIReque return (obj == null) ? 0 : obj.swigCPtr; } + protected static long swigRelease(ClientAPI_ExternalPKICertRequest obj) { + long ptr = 0; + if (obj != null) { + if (!obj.swigCMemOwn) + throw new RuntimeException("Cannot release ownership as memory is not owned"); + ptr = obj.swigCPtr; + obj.swigCMemOwn = false; + obj.delete(); + } + return ptr; + } + @SuppressWarnings("deprecation") protected void finalize() { delete(); diff --git a/client/android/src/net/openvpn/ovpn3/ClientAPI_ExternalPKIRequestBase.java b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_ExternalPKIRequestBase.java similarity index 82% rename from client/android/src/net/openvpn/ovpn3/ClientAPI_ExternalPKIRequestBase.java rename to client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_ExternalPKIRequestBase.java index 75a6072e..65551a2c 100644 --- a/client/android/src/net/openvpn/ovpn3/ClientAPI_ExternalPKIRequestBase.java +++ b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_ExternalPKIRequestBase.java @@ -1,8 +1,8 @@ /* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.1 + * This file was automatically generated by SWIG (https://www.swig.org). + * Version 4.1.1 * - * Do not make changes to this file unless you know what you are doing--modify + * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ @@ -21,6 +21,18 @@ public class ClientAPI_ExternalPKIRequestBase { return (obj == null) ? 0 : obj.swigCPtr; } + protected static long swigRelease(ClientAPI_ExternalPKIRequestBase obj) { + long ptr = 0; + if (obj != null) { + if (!obj.swigCMemOwn) + throw new RuntimeException("Cannot release ownership as memory is not owned"); + ptr = obj.swigCPtr; + obj.swigCMemOwn = false; + obj.delete(); + } + return ptr; + } + @SuppressWarnings("deprecation") protected void finalize() { delete(); diff --git a/client/android/src/net/openvpn/ovpn3/ClientAPI_ExternalPKISignRequest.java b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_ExternalPKISignRequest.java similarity index 81% rename from client/android/src/net/openvpn/ovpn3/ClientAPI_ExternalPKISignRequest.java rename to client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_ExternalPKISignRequest.java index bd91e4f1..a08ae14f 100644 --- a/client/android/src/net/openvpn/ovpn3/ClientAPI_ExternalPKISignRequest.java +++ b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_ExternalPKISignRequest.java @@ -1,8 +1,8 @@ /* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.1 + * This file was automatically generated by SWIG (https://www.swig.org). + * Version 4.1.1 * - * Do not make changes to this file unless you know what you are doing--modify + * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ @@ -20,6 +20,18 @@ public class ClientAPI_ExternalPKISignRequest extends ClientAPI_ExternalPKIReque return (obj == null) ? 0 : obj.swigCPtr; } + protected static long swigRelease(ClientAPI_ExternalPKISignRequest obj) { + long ptr = 0; + if (obj != null) { + if (!obj.swigCMemOwn) + throw new RuntimeException("Cannot release ownership as memory is not owned"); + ptr = obj.swigCPtr; + obj.swigCMemOwn = false; + obj.delete(); + } + return ptr; + } + @SuppressWarnings("deprecation") protected void finalize() { delete(); diff --git a/client/android/src/net/openvpn/ovpn3/ClientAPI_InterfaceStats.java b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_InterfaceStats.java similarity index 85% rename from client/android/src/net/openvpn/ovpn3/ClientAPI_InterfaceStats.java rename to client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_InterfaceStats.java index f486589f..325fddca 100644 --- a/client/android/src/net/openvpn/ovpn3/ClientAPI_InterfaceStats.java +++ b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_InterfaceStats.java @@ -1,8 +1,8 @@ /* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.1 + * This file was automatically generated by SWIG (https://www.swig.org). + * Version 4.1.1 * - * Do not make changes to this file unless you know what you are doing--modify + * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ @@ -21,6 +21,18 @@ public class ClientAPI_InterfaceStats { return (obj == null) ? 0 : obj.swigCPtr; } + protected static long swigRelease(ClientAPI_InterfaceStats obj) { + long ptr = 0; + if (obj != null) { + if (!obj.swigCMemOwn) + throw new RuntimeException("Cannot release ownership as memory is not owned"); + ptr = obj.swigCPtr; + obj.swigCMemOwn = false; + obj.delete(); + } + return ptr; + } + @SuppressWarnings("deprecation") protected void finalize() { delete(); diff --git a/client/android/src/net/openvpn/ovpn3/ClientAPI_KeyValue.java b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_KeyValue.java similarity index 78% rename from client/android/src/net/openvpn/ovpn3/ClientAPI_KeyValue.java rename to client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_KeyValue.java index 055677be..b0c67c71 100644 --- a/client/android/src/net/openvpn/ovpn3/ClientAPI_KeyValue.java +++ b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_KeyValue.java @@ -1,8 +1,8 @@ /* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.1 + * This file was automatically generated by SWIG (https://www.swig.org). + * Version 4.1.1 * - * Do not make changes to this file unless you know what you are doing--modify + * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ @@ -21,6 +21,18 @@ public class ClientAPI_KeyValue { return (obj == null) ? 0 : obj.swigCPtr; } + protected static long swigRelease(ClientAPI_KeyValue obj) { + long ptr = 0; + if (obj != null) { + if (!obj.swigCMemOwn) + throw new RuntimeException("Cannot release ownership as memory is not owned"); + ptr = obj.swigCPtr; + obj.swigCMemOwn = false; + obj.delete(); + } + return ptr; + } + @SuppressWarnings("deprecation") protected void finalize() { delete(); diff --git a/client/android/src/net/openvpn/ovpn3/ClientAPI_LLVector.java b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_LLVector.java similarity index 89% rename from client/android/src/net/openvpn/ovpn3/ClientAPI_LLVector.java rename to client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_LLVector.java index c1443386..98be4f93 100644 --- a/client/android/src/net/openvpn/ovpn3/ClientAPI_LLVector.java +++ b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_LLVector.java @@ -1,8 +1,8 @@ /* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.1 + * This file was automatically generated by SWIG (https://www.swig.org). + * Version 4.1.1 * - * Do not make changes to this file unless you know what you are doing--modify + * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ @@ -21,6 +21,18 @@ public class ClientAPI_LLVector extends java.util.AbstractList implements return (obj == null) ? 0 : obj.swigCPtr; } + protected static long swigRelease(ClientAPI_LLVector obj) { + long ptr = 0; + if (obj != null) { + if (!obj.swigCMemOwn) + throw new RuntimeException("Cannot release ownership as memory is not owned"); + ptr = obj.swigCPtr; + obj.swigCMemOwn = false; + obj.delete(); + } + return ptr; + } + @SuppressWarnings("deprecation") protected void finalize() { delete(); diff --git a/client/android/src/net/openvpn/ovpn3/ClientAPI_LogInfo.java b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_LogInfo.java similarity index 75% rename from client/android/src/net/openvpn/ovpn3/ClientAPI_LogInfo.java rename to client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_LogInfo.java index 008aeb22..ac18d163 100644 --- a/client/android/src/net/openvpn/ovpn3/ClientAPI_LogInfo.java +++ b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_LogInfo.java @@ -1,8 +1,8 @@ /* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.1 + * This file was automatically generated by SWIG (https://www.swig.org). + * Version 4.1.1 * - * Do not make changes to this file unless you know what you are doing--modify + * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ @@ -21,6 +21,18 @@ public class ClientAPI_LogInfo { return (obj == null) ? 0 : obj.swigCPtr; } + protected static long swigRelease(ClientAPI_LogInfo obj) { + long ptr = 0; + if (obj != null) { + if (!obj.swigCMemOwn) + throw new RuntimeException("Cannot release ownership as memory is not owned"); + ptr = obj.swigCPtr; + obj.swigCMemOwn = false; + obj.delete(); + } + return ptr; + } + @SuppressWarnings("deprecation") protected void finalize() { delete(); diff --git a/client/android/src/net/openvpn/ovpn3/ClientAPI_MergeConfig.java b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_MergeConfig.java similarity index 84% rename from client/android/src/net/openvpn/ovpn3/ClientAPI_MergeConfig.java rename to client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_MergeConfig.java index 74d37c77..f8994bfb 100644 --- a/client/android/src/net/openvpn/ovpn3/ClientAPI_MergeConfig.java +++ b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_MergeConfig.java @@ -1,8 +1,8 @@ /* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.1 + * This file was automatically generated by SWIG (https://www.swig.org). + * Version 4.1.1 * - * Do not make changes to this file unless you know what you are doing--modify + * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ @@ -21,6 +21,18 @@ public class ClientAPI_MergeConfig { return (obj == null) ? 0 : obj.swigCPtr; } + protected static long swigRelease(ClientAPI_MergeConfig obj) { + long ptr = 0; + if (obj != null) { + if (!obj.swigCMemOwn) + throw new RuntimeException("Cannot release ownership as memory is not owned"); + ptr = obj.swigCPtr; + obj.swigCMemOwn = false; + obj.delete(); + } + return ptr; + } + @SuppressWarnings("deprecation") protected void finalize() { delete(); diff --git a/client/android/src/net/openvpn/ovpn3/ClientAPI_OpenVPNClient.java b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_OpenVPNClient.java similarity index 93% rename from client/android/src/net/openvpn/ovpn3/ClientAPI_OpenVPNClient.java rename to client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_OpenVPNClient.java index 19701ab3..c37da49a 100644 --- a/client/android/src/net/openvpn/ovpn3/ClientAPI_OpenVPNClient.java +++ b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_OpenVPNClient.java @@ -1,8 +1,8 @@ /* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.1 + * This file was automatically generated by SWIG (https://www.swig.org). + * Version 4.1.1 * - * Do not make changes to this file unless you know what you are doing--modify + * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ @@ -20,6 +20,18 @@ public class ClientAPI_OpenVPNClient extends ClientAPI_TunBuilderBase { return (obj == null) ? 0 : obj.swigCPtr; } + protected static long swigRelease(ClientAPI_OpenVPNClient obj) { + long ptr = 0; + if (obj != null) { + if (!obj.swigCMemOwn) + throw new RuntimeException("Cannot release ownership as memory is not owned"); + ptr = obj.swigCPtr; + obj.swigCMemOwn = false; + obj.delete(); + } + return ptr; + } + @SuppressWarnings("deprecation") protected void finalize() { delete(); diff --git a/client/android/src/net/openvpn/ovpn3/ClientAPI_OpenVPNClientHelper.java b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_OpenVPNClientHelper.java similarity index 84% rename from client/android/src/net/openvpn/ovpn3/ClientAPI_OpenVPNClientHelper.java rename to client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_OpenVPNClientHelper.java index 47488823..42345492 100644 --- a/client/android/src/net/openvpn/ovpn3/ClientAPI_OpenVPNClientHelper.java +++ b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_OpenVPNClientHelper.java @@ -1,8 +1,8 @@ /* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.1 + * This file was automatically generated by SWIG (https://www.swig.org). + * Version 4.1.1 * - * Do not make changes to this file unless you know what you are doing--modify + * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ @@ -21,6 +21,18 @@ public class ClientAPI_OpenVPNClientHelper { return (obj == null) ? 0 : obj.swigCPtr; } + protected static long swigRelease(ClientAPI_OpenVPNClientHelper obj) { + long ptr = 0; + if (obj != null) { + if (!obj.swigCMemOwn) + throw new RuntimeException("Cannot release ownership as memory is not owned"); + ptr = obj.swigCPtr; + obj.swigCMemOwn = false; + obj.delete(); + } + return ptr; + } + @SuppressWarnings("deprecation") protected void finalize() { delete(); diff --git a/client/android/src/net/openvpn/ovpn3/ClientAPI_ProvideCreds.java b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_ProvideCreds.java similarity index 87% rename from client/android/src/net/openvpn/ovpn3/ClientAPI_ProvideCreds.java rename to client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_ProvideCreds.java index f82a9c35..073f3034 100644 --- a/client/android/src/net/openvpn/ovpn3/ClientAPI_ProvideCreds.java +++ b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_ProvideCreds.java @@ -1,8 +1,8 @@ /* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.1 + * This file was automatically generated by SWIG (https://www.swig.org). + * Version 4.1.1 * - * Do not make changes to this file unless you know what you are doing--modify + * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ @@ -21,6 +21,18 @@ public class ClientAPI_ProvideCreds { return (obj == null) ? 0 : obj.swigCPtr; } + protected static long swigRelease(ClientAPI_ProvideCreds obj) { + long ptr = 0; + if (obj != null) { + if (!obj.swigCMemOwn) + throw new RuntimeException("Cannot release ownership as memory is not owned"); + ptr = obj.swigCPtr; + obj.swigCMemOwn = false; + obj.delete(); + } + return ptr; + } + @SuppressWarnings("deprecation") protected void finalize() { delete(); diff --git a/client/android/src/net/openvpn/ovpn3/ClientAPI_RemoteOverride.java b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_RemoteOverride.java similarity index 83% rename from client/android/src/net/openvpn/ovpn3/ClientAPI_RemoteOverride.java rename to client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_RemoteOverride.java index 80bdde67..754f3771 100644 --- a/client/android/src/net/openvpn/ovpn3/ClientAPI_RemoteOverride.java +++ b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_RemoteOverride.java @@ -1,8 +1,8 @@ /* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.1 + * This file was automatically generated by SWIG (https://www.swig.org). + * Version 4.1.1 * - * Do not make changes to this file unless you know what you are doing--modify + * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ @@ -21,6 +21,18 @@ public class ClientAPI_RemoteOverride { return (obj == null) ? 0 : obj.swigCPtr; } + protected static long swigRelease(ClientAPI_RemoteOverride obj) { + long ptr = 0; + if (obj != null) { + if (!obj.swigCMemOwn) + throw new RuntimeException("Cannot release ownership as memory is not owned"); + ptr = obj.swigCPtr; + obj.swigCMemOwn = false; + obj.delete(); + } + return ptr; + } + @SuppressWarnings("deprecation") protected void finalize() { delete(); diff --git a/client/android/src/net/openvpn/ovpn3/ClientAPI_ServerEntry.java b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_ServerEntry.java similarity index 77% rename from client/android/src/net/openvpn/ovpn3/ClientAPI_ServerEntry.java rename to client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_ServerEntry.java index f5f48f56..920b3bcc 100644 --- a/client/android/src/net/openvpn/ovpn3/ClientAPI_ServerEntry.java +++ b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_ServerEntry.java @@ -1,8 +1,8 @@ /* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.1 + * This file was automatically generated by SWIG (https://www.swig.org). + * Version 4.1.1 * - * Do not make changes to this file unless you know what you are doing--modify + * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ @@ -21,6 +21,18 @@ public class ClientAPI_ServerEntry { return (obj == null) ? 0 : obj.swigCPtr; } + protected static long swigRelease(ClientAPI_ServerEntry obj) { + long ptr = 0; + if (obj != null) { + if (!obj.swigCMemOwn) + throw new RuntimeException("Cannot release ownership as memory is not owned"); + ptr = obj.swigCPtr; + obj.swigCMemOwn = false; + obj.delete(); + } + return ptr; + } + @SuppressWarnings("deprecation") protected void finalize() { delete(); diff --git a/client/android/src/net/openvpn/ovpn3/ClientAPI_ServerEntryVector.java b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_ServerEntryVector.java similarity index 90% rename from client/android/src/net/openvpn/ovpn3/ClientAPI_ServerEntryVector.java rename to client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_ServerEntryVector.java index 3a899ca5..a4ded35f 100644 --- a/client/android/src/net/openvpn/ovpn3/ClientAPI_ServerEntryVector.java +++ b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_ServerEntryVector.java @@ -1,8 +1,8 @@ /* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.1 + * This file was automatically generated by SWIG (https://www.swig.org). + * Version 4.1.1 * - * Do not make changes to this file unless you know what you are doing--modify + * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ @@ -21,6 +21,18 @@ public class ClientAPI_ServerEntryVector extends java.util.AbstractList implemen return (obj == null) ? 0 : obj.swigCPtr; } + protected static long swigRelease(ClientAPI_StringVec obj) { + long ptr = 0; + if (obj != null) { + if (!obj.swigCMemOwn) + throw new RuntimeException("Cannot release ownership as memory is not owned"); + ptr = obj.swigCPtr; + obj.swigCMemOwn = false; + obj.delete(); + } + return ptr; + } + @SuppressWarnings("deprecation") protected void finalize() { delete(); diff --git a/client/android/src/net/openvpn/ovpn3/ClientAPI_TransportStats.java b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_TransportStats.java similarity index 83% rename from client/android/src/net/openvpn/ovpn3/ClientAPI_TransportStats.java rename to client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_TransportStats.java index 6a2f3726..8441ad9c 100644 --- a/client/android/src/net/openvpn/ovpn3/ClientAPI_TransportStats.java +++ b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_TransportStats.java @@ -1,8 +1,8 @@ /* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.1 + * This file was automatically generated by SWIG (https://www.swig.org). + * Version 4.1.1 * - * Do not make changes to this file unless you know what you are doing--modify + * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ @@ -21,6 +21,18 @@ public class ClientAPI_TransportStats { return (obj == null) ? 0 : obj.swigCPtr; } + protected static long swigRelease(ClientAPI_TransportStats obj) { + long ptr = 0; + if (obj != null) { + if (!obj.swigCMemOwn) + throw new RuntimeException("Cannot release ownership as memory is not owned"); + ptr = obj.swigCPtr; + obj.swigCMemOwn = false; + obj.delete(); + } + return ptr; + } + @SuppressWarnings("deprecation") protected void finalize() { delete(); diff --git a/client/android/src/net/openvpn/ovpn3/ClientAPI_TunBuilderBase.java b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_TunBuilderBase.java similarity index 92% rename from client/android/src/net/openvpn/ovpn3/ClientAPI_TunBuilderBase.java rename to client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_TunBuilderBase.java index 3c8358d6..69fa2ba4 100644 --- a/client/android/src/net/openvpn/ovpn3/ClientAPI_TunBuilderBase.java +++ b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ClientAPI_TunBuilderBase.java @@ -1,8 +1,8 @@ /* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.1 + * This file was automatically generated by SWIG (https://www.swig.org). + * Version 4.1.1 * - * Do not make changes to this file unless you know what you are doing--modify + * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ @@ -21,6 +21,18 @@ public class ClientAPI_TunBuilderBase { return (obj == null) ? 0 : obj.swigCPtr; } + protected static long swigRelease(ClientAPI_TunBuilderBase obj) { + long ptr = 0; + if (obj != null) { + if (!obj.swigCMemOwn) + throw new RuntimeException("Cannot release ownership as memory is not owned"); + ptr = obj.swigCPtr; + obj.swigCMemOwn = false; + obj.delete(); + } + return ptr; + } + @SuppressWarnings("deprecation") protected void finalize() { delete(); diff --git a/client/android/src/net/openvpn/ovpn3/SWIGTYPE_p_std__string.java b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/SWIGTYPE_p_std__string.java similarity index 75% rename from client/android/src/net/openvpn/ovpn3/SWIGTYPE_p_std__string.java rename to client/android/openvpn/src/main/java/net/openvpn/ovpn3/SWIGTYPE_p_std__string.java index e49f5874..c5728d5f 100644 --- a/client/android/src/net/openvpn/ovpn3/SWIGTYPE_p_std__string.java +++ b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/SWIGTYPE_p_std__string.java @@ -1,8 +1,8 @@ /* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.1 + * This file was automatically generated by SWIG (https://www.swig.org). + * Version 4.1.1 * - * Do not make changes to this file unless you know what you are doing--modify + * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ @@ -22,5 +22,9 @@ public class SWIGTYPE_p_std__string { protected static long getCPtr(SWIGTYPE_p_std__string obj) { return (obj == null) ? 0 : obj.swigCPtr; } + + protected static long swigRelease(SWIGTYPE_p_std__string obj) { + return (obj == null) ? 0 : obj.swigCPtr; + } } diff --git a/client/android/src/net/openvpn/ovpn3/SWIGTYPE_p_std__vectorT_openvpn__ClientAPI__KeyValue_t.java b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/SWIGTYPE_p_std__vectorT_openvpn__ClientAPI__KeyValue_t.java similarity index 75% rename from client/android/src/net/openvpn/ovpn3/SWIGTYPE_p_std__vectorT_openvpn__ClientAPI__KeyValue_t.java rename to client/android/openvpn/src/main/java/net/openvpn/ovpn3/SWIGTYPE_p_std__vectorT_openvpn__ClientAPI__KeyValue_t.java index 15ff7a0f..0486219e 100644 --- a/client/android/src/net/openvpn/ovpn3/SWIGTYPE_p_std__vectorT_openvpn__ClientAPI__KeyValue_t.java +++ b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/SWIGTYPE_p_std__vectorT_openvpn__ClientAPI__KeyValue_t.java @@ -1,8 +1,8 @@ /* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.1 + * This file was automatically generated by SWIG (https://www.swig.org). + * Version 4.1.1 * - * Do not make changes to this file unless you know what you are doing--modify + * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ @@ -22,5 +22,9 @@ public class SWIGTYPE_p_std__vectorT_openvpn__ClientAPI__KeyValue_t { protected static long getCPtr(SWIGTYPE_p_std__vectorT_openvpn__ClientAPI__KeyValue_t obj) { return (obj == null) ? 0 : obj.swigCPtr; } + + protected static long swigRelease(SWIGTYPE_p_std__vectorT_openvpn__ClientAPI__KeyValue_t obj) { + return (obj == null) ? 0 : obj.swigCPtr; + } } diff --git a/client/android/src/net/openvpn/ovpn3/ovpncli.java b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ovpncli.java similarity index 75% rename from client/android/src/net/openvpn/ovpn3/ovpncli.java rename to client/android/openvpn/src/main/java/net/openvpn/ovpn3/ovpncli.java index 944d22ed..f8ce59cf 100644 --- a/client/android/src/net/openvpn/ovpn3/ovpncli.java +++ b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ovpncli.java @@ -1,8 +1,8 @@ /* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.1 + * This file was automatically generated by SWIG (https://www.swig.org). + * Version 4.1.1 * - * Do not make changes to this file unless you know what you are doing--modify + * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ diff --git a/client/android/src/net/openvpn/ovpn3/ovpncliJNI.java b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ovpncliJNI.java similarity index 99% rename from client/android/src/net/openvpn/ovpn3/ovpncliJNI.java rename to client/android/openvpn/src/main/java/net/openvpn/ovpn3/ovpncliJNI.java index 875629ea..4630b60d 100644 --- a/client/android/src/net/openvpn/ovpn3/ovpncliJNI.java +++ b/client/android/openvpn/src/main/java/net/openvpn/ovpn3/ovpncliJNI.java @@ -1,8 +1,8 @@ /* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.1 + * This file was automatically generated by SWIG (https://www.swig.org). + * Version 4.1.1 * - * Do not make changes to this file unless you know what you are doing--modify + * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ diff --git a/client/android/openvpn/src/main/kotlin/org/amnezia/vpn/protocol/openvpn/OpenVpn.kt b/client/android/openvpn/src/main/kotlin/org/amnezia/vpn/protocol/openvpn/OpenVpn.kt new file mode 100644 index 00000000..8cbb7922 --- /dev/null +++ b/client/android/openvpn/src/main/kotlin/org/amnezia/vpn/protocol/openvpn/OpenVpn.kt @@ -0,0 +1,106 @@ +package org.amnezia.vpn.protocol.openvpn + +import android.content.Context +import android.net.VpnService.Builder +import kotlinx.coroutines.flow.MutableStateFlow +import net.openvpn.ovpn3.ClientAPI_Config +import org.amnezia.vpn.protocol.BadConfigException +import org.amnezia.vpn.protocol.Protocol +import org.amnezia.vpn.protocol.ProtocolState +import org.amnezia.vpn.protocol.Statistics +import org.amnezia.vpn.protocol.VpnStartException +import org.amnezia.vpn.util.NetworkUtils +import org.json.JSONObject + +/** + * Config Example: + * { + * "protocol": "openvpn", + * "description": "Server 1", + * "dns1": "1.1.1.1", + * "dns2": "1.0.0.1", + * "hostName": "100.100.100.0", + * "splitTunnelSites": [ + * ], + * "splitTunnelType": 0, + * "openvpn_config_data": { + * "config": "openVpnConfig" + * } + * } + */ + +class OpenVpn : Protocol() { + + private lateinit var context: Context + private var openVpnClient: OpenVpnClient? = null + + override val statistics: Statistics + get() { + openVpnClient?.let { client -> + val stats = client.transport_stats() + return Statistics.build { + setRxBytes(stats.bytesIn) + setTxBytes(stats.bytesOut) + } + } + return Statistics.EMPTY_STATISTICS + } + + override fun initialize(context: Context, state: MutableStateFlow) { + super.initialize(context, state) + loadSharedLibrary(context, "ovpn3") + this.context = context + } + + override fun startVpn(config: JSONObject, vpnBuilder: Builder, protect: (Int) -> Boolean) { + val configBuilder = OpenVpnConfig.Builder() + openVpnClient = OpenVpnClient( + configBuilder, + state, + { ipv6 -> NetworkUtils.getLocalNetworks(context, ipv6) }, + makeEstablish(configBuilder, vpnBuilder), + protect + ) + try { + parseConfig(config) + openVpnClient?.let { client -> + val status = client.connect() + if (status.error) { + throw VpnStartException("OpenVpn connect() error: ${status.status}: ${status.message}") + } + } + } catch (e: Exception) { + openVpnClient = null + throw e + } + } + + override fun stopVpn() { + openVpnClient?.stop() + openVpnClient = null + } + + private fun parseConfig(config: JSONObject) { + val openVpnConfig = ClientAPI_Config() + openVpnConfig.content = config.getJSONObject("openvpn_config_data").getString("config") + openVpnClient?.let { client -> + val evalConfig = client.eval_config(openVpnConfig) + if (evalConfig.error) { + throw BadConfigException("OpenVPN config parse error: ${evalConfig.message}") + } + } + } + + private fun makeEstablish(configBuilder: OpenVpnConfig.Builder, vpnBuilder: Builder): () -> Int = + { + val openVpnConfig = configBuilder.build() + buildVpnInterface(openVpnConfig, vpnBuilder) + + vpnBuilder.establish().use { tunFd -> + if (tunFd == null) { + throw VpnStartException("Create VPN interface: permission not granted or revoked") + } + return@use tunFd.detachFd() + } + } +} diff --git a/client/android/openvpn/src/main/kotlin/org/amnezia/vpn/protocol/openvpn/OpenVpnClient.kt b/client/android/openvpn/src/main/kotlin/org/amnezia/vpn/protocol/openvpn/OpenVpnClient.kt new file mode 100644 index 00000000..a504adaa --- /dev/null +++ b/client/android/openvpn/src/main/kotlin/org/amnezia/vpn/protocol/openvpn/OpenVpnClient.kt @@ -0,0 +1,418 @@ +package org.amnezia.vpn.protocol.openvpn + +import android.net.ProxyInfo +import kotlinx.coroutines.flow.MutableStateFlow +import net.openvpn.ovpn3.ClientAPI_Config +import net.openvpn.ovpn3.ClientAPI_EvalConfig +import net.openvpn.ovpn3.ClientAPI_Event +import net.openvpn.ovpn3.ClientAPI_LogInfo +import net.openvpn.ovpn3.ClientAPI_OpenVPNClient +import net.openvpn.ovpn3.ClientAPI_Status +import net.openvpn.ovpn3.ClientAPI_StringVec +import net.openvpn.ovpn3.ClientAPI_TransportStats +import org.amnezia.vpn.protocol.ProtocolState +import org.amnezia.vpn.protocol.ProtocolState.CONNECTED +import org.amnezia.vpn.protocol.ProtocolState.DISCONNECTED +import org.amnezia.vpn.protocol.VpnStartException +import org.amnezia.vpn.util.InetNetwork +import org.amnezia.vpn.util.Log +import org.amnezia.vpn.util.parseInetAddress + +private const val TAG = "OpenVpnClient" +private const val EMULATED_EXCLUDE_ROUTES = (1 shl 16) + +class OpenVpnClient( + private val configBuilder: OpenVpnConfig.Builder, + private val state: MutableStateFlow, + private val getLocalNetworks: (Boolean) -> List, + private val establish: () -> Int, + private val protect: (Int) -> Boolean +) : ClientAPI_OpenVPNClient() { + + /************************************************************************** + * Tun builder callbacks + **************************************************************************/ + + // Tun builder methods, loosely based on the Android VpnService.Builder + // abstraction. These methods comprise an abstraction layer that + // allows the OpenVPN C++ core to call out to external methods for + // establishing the tunnel, adding routes, etc. + + // All methods returning bool use the return + // value to indicate success (true) or fail (false). + // tun_builder_new() should be called first, then arbitrary setter methods, + // and finally tun_builder_establish to return the socket descriptor + // for the session. IP addresses are pre-validated before being passed to + // these methods. + // This interface is based on Android's VpnService.Builder. + + // Callback to construct a new tun builder + // Should be called first. + override fun tun_builder_new(): Boolean { + Log.v(TAG, "tun_builder_new") + return true + } + + // Callback to set MTU of the VPN interface + // Never called more than once per tun_builder session. + override fun tun_builder_set_mtu(mtu: Int): Boolean { + Log.v(TAG, "tun_builder_set_mtu: $mtu") + configBuilder.setMtu(mtu) + return true + } + + // Callback to add network address to VPN interface + // May be called more than once per tun_builder session + override fun tun_builder_add_address( + address: String, prefix_length: Int, + gateway: String, ipv6: Boolean, net30: Boolean + ): Boolean { + Log.v(TAG, "tun_builder_add_address: $address, $prefix_length, $gateway, $ipv6, $net30") + configBuilder.addAddress(InetNetwork(address, prefix_length)) + return true + } + + // Callback to add route to VPN interface + // May be called more than once per tun_builder session + // metric is optional and should be ignored if < 0 + override fun tun_builder_add_route(address: String, prefix_length: Int, metric: Int, ipv6: Boolean): Boolean { + Log.v(TAG, "tun_builder_add_route: $address, $prefix_length, $metric, $ipv6") + if (address == "remote_host") return false + configBuilder.addRoute(InetNetwork(address, prefix_length)) + return true + } + + // Callback to exclude route from VPN interface + // May be called more than once per tun_builder session + // metric is optional and should be ignored if < 0 + override fun tun_builder_exclude_route(address: String, prefix_length: Int, metric: Int, ipv6: Boolean): Boolean { + Log.v(TAG, "tun_builder_exclude_route: $address, $prefix_length, $metric, $ipv6") + configBuilder.excludeRoute(InetNetwork(address, prefix_length)) + return true + } + + // Callback to add DNS server to VPN interface + // May be called more than once per tun_builder session + // If reroute_dns is true, all DNS traffic should be routed over the + // tunnel, while if false, only DNS traffic that matches an added search + // domain should be routed. + // Guaranteed to be called after tun_builder_reroute_gw. + override fun tun_builder_add_dns_server(address: String, ipv6: Boolean): Boolean { + Log.v(TAG, "tun_builder_add_dns_server: $address, $ipv6") + configBuilder.addDnsServer(parseInetAddress(address)) + return true + } + + // Optional callback that indicates whether traffic of a certain + // address family (AF_INET or AF_INET6) should be + // blocked or allowed, to prevent unencrypted packet leakage when + // the tunnel is IPv4-only/IPv6-only, but the local machine + // has connectivity with the other protocol to the internet. + // Controlled by "block-ipv6" and block-ipv6 config var. + // If addresses are added for a family this setting should be + // ignored for that family + // See also Android's VPNService.Builder.allowFamily method + /* override fun tun_builder_set_allow_family(af: Int, allow: Boolean): Boolean { + Log.v(TAG, "tun_builder_set_allow_family: $af, $allow") + return true + } */ + + // Callback to set address of remote server + // Never called more than once per tun_builder session. + override fun tun_builder_set_remote_address(address: String, ipv6: Boolean): Boolean { + Log.v(TAG, "tun_builder_set_remote_address: $address, $ipv6") + return true + } + + // Optional callback that indicates OSI layer, should be 2 or 3. + // Defaults to 3. + override fun tun_builder_set_layer(layer: Int): Boolean { + Log.v(TAG, "tun_builder_set_layer: $layer") + return layer == 3 + } + + // Callback to set the session name + // Never called more than once per tun_builder session. + override fun tun_builder_set_session_name(name: String): Boolean { + Log.v(TAG, "tun_builder_set_session_name: $name") + return true + } + + // Callback to establish the VPN tunnel, returning a file descriptor + // to the tunnel, which the caller will henceforth own. Returns -1 + // if the tunnel could not be established. + // Always called last after tun_builder session has been configured. + override fun tun_builder_establish(): Int { + Log.v(TAG, "tun_builder_establish") + return establish() + } + + // Callback to reroute default gateway to VPN interface. + // ipv4 is true if the default route to be added should be IPv4. + // ipv6 is true if the default route to be added should be IPv6. + // flags are defined in RGWFlags (rgwflags.hpp). + // Never called more than once per tun_builder session. + override fun tun_builder_reroute_gw(ipv4: Boolean, ipv6: Boolean, flags: Long): Boolean { + Log.v(TAG, "tun_builder_reroute_gw: $ipv4, $ipv6, $flags") + if ((flags and EMULATED_EXCLUDE_ROUTES.toLong()) != 0L) return true + if (ipv4) { + configBuilder.addRoute(InetNetwork("0.0.0.0", 0)) + } + if (ipv6) { + configBuilder.addRoute(InetNetwork("::", 0)) + } + return true + } + + // Callback to add search domain to DNS resolver + // May be called more than once per tun_builder session + // See tun_builder_add_dns_server above for description of + // reroute_dns parameter. + // Guaranteed to be called after tun_builder_reroute_gw. + override fun tun_builder_add_search_domain(domain: String): Boolean { + Log.v(TAG, "tun_builder_add_search_domain: $domain") + configBuilder.setSearchDomain(domain) + return true + } + + // Callback to set the HTTP proxy + // Never called more than once per tun_builder session. + override fun tun_builder_set_proxy_http(host: String, port: Int): Boolean { + Log.v(TAG, "tun_builder_set_proxy_http: $host, $port") + try { + configBuilder.setHttpProxy(ProxyInfo.buildDirectProxy(host, port)) + } catch (e: Exception) { + Log.e(TAG, "Could not set proxy: ${e.message}") + return false + } + return true + } + + // Callback to set the HTTPS proxy + // Never called more than once per tun_builder session. + override fun tun_builder_set_proxy_https(host: String, port: Int): Boolean { + Log.v(TAG, "tun_builder_set_proxy_https: $host, $port") + return false + } + + // When the exclude local network option is enabled this + // function is called to get a list of local networks so routes + // to exclude them from the VPN network are generated + // This should be a list of CIDR networks (e.g. 192.168.0.0/24) + override fun tun_builder_get_local_networks(ipv6: Boolean): ClientAPI_StringVec { + Log.v(TAG, "tun_builder_get_local_networks: $ipv6") + val networks = ClientAPI_StringVec() + for (address in getLocalNetworks(ipv6)) { + networks.add(address.toString()) + } + return networks + } + + // Optional callback to set default value for route metric. + // Guaranteed to be called before other methods that deal + // with routes such as tun_builder_add_route and + // tun_builder_reroute_gw. Route metric is ignored + // if < 0. + /* override fun tun_builder_set_route_metric_default(metric: Int): Boolean { + Log.v(TAG, "tun_builder_set_route_metric_default: $metric") + return super.tun_builder_set_route_metric_default(metric) + } */ + + // Callback to add a host which should bypass the proxy + // May be called more than once per tun_builder session + /* override fun tun_builder_add_proxy_bypass(bypass_host: String): Boolean { + Log.v(TAG, "tun_builder_add_proxy_bypass: $bypass_host") + return super.tun_builder_add_proxy_bypass(bypass_host) + } */ + + // Callback to set the proxy "Auto Config URL" + // Never called more than once per tun_builder session. + /* override fun tun_builder_set_proxy_auto_config_url(url: String): Boolean { + Log.v(TAG, "tun_builder_set_proxy_auto_config_url: $url") + return super.tun_builder_set_proxy_auto_config_url(url) + } */ + + // Callback to add Windows WINS server to VPN interface. + // WINS server addresses are always IPv4. + // May be called more than once per tun_builder session. + // Guaranteed to be called after tun_builder_reroute_gw. + /* override fun tun_builder_add_wins_server(address: String): Boolean { + Log.v(TAG, "tun_builder_add_wins_server: $address") + return super.tun_builder_add_wins_server(address) + } */ + + // Optional callback to set a DNS suffix on tun/tap adapter. + // Currently only implemented on Windows, where it will + // set the "Connection-specific DNS Suffix" property on + // the TAP driver. + /* override fun tun_builder_set_adapter_domain_suffix(name: String): Boolean { + Log.v(TAG, "tun_builder_set_adapter_domain_suffix: $name") + return super.tun_builder_set_adapter_domain_suffix(name) + } */ + + // Return true if tun interface may be persisted, i.e. rolled + // into a new session with properties untouched. This method + // is only called after all other tests of persistence + // allowability succeed, therefore it can veto persistence. + // If persistence is ultimately enabled, + // tun_builder_establish_lite() will be called. Otherwise, + // tun_builder_establish() will be called. + /* override fun tun_builder_persist(): Boolean { + Log.v(TAG, "tun_builder_persist") + return super.tun_builder_persist() + } */ + + // Indicates a reconnection with persisted tun state. + /* override fun tun_builder_establish_lite() { + Log.v(TAG, "tun_builder_establish_lite") + super.tun_builder_establish_lite() + } */ + + // Indicates that tunnel is being torn down. + // If disconnect == true, then the teardown is occurring + // prior to final disconnect. + /* override fun tun_builder_teardown(disconnect: Boolean) { + Log.v(TAG, "tun_builder_teardown: $disconnect") + super.tun_builder_teardown(disconnect) + } */ + + /************************************************************************** + * Connection control methods + **************************************************************************/ + + // Parse OpenVPN configuration file. + override fun eval_config(arg0: ClientAPI_Config): ClientAPI_EvalConfig { + Log.v(TAG, "eval_config") + return super.eval_config(arg0) + } + + // Primary VPN client connect method, doesn't return until disconnect. + // Should be called by a worker thread. This method will make callbacks + // to event() and log() functions. Make sure to call eval_config() + // and possibly provide_creds() as well before this function. + override fun connect(): ClientAPI_Status { + Log.v(TAG, "connect") + return super.connect() + } + + // Callback to "protect" a socket from being routed through the tunnel. + // Will be called from the thread executing connect(). + // The remote and ipv6 are the remote host this socket will connect to + override fun socket_protect(socket: Int, remote: String, ipv6: Boolean): Boolean { + Log.v(TAG, "socket_protect: $socket, $remote, $ipv6") + return protect(socket) + } + + // Stop the client. Only meaningful when connect() is running. + // May be called asynchronously from a different thread + // when connect() is running. + override fun stop() { + Log.v(TAG, "stop") + super.stop() + } + + // Pause the client -- useful to avoid continuous reconnection attempts + // when network is down. May be called from a different thread + // when connect() is running. + override fun pause(reason: String) { + Log.v(TAG, "pause: $reason") + super.pause(reason) + } + + // Resume the client after it has been paused. May be called from a + // different thread when connect() is running. + override fun resume() { + Log.v(TAG, "resume") + super.resume() + } + + // Do a disconnect/reconnect cycle n seconds from now. May be called + // from a different thread when connect() is running. + override fun reconnect(seconds: Int) { + Log.v(TAG, "reconnect") + super.reconnect(seconds) + } + + // When a connection is close to timeout, the core will call this + // method. If it returns false, the core will disconnect with a + // CONNECTION_TIMEOUT event. If true, the core will enter a PAUSE + // state. + override fun pause_on_connection_timeout(): Boolean { + Log.v(TAG, "pause_on_connection_timeout") + return false + } + + // Return information about the most recent connection. Should be called + // after an event of type "CONNECTED". + /* override fun connection_info(): ClientAPI_ConnectionInfo { + Log.v(TAG, "connection_info") + return super.connection_info() + } */ + + /************************************************************************** + * Status callbacks + **************************************************************************/ + + // Callback for delivering events during connect() call. + // Will be called from the thread executing connect(). + override fun event(event: ClientAPI_Event) { + val name = event.name + val info = event.info + Log.v(TAG, "OpenVpn event: $name: $info") + when (name) { + "COMPRESSION_ENABLED", "WARN" -> Log.w(TAG, "$name: $info") + "CONNECTED" -> state.value = CONNECTED + "DISCONNECTED" -> state.value = DISCONNECTED + "CONNECTION_TIMEOUT" -> { + Log.w(TAG, "$name: $info") + state.value = DISCONNECTED + // todo: test it + throw VpnStartException("Connection timeout") + } + } + if (event.error) Log.e(TAG, "OpenVpn ERROR: $name: $info") + if (event.fatal) Log.e(TAG, "OpenVpn FATAL: $name: $info") + } + + // Callback for logging. + // Will be called from the thread executing connect(). + override fun log(arg0: ClientAPI_LogInfo) { + arg0.text.dropLastWhile { it == '\n' }.let { + Log.d(TAG, "OpenVpnLog: $it") + } + } + + /************************************************************************** + * Stats methods + **************************************************************************/ + + // return transport stats only + override fun transport_stats(): ClientAPI_TransportStats { + Log.v(TAG, "transport_stats") + return super.transport_stats() + } + + // return a stats value, index should be >= 0 and < stats_n() + /* override fun stats_value(index: Int): Long { + Log.v(TAG, "stats_value: $index") + return super.stats_value(index) + } */ + + // return all stats in a bundle + /* override fun stats_bundle(): ClientAPI_LLVector { + Log.v(TAG, "stats_bundle") + return super.stats_bundle() + } */ + + // return tun stats only + /* override fun tun_stats(): ClientAPI_InterfaceStats { + Log.v(TAG, "tun_stats") + return super.tun_stats() + } */ + + // post control channel message + /* override fun post_cc_msg(msg: String) { + Log.v(TAG, "post_cc_msg: $msg") + super.post_cc_msg(msg) + } */ +} diff --git a/client/android/openvpn/src/main/kotlin/org/amnezia/vpn/protocol/openvpn/OpenVpnConfig.kt b/client/android/openvpn/src/main/kotlin/org/amnezia/vpn/protocol/openvpn/OpenVpnConfig.kt new file mode 100644 index 00000000..36d8d93b --- /dev/null +++ b/client/android/openvpn/src/main/kotlin/org/amnezia/vpn/protocol/openvpn/OpenVpnConfig.kt @@ -0,0 +1,20 @@ +package org.amnezia.vpn.protocol.openvpn + +import org.amnezia.vpn.protocol.ProtocolConfig + +private const val OPENVPN_DEFAULT_MTU = 1500 + +class OpenVpnConfig private constructor( + protocolConfigBuilder: ProtocolConfig.Builder +) : ProtocolConfig(protocolConfigBuilder) { + + class Builder : ProtocolConfig.Builder(false) { + override var mtu: Int = OPENVPN_DEFAULT_MTU + + override fun build(): OpenVpnConfig = OpenVpnConfig(this) + } + + companion object { + inline fun build(block: Builder.() -> Unit): OpenVpnConfig = Builder().apply(block).build() + } +} diff --git a/client/android/settings.gradle.kts b/client/android/settings.gradle.kts index 7f22efa2..8bfe25da 100644 --- a/client/android/settings.gradle.kts +++ b/client/android/settings.gradle.kts @@ -34,6 +34,7 @@ include(":utils") include(":protocolApi") include(":wireguard") include(":awg") +include(":openvpn") // get values from gradle or local properties val androidBuildToolsVersion: String by gradleProperties diff --git a/client/android/src/org/amnezia/vpn/AmneziaVpnService.kt b/client/android/src/org/amnezia/vpn/AmneziaVpnService.kt index 13e0cb29..b739ed49 100644 --- a/client/android/src/org/amnezia/vpn/AmneziaVpnService.kt +++ b/client/android/src/org/amnezia/vpn/AmneziaVpnService.kt @@ -313,6 +313,7 @@ class AmneziaVpnService : VpnService() { ?: when (protocolName) { "wireguard" -> Wireguard() "awg" -> Awg() + "openvpn" -> OpenVpn() else -> throw IllegalArgumentException("Failed to load $protocolName protocol") }.apply { initialize(applicationContext, protocolState) } diff --git a/client/android/src/org/amnezia/vpn/OpenVPNThreadv3.kt b/client/android/src/org/amnezia/vpn/OpenVPNThreadv3.kt deleted file mode 100644 index f2496db1..00000000 --- a/client/android/src/org/amnezia/vpn/OpenVPNThreadv3.kt +++ /dev/null @@ -1,259 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public -* License, v. 2.0. If a copy of the MPL was not distributed with this -* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package org.amnezia.vpn - -import android.content.Context -import android.content.Intent -import android.os.Build -import android.os.IBinder -import android.system.OsConstants -import java.io.File -// import com.wireguard.android.util.SharedLibraryLoader -// import com.wireguard.config.* -// import com.wireguard.crypto.Key -import org.json.JSONObject -import java.util.Base64 - -// import com.wireguard.config.* - -import net.openvpn.ovpn3.ClientAPI_Config -import net.openvpn.ovpn3.ClientAPI_EvalConfig -import net.openvpn.ovpn3.ClientAPI_Event -import net.openvpn.ovpn3.ClientAPI_ExternalPKICertRequest -import net.openvpn.ovpn3.ClientAPI_ExternalPKISignRequest -import net.openvpn.ovpn3.ClientAPI_LogInfo -import net.openvpn.ovpn3.ClientAPI_OpenVPNClient -import net.openvpn.ovpn3.ClientAPI_ProvideCreds -import net.openvpn.ovpn3.ClientAPI_Status -import net.openvpn.ovpn3.ClientAPI_TransportStats - - -import java.lang.StringBuilder - -class OpenVPNThreadv3(var service: AmneziaVpnService): ClientAPI_OpenVPNClient()/* , Runnable */ { - /* private val tag = "OpenVPNThreadv3" - private var mAlreadyInitialised = false - private var mService: AmneziaVpnService = service - - private var bytesInIndex = -1 - private var bytesOutIndex = -1 - - init { - findConfigIndices() - } - - private fun findConfigIndices() { - val n: Int = stats_n() - - for (i in 0 until n) { - val name: String = stats_name(i) - if (name == "BYTES_IN") bytesInIndex = i - if (name == "BYTES_OUT") bytesOutIndex = i - } - } - - fun getTotalRxBytes(): Long { - return stats_value(bytesInIndex) - } - - fun getTotalTxBytes(): Long { - return stats_value(bytesOutIndex) - } - - override fun reconnect(seconds :Int) { - Log.v(tag, "reconnect") - super.reconnect(seconds) - } - - - override fun run() { - - val config: ClientAPI_Config = ClientAPI_Config() - - val jsonVpnConfig = mService.getVpnConfig() - val ovpnConfig = jsonVpnConfig.getJSONObject("openvpn_config_data").getString("config") - val splitTunnelType = jsonVpnConfig.getInt("splitTunnelType") - val splitTunnelSites = jsonVpnConfig.getJSONArray("splitTunnelSites") - - val resultingConfig = StringBuilder() - resultingConfig.append(ovpnConfig) - - if (jsonVpnConfig.getString("protocol") == "cloak") { - val cloakConfigJson: JSONObject = jsonVpnConfig.getJSONObject("cloak_config_data") - - if (cloakConfigJson.has("NumConn")) { - cloakConfigJson.put("NumConn", 1) - } - - if (cloakConfigJson.has("ProxyMethod")) { - cloakConfigJson.put("ProxyMethod", "openvpn") - } - - if (cloakConfigJson.has("port")) { - val portValue = cloakConfigJson.get("port") - cloakConfigJson.remove("port") - cloakConfigJson.put("RemotePort", portValue) - } - - if (cloakConfigJson.has("remote")) { - val hostValue = cloakConfigJson.get("remote") - cloakConfigJson.remove("remote") - cloakConfigJson.put("RemoteHost", hostValue) - } - - val cloakConfigData = jsonVpnConfig.getJSONObject("cloak_config_data").toString().toByteArray() - val cloakConfig = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - Base64.getEncoder().encodeToString(cloakConfigData) - } else { - android.util.Base64.encodeToString(cloakConfigData, android.util.Base64.DEFAULT) - } - - resultingConfig.append("\n\n") - resultingConfig.append(cloakConfig) - resultingConfig.append("\n\n") - - config.setUsePluggableTransports(true) - } - - config.content = resultingConfig.toString() - - eval_config(config) - - val status = connect() - - if (status.getError()) { - Log.i(tag, "connect() error: " + status.getError() + ": " + status.getMessage()) - } - } - - override fun log(arg0: ClientAPI_LogInfo){ - Log.i(tag, arg0.getText()) - } - - override fun event(event: ClientAPI_Event ) { - val eventName = event.getName() - when (eventName) { - "CONNECTED" -> mService.isUp = true - "DISCONNECTED" -> mService.isUp = false - } - Log.i(tag, eventName) - } - - override fun tun_builder_new(): Boolean { - return true - } - - override fun tun_builder_establish(): Int { - Log.v(tag, "tun_builder_establish") - val jsonVpnConfig = mService.getVpnConfig() - - val splitTunnelType = jsonVpnConfig.getInt("splitTunnelType") - val splitTunnelSites = jsonVpnConfig.getJSONArray("splitTunnelSites") - if (splitTunnelType == 1) { - for (i in 0 until splitTunnelSites.length()) { - val site = splitTunnelSites.getString(i) - val ipRange = IPRange(site) - mService.addRoute(ipRange.getFrom().getHostAddress(), ipRange.getPrefix()) - } - } - if (splitTunnelType == 2) { - val ipRangeSet = IPRangeSet.fromString("0.0.0.0/0") - ipRangeSet.remove(IPRange("127.0.0.0/8")) - for (i in 0 until splitTunnelSites.length()) { - val site = splitTunnelSites.getString(i) - ipRangeSet.remove(IPRange(site)) - } - ipRangeSet.subnets().forEach { - mService.addRoute(it.getFrom().getHostAddress(), it.getPrefix()) - Thread.sleep(10) - } - mService.addRoute("2000::", 3) - } - - return mService.establish()!!.detachFd() - } - - override fun tun_builder_add_address(address: String , prefix_length: Int , gateway: String , ipv6:Boolean , net30: Boolean ): Boolean { - Log.v(tag, "tun_builder_add_address") - mService.addAddress(address, prefix_length) - return true - } - - override fun tun_builder_add_route(address: String, prefix_length: Int, metric: Int, ipv6: Boolean): Boolean { - Log.v(tag, "tun_builder_add_route") - if (address.equals("remote_host")) - return false - - mService.addRoute(address, prefix_length); - return true - } - - override fun tun_builder_reroute_gw(ipv4: Boolean, ipv6: Boolean , flags: Long): Boolean { - Log.v(tag, "tun_builder_reroute_gw") - mService.addRoute("0.0.0.0", 0) - return true - } - - override fun tun_builder_exclude_route(address: String, prefix_length: Int, metric: Int, ipv6: Boolean): Boolean { - Log.v(tag, "tun_builder_exclude_route") - mService.addRoute(address, prefix_length); - return true - } - - override fun tun_builder_set_remote_address(address: String , ipv6: Boolean): Boolean { - mService.setMtu(1500) - return true - } - - override fun tun_builder_set_mtu(mtu: Int): Boolean { - Log.v(tag, "tun_builder_set_mtu") - mService.setMtu(mtu) - return true - } - - override fun tun_builder_add_dns_server(address: String , ipv6: Boolean): Boolean { - mService.addDNS(address) - return true - } - - override fun tun_builder_set_session_name(name: String ): Boolean { - Log.v(tag, "We should call this session: " + name) - mService.setSessionName(name) - return true - } - - override fun tun_builder_set_proxy_http(host: String, port: Int): Boolean { - return mService.addHttpProxy(host, port); - } - - override fun tun_builder_set_proxy_https(host: String , port: Int): Boolean { - Log.v(tag, "tun_builder_set_proxy_https") - return false - } - - override fun pause_on_connection_timeout(): Boolean { - Log.v(tag, "pause_on_connection_timeout") - return true - } - - override fun tun_builder_add_search_domain(domain: String ): Boolean { - mService.setDomain(domain); - return true - } - - override fun tun_builder_set_layer(layer: Int): Boolean { - return layer == 3 - } - - override fun socket_protect(socket: Int, remote: String, ipv6: Boolean): Boolean { - Log.v(tag, "socket_protect") - return mService.protect(socket); - - } - - override fun stop() { - super.stop() - } */ -}